diff --git a/inc/instance-config.php b/inc/instance-config.php index 7ab9dfdc..75145129 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -121,6 +121,7 @@ $config['additional_javascript'][] = 'js/toggle-locked-threads.js'; $config['additional_javascript'][] = 'js/toggle-images.js'; $config['additional_javascript'][] = 'js/mobile-style.js'; + $config['additional_javascript'][] = 'js/id_highlighter.js' $config['font_awesome_css'] = '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css'; diff --git a/js/id_colors.js b/js/id_colors.js new file mode 100644 index 00000000..6923dbec --- /dev/null +++ b/js/id_colors.js @@ -0,0 +1,34 @@ +$.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; +}; + +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; +} + +$(".poster_id").each(function(){ + var rgb = stringToRGB($(this).text()); + + $(this).css({ + "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", + "padding": "3px 5px", + "border-radius": "8px", + "color": "white" + }); +}); + diff --git a/js/id_highlighter.js b/js/id_highlighter.js new file mode 100644 index 00000000..60052031 --- /dev/null +++ b/js/id_highlighter.js @@ -0,0 +1,40 @@ +Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } + +var idshighlighted = []; + +function getPostsById(id){ + return $(".poster_id").filter(function(i){ + return $(this).text() == id; + }); +} + +function getMasterPosts(parents){ + if(!parents.hasClass("post")) return; + + var toRet = []; + + $(parents).each(function(){ + if($(this).hasClass("post")) + toRet.push($(this)); + }); + + return toRet; +} + +$(".poster_id").click(function(){ + var id = $(this).text(); + + if($.inArray(id, idshighlighted) !== -1){ + idshighlighted.remove(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).removeClass("highlighted"); + }); + }else{ + idshighlighted.push(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).addClass("highlighted"); + }); + } +}); diff --git a/stylesheets/style.css b/stylesheets/style.css index dbc367cf..f7a70780 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -905,6 +905,10 @@ div.thread:hover { word-wrap: break-word; } +.poster_id{ + cursor: pointer; +} + code > pre { /* Better code tags */ background:black;