lainchan/js/id_colors.js

48 lines
927 B
JavaScript
Raw Normal View History

if (active_page == 'thread' || active_page == 'index') {
$(document).ready(function(){
$.hash = function(str) {
var i, j, msg = 0;
for (i = 0, j = str.length; i < j; ++i) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
}
return msg;
};
2014-09-27 14:56:05 -04:00
function stringToRGB(str){
var rgb, hash;
rgb = [];
hash = $.hash(str);
rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF;
return rgb;
}
2014-09-27 14:56:05 -04:00
function colorPostId(el) {
2014-09-27 16:19:58 -04:00
var rgb = stringToRGB($(el).text());
2014-09-27 16:19:58 -04:00
$(el).css({
"background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
"padding": "3px 5px",
"border-radius": "8px",
"color": "white"
});
}
$(".poster_id").each(function(k, v){
colorPostId(v);
});
$(document).on('new_post', function(e, post) {
$(post).find('.poster_id').each(function(k, v) {
colorPostId(v);
});
});
2014-09-27 14:56:05 -04:00
});
}