From 0cc7b8ee29bdd7bd663842978adda8775a6b295e Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Aug 2013 15:12:27 -0700 Subject: [PATCH 1/3] Couple small changes --- builds/4chan-X.user.js | 10 ++++++---- builds/crx/script.js | 10 ++++++---- src/Miscellaneous/ColorUserIDs.coffee | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index bbddd4f10..110c6975b 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -8815,7 +8815,7 @@ IDColor = { init: function() { - if (!Conf['Color User IDs']) { + if (g.VIEW === 'catalog' || !Conf['Color user IDs']) { return; } return Post.prototype.callbacks.push({ @@ -8826,9 +8826,11 @@ node: function() { var str, uid; - str = this.info.uniqueID; + if (this.isClone || !(str = this.info.uniqueID)) { + return; + } uid = $('.hand', this.nodes.uniqueID); - if (!(str && uid && uid.nodeName === 'SPAN')) { + if (!(uid && uid.nodeName === 'SPAN')) { return; } return uid.style.cssText = IDColor.css(IDColor.ids[str] || IDColor.compute(str)); @@ -8837,7 +8839,7 @@ compute: function(str) { var hash, rgb; - hash = this.hash(str); + hash = IDColor.hash(str); 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; this.ids[str] = rgb; diff --git a/builds/crx/script.js b/builds/crx/script.js index 1f5f1120d..b198cb92b 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -8802,7 +8802,7 @@ IDColor = { init: function() { - if (!Conf['Color User IDs']) { + if (g.VIEW === 'catalog' || !Conf['Color user IDs']) { return; } return Post.prototype.callbacks.push({ @@ -8813,9 +8813,11 @@ node: function() { var str, uid; - str = this.info.uniqueID; + if (this.isClone || !(str = this.info.uniqueID)) { + return; + } uid = $('.hand', this.nodes.uniqueID); - if (!(str && uid && uid.nodeName === 'SPAN')) { + if (!(uid && uid.nodeName === 'SPAN')) { return; } return uid.style.cssText = IDColor.css(IDColor.ids[str] || IDColor.compute(str)); @@ -8824,7 +8826,7 @@ compute: function(str) { var hash, rgb; - hash = this.hash(str); + hash = IDColor.hash(str); 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; this.ids[str] = rgb; diff --git a/src/Miscellaneous/ColorUserIDs.coffee b/src/Miscellaneous/ColorUserIDs.coffee index a0b442a17..754dd5add 100644 --- a/src/Miscellaneous/ColorUserIDs.coffee +++ b/src/Miscellaneous/ColorUserIDs.coffee @@ -1,21 +1,21 @@ IDColor = init: -> - return unless Conf['Color User IDs'] + return if g.VIEW is 'catalog' or !Conf['Color user IDs'] Post::callbacks.push name: 'Color User IDs' cb: @node node: -> - str = @info.uniqueID + return if @isClone or not str = @info.uniqueID uid = $ '.hand', @nodes.uniqueID - return unless str and uid and uid.nodeName is 'SPAN' + return unless uid and uid.nodeName is 'SPAN' uid.style.cssText = IDColor.css IDColor.ids[str] or IDColor.compute str ids: {} compute: (str) -> - hash = @hash str + hash = IDColor.hash str rgb = [ (hash >> 24) & 0xFF From f4e80537834662a03a509b7ca5bef663584dae18 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Aug 2013 15:20:18 -0700 Subject: [PATCH 2/3] Prevent jp from matching jpg --- builds/4chan-X.user.js | 2 +- builds/crx/script.js | 2 +- src/Linkification/Linkify.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 110c6975b..bd5e373f4 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4425,7 +4425,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = /(?:[a-z][-\w]+:([a-z\d%\/])|www\d{0,3}[.]|[-a-z\d.]+[.](com|net|org|jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi)|[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}|[-\w\d.@]+@[a-z\d.-]+\.[a-z\d])/i; + this.regString = /(?:[a-z][-\w]+:([a-z\d%\/])|www\d{0,3}[.]|[-a-z\d.]+[.](com|net|org|co\.jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi)|[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}|[-\w\d.@]+@[a-z\d.-]+\.[a-z\d])/i; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } diff --git a/builds/crx/script.js b/builds/crx/script.js index b198cb92b..166daccc8 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4431,7 +4431,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = /(?:[a-z][-\w]+:([a-z\d%\/])|www\d{0,3}[.]|[-a-z\d.]+[.](com|net|org|jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi)|[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}|[-\w\d.@]+@[a-z\d.-]+\.[a-z\d])/i; + this.regString = /(?:[a-z][-\w]+:([a-z\d%\/])|www\d{0,3}[.]|[-a-z\d.]+[.](com|net|org|co\.jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi)|[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}|[-\w\d.@]+@[a-z\d.-]+\.[a-z\d])/i; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 35d722b47..7d1085aa8 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -14,7 +14,7 @@ Linkify = # This should account for virtually all links posted without www or http: # If it misses any, screw it. No, I will not add canv.as [-a-z\d.]+[.]( - com|net|org|jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi + com|net|org|co\.jp|uk|ru|be|tv|xxx|edu|gov|cd|es|de|se|tk|dk|io|fm|fi ) | # IPv4 Addresses From 976f539c8cc0e98895896234fd85260de5d50f01 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Aug 2013 15:34:39 -0700 Subject: [PATCH 3/3] Don't allow indexes larger than start node length --- builds/4chan-X.user.js | 8 ++++---- builds/crx/script.js | 8 ++++---- src/Linkification/Linkify.coffee | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index bd5e373f4..ec0d6b402 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4438,7 +4438,7 @@ }); }, node: function() { - var data, el, end, endNode, i, index, items, lIndex, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; + var data, el, end, endNode, i, index, items, lIndex, len, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4484,10 +4484,10 @@ } range = Linkify.makeRange(node, endNode, index, length); if (link = Linkify.regString.exec(text = range.toString())) { - if (lIndex = link.index) { - range.setStart(node, lIndex + index); - text = text.slice(0, lIndex); + if ((lIndex = link.index) && (len = lIndex + index) < node.data.length) { + range.setStart(node, len); } + text = text.slice(0, lIndex); links.push([range, text]); } break; diff --git a/builds/crx/script.js b/builds/crx/script.js index 166daccc8..7e63a60bb 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4444,7 +4444,7 @@ }); }, node: function() { - var data, el, end, endNode, i, index, items, lIndex, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; + var data, el, end, endNode, i, index, items, lIndex, len, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4490,10 +4490,10 @@ } range = Linkify.makeRange(node, endNode, index, length); if (link = Linkify.regString.exec(text = range.toString())) { - if (lIndex = link.index) { - range.setStart(node, lIndex + index); - text = text.slice(0, lIndex); + if ((lIndex = link.index) && (len = lIndex + index) < node.data.length) { + range.setStart(node, len); } + text = text.slice(0, lIndex); links.push([range, text]); } break; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 7d1085aa8..ea237719e 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -76,9 +76,9 @@ Linkify = test.lastIndex = 0 if length is endNode.data.length range = Linkify.makeRange node, endNode, index, length if link = Linkify.regString.exec text = range.toString() - if lIndex = link.index - range.setStart node, lIndex + index - text = text[...lIndex] + if (lIndex = link.index) and (len = lIndex + index) < node.data.length + range.setStart node, len + text = text[...lIndex] links.push [range, text] break