From bf8fedb659b96b2c04a0c434c9928ab8a1848a4b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 26 Jul 2014 18:57:41 -0700 Subject: [PATCH] Merge @ccd0's title fix. Make some funny changes to IDColor --- LICENSE | 2 +- builds/appchan-x.user.js | 45 ++++++++++++-------------------- builds/crx/script.js | 45 ++++++++++++-------------------- src/Miscellaneous/IDColor.coffee | 41 +++++++++++++++-------------- src/Monitoring/Unread.coffee | 2 +- 5 files changed, 58 insertions(+), 77 deletions(-) diff --git a/LICENSE b/LICENSE index 0f73eba1c..310d07ab4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.9.31 - 2014-07-18 +* appchan x - Version 2.9.31 - 2014-07-26 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 8d6843d36..5fdbec03a 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -25,7 +25,7 @@ // ==/UserScript== /* -* appchan x - Version 2.9.31 - 2014-07-18 +* appchan x - Version 2.9.31 - 2014-07-26 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -13046,7 +13046,7 @@ Unread.read(); return Unread.update(); } else { - return Unread.addPosts(e.detail.newPosts.map(function(fullID) { + return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) { return g.posts[fullID]; })); } @@ -15532,46 +15532,35 @@ if (!Conf['Color User IDs']) { return; } - this.ids = {}; + this.ids = { + Heaven: [0, 0, 0, '#fff'] + }; return Post.callbacks.push({ name: 'Color User IDs', cb: this.node }); }, node: function() { - var rgb, span, style, uid; - if (this.isClone || !(uid = this.info.uniqueID)) { + var rgb, span, uid; + if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) { return; } - span = $('.hand', this.nodes.uniqueID); - if (!(span && span.nodeName === 'SPAN')) { - return; - } - rgb = IDColor.compute(uid); - style = span.style; - style.color = rgb[3]; - style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; + rgb = IDColor.ids[uid] || IDColor.compute(uid); + span.style.color = rgb[3]; + span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; $.addClass(span, 'painted'); return span.title = 'Highlight posts by this ID'; }, compute: function(uid) { - var hash, rgb; - if (IDColor.ids[uid]) { - return IDColor.ids[uid]; - } - hash = IDColor.hash(uid); - rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; - rgb[3] = (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff'; - return this.ids[uid] = rgb; - }, - hash: function(uid) { - var i, msg; - msg = 0; - i = 0; + var hash, i, rgb; + i = 1; + hash = uid.charCodeAt(0); while (i < 8) { - msg = (msg << 5) - msg + uid.charCodeAt(i++); + hash = (hash << 5) - hash + uid.charCodeAt(i++); } - return msg; + rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; + rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff'); + return this.ids[uid] = rgb; } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index a15b0eadc..742b88a22 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.9.31 - 2014-07-18 +* appchan x - Version 2.9.31 - 2014-07-26 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -13055,7 +13055,7 @@ Unread.read(); return Unread.update(); } else { - return Unread.addPosts(e.detail.newPosts.map(function(fullID) { + return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) { return g.posts[fullID]; })); } @@ -15546,46 +15546,35 @@ if (!Conf['Color User IDs']) { return; } - this.ids = {}; + this.ids = { + Heaven: [0, 0, 0, '#fff'] + }; return Post.callbacks.push({ name: 'Color User IDs', cb: this.node }); }, node: function() { - var rgb, span, style, uid; - if (this.isClone || !(uid = this.info.uniqueID)) { + var rgb, span, uid; + if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) { return; } - span = $('.hand', this.nodes.uniqueID); - if (!(span && span.nodeName === 'SPAN')) { - return; - } - rgb = IDColor.compute(uid); - style = span.style; - style.color = rgb[3]; - style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; + rgb = IDColor.ids[uid] || IDColor.compute(uid); + span.style.color = rgb[3]; + span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; $.addClass(span, 'painted'); return span.title = 'Highlight posts by this ID'; }, compute: function(uid) { - var hash, rgb; - if (IDColor.ids[uid]) { - return IDColor.ids[uid]; - } - hash = IDColor.hash(uid); - rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; - rgb[3] = (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff'; - return this.ids[uid] = rgb; - }, - hash: function(uid) { - var i, msg; - msg = 0; - i = 0; + var hash, i, rgb; + i = 1; + hash = uid.charCodeAt(0); while (i < 8) { - msg = (msg << 5) - msg + uid.charCodeAt(i++); + hash = (hash << 5) - hash + uid.charCodeAt(i++); } - return msg; + rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; + rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff'); + return this.ids[uid] = rgb; } }; diff --git a/src/Miscellaneous/IDColor.coffee b/src/Miscellaneous/IDColor.coffee index 8c5c66391..037949f9b 100755 --- a/src/Miscellaneous/IDColor.coffee +++ b/src/Miscellaneous/IDColor.coffee @@ -1,41 +1,44 @@ IDColor = init: -> return if !Conf['Color User IDs'] - @ids = {} + @ids = { + Heaven: [0, 0, 0, '#fff'] + } Post.callbacks.push name: 'Color User IDs' cb: @node node: -> - return if @isClone or not uid = @info.uniqueID - span = $ '.hand', @nodes.uniqueID - return unless span and span.nodeName is 'SPAN' - rgb = IDColor.compute uid - {style} = span - style.color = rgb[3] - style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})" + return if @isClone or !((uid = @info.uniqueID) and (span = $ 'span.hand', @nodes.uniqueID)) + + rgb = IDColor.ids[uid] or IDColor.compute uid + + # Style the damn node. + span.style.color = rgb[3] + span.style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})" $.addClass span, 'painted' span.title = 'Highlight posts by this ID' compute: (uid) -> - return IDColor.ids[uid] if IDColor.ids[uid] + # Convert chars to integers, bitshift and math to create a larger integer + # Create a nice string of binary + i = 1 + hash = uid.charCodeAt 0 + hash = (hash << 5) - hash + uid.charCodeAt i++ while i < 8 - hash = IDColor.hash uid + # Convert binary string to numerical values with bitshift and '&' truncation. rgb = [ (hash >> 24) & 0xFF (hash >> 16) & 0xFF (hash >> 8) & 0xFF ] - rgb[3] = if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 - '#000' + + # Weight color luminance values, assign a font color that should be readable. + rgb.push if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 + '#000' else '#fff' - @ids[uid] = rgb - hash: (uid) -> - msg = 0 - i = 0 - while i < 8 - msg = (msg << 5) - msg + uid.charCodeAt i++ - msg + # Cache. + @ids[uid] = rgb \ No newline at end of file diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 245630605..856d18cc3 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -126,7 +126,7 @@ Unread = Unread.read() Unread.update() else - Unread.addPosts e.detail.newPosts.map (fullID) -> g.posts[fullID] + Unread.addPosts [].map.call e.detail.newPosts, (fullID) -> g.posts[fullID] readSinglePost: (post) -> {ID} = post