From befe393778c36fa40a93160c1ab107b35e4fb99b Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 21:23:51 +0000 Subject: [PATCH] Rewrite color IDs script so it actually works --- inc/instance-config.php | 1 + js/id_colors.js | 55 ++++++++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/inc/instance-config.php b/inc/instance-config.php index d74b97fd..a839c2b2 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -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'); diff --git a/js/id_colors.js b/js/id_colors.js index 9cde1b00..594b99d3 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -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); - } - - return msg; - }; + if (window.Options && Options.get_tab('general')) { + selector = '#color-ids>input'; + event = 'change'; + Options.extend_tab("general", ""); + } + + else { + selector = '#color-ids'; + event = 'click'; + $('hr:first').before('
'+_('Color IDs')+'
') + } + + $(selector).on(event, function() { + if (localStorage.color_ids === 'true') { + localStorage.color_ids = 'false'; + } else { + localStorage.color_ids = 'true'; + } + }); + + if (!localStorage.color_ids || localStorage.color_ids === 'false') { + return; + } else { + $('#color-ids>input').attr('checked','checked'); + } + + 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); + } - 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; } 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); }); }); + }); }