Browse Source

Call on ready, dont pollute window namespace with vars

pull/40/head
8chan 10 years ago
committed by czaks
parent
commit
035f8437ab
  1. 65
      js/id_colors.js

65
js/id_colors.js

@ -1,34 +1,37 @@
$.hash = function(str) { if (active_page == 'thread' || active_page == 'index') {
var i, j, msg = 0; $(document).ready(function(){
$.hash = function(str) {
for (i = 0, j = str.length; i < j; ++i) { var i, j, msg = 0;
msg = ((msg << 5) - msg) + str.charCodeAt(i);
} for (i = 0, j = str.length; i < j; ++i) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
return msg; }
};
return msg;
};
function stringToRGB(str){ function stringToRGB(str){
var rgb, hash; var rgb, hash;
rgb = []; rgb = [];
hash = $.hash(str); hash = $.hash(str);
rgb[0] = (hash >> 24) & 0xFF; rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF; rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF; rgb[2] = (hash >> 8) & 0xFF;
return rgb; return rgb;
} }
$(".poster_id").each(function(){ $(".poster_id").each(function(){
var rgb = stringToRGB($(this).text()); var rgb = stringToRGB($(this).text());
$(this).css({ $(this).css({
"background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
"padding": "3px 5px", "padding": "3px 5px",
"border-radius": "8px", "border-radius": "8px",
"color": "white" "color": "white"
});
});
}); });
}); }

Loading…
Cancel
Save