Rewrite color IDs script so it actually works

This commit is contained in:
8chan 2014-09-27 21:23:51 +00:00
parent 150480f3fc
commit befe393778
2 changed files with 36 additions and 20 deletions

View File

@ -84,6 +84,7 @@
$config['mod']['recent_reports'] = 65535;
// Board shit
$config['poster_id_length'] = 6;
$config['ayah_enabled'] = true;
$config['url_banner'] = '/banners.php';
//$config['default_stylesheet'] = array('Notsuba', 'notsuba.css');

View File

@ -1,30 +1,44 @@
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);
if (window.Options && Options.get_tab('general')) {
selector = '#color-ids>input';
event = 'change';
Options.extend_tab("general", "<label id='color-ids'><input type='checkbox' /> "+_('Color IDs')+"</label>");
}
return msg;
};
else {
selector = '#color-ids';
event = 'click';
$('hr:first').before('<div id="color-ids" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+_('Color IDs')+'</a></div>')
}
function stringToRGB(str){
var rgb, hash;
$(selector).on(event, function() {
if (localStorage.color_ids === 'true') {
localStorage.color_ids = 'false';
} else {
localStorage.color_ids = 'true';
}
});
rgb = [];
hash = $.hash(str);
if (!localStorage.color_ids || localStorage.color_ids === 'false') {
return;
} else {
$('#color-ids>input').attr('checked','checked');
}
rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF;
function IDToRGB(id_str){
var id = id_str.match(/.{1,2}/g);
var rgb = new Array();
for (i = 0; i < id.length; i++) {
rgb[i] = parseInt(id[i], 16);
}
return rgb;
}
function colorPostId(el) {
var rgb = stringToRGB($(el).text());
var rgb = IDToRGB($(el).text());
$(el).css({
"background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
@ -43,5 +57,6 @@ if (active_page == 'thread' || active_page == 'index') {
colorPostId(v);
});
});
});
}