2018-03-09 14:40:21 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<title>Colors</title>
|
|
|
|
<script type="text/javascript">
|
2018-03-15 15:40:50 +01:00
|
|
|
|
|
|
|
var hexLetters = '0123456789ABCDEF';
|
2018-03-09 14:40:21 +01:00
|
|
|
|
|
|
|
enhanceColor = function(color) {
|
|
|
|
var c = eval("0x" + color);
|
|
|
|
var hi = Math.round(c / 16);
|
|
|
|
if (hi < 15) {
|
|
|
|
hi += Math.round((15 - hi) / 1.5);
|
|
|
|
}
|
|
|
|
if (hi > 15)
|
|
|
|
hi = 15;
|
|
|
|
return '' + hexLetters[hi] + hexLetters[c % 16];
|
|
|
|
}
|
|
|
|
|
|
|
|
randomRGB = function() {
|
|
|
|
var color = '';
|
|
|
|
var couple = '';
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
//do {
|
|
|
|
couple = '' + hexLetters[Math.floor(Math.random() * 10)]
|
|
|
|
+ hexLetters[Math.floor(Math.random() * 16)];
|
|
|
|
// for (j = 0; j < 2; j++) {
|
|
|
|
// couple += letters[Math.floor(Math.random() * 16)];
|
|
|
|
// }
|
|
|
|
//} while ((255 - parseInt("0x" + couple)) < 128)
|
|
|
|
color += couple;
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
changeColor = function() {
|
|
|
|
var color = randomRGB();
|
|
|
|
var complemetar = 0xFFFFFF - eval("0x" + color.substring(1));
|
|
|
|
var complement = complemetar.toString(16);
|
|
|
|
var R = enhanceColor(complement.substring(0, 2));
|
|
|
|
var G = enhanceColor(complement.substring(2, 4));
|
|
|
|
var B = enhanceColor(complement.substring(4));
|
|
|
|
complement = "#" + R + G + B;
|
|
|
|
var span = document.getElementsByTagName("SPAN");
|
|
|
|
span[0].setAttribute("style", "color:#" + color + "; font-weight:bold;");
|
|
|
|
span[1].setAttribute("style", "color:#" + color + "; background:"
|
|
|
|
+ complement + "; font-weight:bold;");
|
|
|
|
}
|
2018-03-15 15:40:50 +01:00
|
|
|
|
|
|
|
testReplace = function() {
|
|
|
|
var text = "<< Text between >>";
|
|
|
|
text = text.replace(/</g, "<");
|
|
|
|
text = text.replace(/>/g, ">");
|
|
|
|
console.log(text);
|
|
|
|
document.getElementById("between-text").innerHtml = text;
|
|
|
|
}
|
2018-03-09 14:40:21 +01:00
|
|
|
</script>
|
|
|
|
</head>
|
2018-03-15 15:40:50 +01:00
|
|
|
<body onload="testReplace()">
|
2018-03-09 14:40:21 +01:00
|
|
|
<div>
|
|
|
|
<span>TEST COLORE</span>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span>TEST COLORE + SFONDO</span>
|
|
|
|
</div>
|
2018-03-15 15:40:50 +01:00
|
|
|
<div id="between-text">
|
|
|
|
</div>
|
2018-03-09 14:40:21 +01:00
|
|
|
</body>
|
|
|
|
</html>
|