From 708f56c759ed518dd583a628150d526b1f342e28 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 11 Aug 2013 23:25:43 -0700 Subject: [PATCH 1/5] Strengthen Linkifier Now can linkify within code tags, providing the initial 'check' is successful. --- LICENSE | 2 +- builds/4chan-X.user.js | 29 ++++++++++++++--------------- builds/crx/script.js | 29 ++++++++++++++--------------- src/Linkification/Linkify.coffee | 28 +++++++++++++--------------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/LICENSE b/LICENSE index a98499ab6..d2ae960d0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.2.25 - 2013-08-10 +* 4chan X - Version 1.2.25 - 2013-08-11 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 9f95c99b1..9baed19bb 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -19,7 +19,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.2.25 - 2013-08-10 +* 4chan X - Version 1.2.25 - 2013-08-11 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -4375,7 +4375,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[^\s@]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; + this.regString = Conf['Allow False Positives'] ? /(\b([-a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[\d]+\.[\d]+\.[\d]+\.[\d]+\/|[a-z]{3,}:[a-z0-9?]|[^\s@]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } @@ -4403,16 +4403,15 @@ } return; } - snapshot = $.X('.//text()', this.nodes.comment); + snapshot = $.X('.//br|.//text()', this.nodes.comment); i = 0; while (node = snapshot.snapshotItem(i++)) { if (node.parentElement.nodeName === "A") { continue; } - data = node.data; - if (Linkify.regString.test(data)) { + if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(node, this); + Linkify.gatherLinks(snapshot, this, node, i); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -4431,7 +4430,7 @@ } } }, - gatherLinks: function(node, post) { + gatherLinks: function(snapshot, post, node, i) { var data, index, len, len2, link, links, match, range, _i, _len, _ref; data = node.data; @@ -4451,7 +4450,7 @@ } Linkify.regString.lastIndex = 0; if (match) { - Linkify.seek(match, node, post); + links.push(Linkify.seek(snapshot, node, match, i)); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -4459,14 +4458,13 @@ Linkify.makeLink(range, post); } }, - seek: function(match, node, post) { - var data, index, link, next, range, result; + seek: function(snapshot, node, match, i) { + var data, link, next, range, result; - index = match.index; link = match[0]; range = document.createRange(); - range.setStart(node, index); - while ((next = node.nextSibling) && next.nodeName !== 'BR') { + range.setStart(node, match.index); + while ((next = snapshot.snapshotItem(i++)) && next.nodeName !== 'BR') { node = next; data = node.data; if (result = /[\s'"]/.exec(data)) { @@ -4476,7 +4474,7 @@ if (range.collapsed) { range.setEndAfter(node); } - return Linkify.makeLink(range, post); + return range; }, makeLink: function(range, post) { var a, link; @@ -4489,7 +4487,8 @@ target: '_blank', href: link }); - range.surroundContents(a); + $.add(a, range.extractContents()); + range.insertNode(a); post.nodes.links.push(a); }, services: function(link) { diff --git a/builds/crx/script.js b/builds/crx/script.js index 00e3f50ad..d967cac01 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.2.25 - 2013-08-10 +* 4chan X - Version 1.2.25 - 2013-08-11 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -4380,7 +4380,7 @@ if (g.VIEW === 'catalog' || !Conf['Linkify']) { return; } - this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[^\s@]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; + this.regString = Conf['Allow False Positives'] ? /(\b([-a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[\d]+\.[\d]+\.[\d]+\.[\d]+\/|[a-z]{3,}:[a-z0-9?]|[^\s@]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi; if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } @@ -4408,16 +4408,15 @@ } return; } - snapshot = $.X('.//text()', this.nodes.comment); + snapshot = $.X('.//br|.//text()', this.nodes.comment); i = 0; while (node = snapshot.snapshotItem(i++)) { if (node.parentElement.nodeName === "A") { continue; } - data = node.data; - if (Linkify.regString.test(data)) { + if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(node, this); + Linkify.gatherLinks(snapshot, this, node, i); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -4436,7 +4435,7 @@ } } }, - gatherLinks: function(node, post) { + gatherLinks: function(snapshot, post, node, i) { var data, index, len, len2, link, links, match, range, _i, _len, _ref; data = node.data; @@ -4456,7 +4455,7 @@ } Linkify.regString.lastIndex = 0; if (match) { - Linkify.seek(match, node, post); + links.push(Linkify.seek(snapshot, node, match, i)); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -4464,14 +4463,13 @@ Linkify.makeLink(range, post); } }, - seek: function(match, node, post) { - var data, index, link, next, range, result; + seek: function(snapshot, node, match, i) { + var data, link, next, range, result; - index = match.index; link = match[0]; range = document.createRange(); - range.setStart(node, index); - while ((next = node.nextSibling) && next.nodeName !== 'BR') { + range.setStart(node, match.index); + while ((next = snapshot.snapshotItem(i++)) && next.nodeName !== 'BR') { node = next; data = node.data; if (result = /[\s'"]/.exec(data)) { @@ -4481,7 +4479,7 @@ if (range.collapsed) { range.setEndAfter(node); } - return Linkify.makeLink(range, post); + return range; }, makeLink: function(range, post) { var a, link; @@ -4494,7 +4492,8 @@ target: '_blank', href: link }); - range.surroundContents(a); + $.add(a, range.extractContents()); + range.insertNode(a); post.nodes.links.push(a); }, services: function(link) { diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index b935fba66..5da99d362 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -5,13 +5,13 @@ Linkify = @regString = if Conf['Allow False Positives'] ///( \b( - [a-z]+:// + [-a-z]+:// | [a-z]{3,}\.[-a-z0-9]+\.[a-z] | [-a-z0-9]+\.[a-z] | - [0-9]+\.[0-9]+\.[0-9]+\.[0-9] + [\d]+\.[\d]+\.[\d]+\.[\d]+/ | [a-z]{3,}:[a-z0-9?] | @@ -43,17 +43,15 @@ Linkify = return - snapshot = $.X './/text()', @nodes.comment + snapshot = $.X './/br|.//text()', @nodes.comment i = 0 while node = snapshot.snapshotItem i++ continue if node.parentElement.nodeName is "A" - data = node.data - - if Linkify.regString.test data + if Linkify.regString.test node.data Linkify.regString.lastIndex = 0 - Linkify.gatherLinks node, @ + Linkify.gatherLinks snapshot, @, node, i return unless Conf['Embedding'] or Conf['Link Title'] @@ -66,7 +64,7 @@ Linkify = return - gatherLinks: (node, post) -> + gatherLinks: (snapshot, post, node, i) -> {data} = node len = data.length links = [] @@ -86,20 +84,19 @@ Linkify = Linkify.regString.lastIndex = 0 if match - Linkify.seek match, node, post + links.push Linkify.seek snapshot, node, match, i for range in links.reverse() Linkify.makeLink range, post return - seek: (match, node, post) -> - {index} = match + seek: (snapshot, node, match, i) -> link = match[0] range = document.createRange() - range.setStart node, index + range.setStart node, match.index - while (next = node.nextSibling) and next.nodeName isnt 'BR' + while (next = snapshot.snapshotItem i++) and next.nodeName isnt 'BR' node = next data = node.data if result = /[\s'"]/.exec data @@ -108,7 +105,7 @@ Linkify = if range.collapsed range.setEndAfter node - Linkify.makeLink range, post + range makeLink: (range, post) -> link = range.toString() @@ -127,7 +124,8 @@ Linkify = rel: 'nofollow noreferrer' target: '_blank' href: link - range.surroundContents a + $.add a, range.extractContents() + range.insertNode a post.nodes.links.push a return From 045ba42296022d9492d2ce33f70c00b1ad6454ca Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 11 Aug 2013 23:31:33 -0700 Subject: [PATCH 2/5] Single-handedly one of the most expensive features in 4chan X? LETS ADD RECURSION! --- builds/4chan-X.user.js | 11 +++++++---- builds/crx/script.js | 11 +++++++---- src/Linkification/Linkify.coffee | 9 ++++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 9baed19bb..4b80565ec 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4450,7 +4450,7 @@ } Linkify.regString.lastIndex = 0; if (match) { - links.push(Linkify.seek(snapshot, node, match, i)); + links.push(Linkify.seek(snapshot, post, node, match, i)); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -4458,8 +4458,8 @@ Linkify.makeLink(range, post); } }, - seek: function(snapshot, node, match, i) { - var data, link, next, range, result; + seek: function(snapshot, post, node, match, i) { + var data, index, link, next, range, result; link = match[0]; range = document.createRange(); @@ -4468,7 +4468,10 @@ node = next; data = node.data; if (result = /[\s'"]/.exec(data)) { - range.setEnd(node, result.index); + index = result.index; + range.setEnd(node, index); + Linkify.regString.lastIndex = index; + Linkify.gatherLinks(snapshot, post, node, i); } } if (range.collapsed) { diff --git a/builds/crx/script.js b/builds/crx/script.js index d967cac01..60987bcda 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4455,7 +4455,7 @@ } Linkify.regString.lastIndex = 0; if (match) { - links.push(Linkify.seek(snapshot, node, match, i)); + links.push(Linkify.seek(snapshot, post, node, match, i)); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -4463,8 +4463,8 @@ Linkify.makeLink(range, post); } }, - seek: function(snapshot, node, match, i) { - var data, link, next, range, result; + seek: function(snapshot, post, node, match, i) { + var data, index, link, next, range, result; link = match[0]; range = document.createRange(); @@ -4473,7 +4473,10 @@ node = next; data = node.data; if (result = /[\s'"]/.exec(data)) { - range.setEnd(node, result.index); + index = result.index; + range.setEnd(node, index); + Linkify.regString.lastIndex = index; + Linkify.gatherLinks(snapshot, post, node, i); } } if (range.collapsed) { diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 5da99d362..8996da4bd 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -84,14 +84,14 @@ Linkify = Linkify.regString.lastIndex = 0 if match - links.push Linkify.seek snapshot, node, match, i + links.push Linkify.seek snapshot, post, node, match, i for range in links.reverse() Linkify.makeLink range, post return - seek: (snapshot, node, match, i) -> + seek: (snapshot, post, node, match, i) -> link = match[0] range = document.createRange() range.setStart node, match.index @@ -100,7 +100,10 @@ Linkify = node = next data = node.data if result = /[\s'"]/.exec data - range.setEnd node, result.index + {index} = result + range.setEnd node, index + Linkify.regString.lastIndex = index + Linkify.gatherLinks snapshot, post, node, i if range.collapsed range.setEndAfter node From 256e20aea5147a7a20ed1b1d5ec367a2c1b31836 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 11 Aug 2013 23:33:44 -0700 Subject: [PATCH 3/5] Since we're adding recursion, we should probably move our variable declaration outside of the potential recursive function --- builds/4chan-X.user.js | 16 ++++++++-------- builds/crx/script.js | 16 ++++++++-------- src/Linkification/Linkify.coffee | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 4b80565ec..a9f20840c 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4388,7 +4388,7 @@ }); }, node: function() { - var data, el, i, items, node, range, snapshot; + var data, el, i, items, links, node, range, snapshot, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4409,10 +4409,16 @@ if (node.parentElement.nodeName === "A") { continue; } + links = []; if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; Linkify.gatherLinks(snapshot, this, node, i); } + _ref = links.reverse(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + range = _ref[_i]; + Linkify.makeLink(range, post); + } } if (!(Conf['Embedding'] || Conf['Link Title'])) { return; @@ -4431,11 +4437,10 @@ } }, gatherLinks: function(snapshot, post, node, i) { - var data, index, len, len2, link, links, match, range, _i, _len, _ref; + var data, index, len, len2, link, match, range; data = node.data; len = data.length; - links = []; while ((match = Linkify.regString.exec(data))) { index = match.index; link = match[0]; @@ -4452,11 +4457,6 @@ if (match) { links.push(Linkify.seek(snapshot, post, node, match, i)); } - _ref = links.reverse(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - range = _ref[_i]; - Linkify.makeLink(range, post); - } }, seek: function(snapshot, post, node, match, i) { var data, index, link, next, range, result; diff --git a/builds/crx/script.js b/builds/crx/script.js index 60987bcda..567de0215 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4393,7 +4393,7 @@ }); }, node: function() { - var data, el, i, items, node, range, snapshot; + var data, el, i, items, links, node, range, snapshot, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4414,10 +4414,16 @@ if (node.parentElement.nodeName === "A") { continue; } + links = []; if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; Linkify.gatherLinks(snapshot, this, node, i); } + _ref = links.reverse(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + range = _ref[_i]; + Linkify.makeLink(range, post); + } } if (!(Conf['Embedding'] || Conf['Link Title'])) { return; @@ -4436,11 +4442,10 @@ } }, gatherLinks: function(snapshot, post, node, i) { - var data, index, len, len2, link, links, match, range, _i, _len, _ref; + var data, index, len, len2, link, match, range; data = node.data; len = data.length; - links = []; while ((match = Linkify.regString.exec(data))) { index = match.index; link = match[0]; @@ -4457,11 +4462,6 @@ if (match) { links.push(Linkify.seek(snapshot, post, node, match, i)); } - _ref = links.reverse(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - range = _ref[_i]; - Linkify.makeLink(range, post); - } }, seek: function(snapshot, post, node, match, i) { var data, index, link, next, range, result; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 8996da4bd..9ab8209a5 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -48,11 +48,15 @@ Linkify = while node = snapshot.snapshotItem i++ continue if node.parentElement.nodeName is "A" + links = [] if Linkify.regString.test node.data Linkify.regString.lastIndex = 0 Linkify.gatherLinks snapshot, @, node, i + for range in links.reverse() + Linkify.makeLink range, post + return unless Conf['Embedding'] or Conf['Link Title'] items = @nodes.links @@ -67,7 +71,6 @@ Linkify = gatherLinks: (snapshot, post, node, i) -> {data} = node len = data.length - links = [] while (match = Linkify.regString.exec data) {index} = match @@ -86,9 +89,6 @@ Linkify = if match links.push Linkify.seek snapshot, post, node, match, i - for range in links.reverse() - Linkify.makeLink range, post - return seek: (snapshot, post, node, match, i) -> From a8ee9b39929320748ce69dd5b51f2a482c4941cf Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 11 Aug 2013 23:44:05 -0700 Subject: [PATCH 4/5] Oops, accidentally got tired. --- builds/4chan-X.user.js | 17 +++++++++-------- builds/crx/script.js | 17 +++++++++-------- src/Linkification/Linkify.coffee | 18 +++++++++--------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index a9f20840c..b7c190b1f 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4412,12 +4412,12 @@ links = []; if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(snapshot, this, node, i); + Linkify.gatherLinks(snapshot, this, node, links, i); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { range = _ref[_i]; - Linkify.makeLink(range, post); + this.nodes.links.push(Linkify.makeLink(range, this)); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -4436,7 +4436,7 @@ } } }, - gatherLinks: function(snapshot, post, node, i) { + gatherLinks: function(snapshot, post, node, links, i) { var data, index, len, len2, link, match, range; data = node.data; @@ -4455,10 +4455,10 @@ } Linkify.regString.lastIndex = 0; if (match) { - links.push(Linkify.seek(snapshot, post, node, match, i)); + links.push(Linkify.seek(snapshot, post, node, links, match, i)); } }, - seek: function(snapshot, post, node, match, i) { + seek: function(snapshot, post, node, links, match, i) { var data, index, link, next, range, result; link = match[0]; @@ -4471,7 +4471,8 @@ index = result.index; range.setEnd(node, index); Linkify.regString.lastIndex = index; - Linkify.gatherLinks(snapshot, post, node, i); + Linkify.gatherLinks(snapshot, post, node, links, i); + return range; } } if (range.collapsed) { @@ -4479,7 +4480,7 @@ } return range; }, - makeLink: function(range, post) { + makeLink: function(range) { var a, link; link = range.toString(); @@ -4492,7 +4493,7 @@ }); $.add(a, range.extractContents()); range.insertNode(a); - post.nodes.links.push(a); + return a; }, services: function(link) { var href, key, match, type, _ref; diff --git a/builds/crx/script.js b/builds/crx/script.js index 567de0215..d7146a8ab 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4417,12 +4417,12 @@ links = []; if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(snapshot, this, node, i); + Linkify.gatherLinks(snapshot, this, node, links, i); } _ref = links.reverse(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { range = _ref[_i]; - Linkify.makeLink(range, post); + this.nodes.links.push(Linkify.makeLink(range, this)); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -4441,7 +4441,7 @@ } } }, - gatherLinks: function(snapshot, post, node, i) { + gatherLinks: function(snapshot, post, node, links, i) { var data, index, len, len2, link, match, range; data = node.data; @@ -4460,10 +4460,10 @@ } Linkify.regString.lastIndex = 0; if (match) { - links.push(Linkify.seek(snapshot, post, node, match, i)); + links.push(Linkify.seek(snapshot, post, node, links, match, i)); } }, - seek: function(snapshot, post, node, match, i) { + seek: function(snapshot, post, node, links, match, i) { var data, index, link, next, range, result; link = match[0]; @@ -4476,7 +4476,8 @@ index = result.index; range.setEnd(node, index); Linkify.regString.lastIndex = index; - Linkify.gatherLinks(snapshot, post, node, i); + Linkify.gatherLinks(snapshot, post, node, links, i); + return range; } } if (range.collapsed) { @@ -4484,7 +4485,7 @@ } return range; }, - makeLink: function(range, post) { + makeLink: function(range) { var a, link; link = range.toString(); @@ -4497,7 +4498,7 @@ }); $.add(a, range.extractContents()); range.insertNode(a); - post.nodes.links.push(a); + return a; }, services: function(link) { var href, key, match, type, _ref; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 9ab8209a5..74dca4b22 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -52,10 +52,10 @@ Linkify = if Linkify.regString.test node.data Linkify.regString.lastIndex = 0 - Linkify.gatherLinks snapshot, @, node, i + Linkify.gatherLinks snapshot, @, node, links, i for range in links.reverse() - Linkify.makeLink range, post + @nodes.links.push Linkify.makeLink range, @ return unless Conf['Embedding'] or Conf['Link Title'] @@ -68,7 +68,7 @@ Linkify = return - gatherLinks: (snapshot, post, node, i) -> + gatherLinks: (snapshot, post, node, links, i) -> {data} = node len = data.length @@ -87,11 +87,11 @@ Linkify = Linkify.regString.lastIndex = 0 if match - links.push Linkify.seek snapshot, post, node, match, i + links.push Linkify.seek snapshot, post, node, links, match, i return - seek: (snapshot, post, node, match, i) -> + seek: (snapshot, post, node, links, match, i) -> link = match[0] range = document.createRange() range.setStart node, match.index @@ -103,14 +103,15 @@ Linkify = {index} = result range.setEnd node, index Linkify.regString.lastIndex = index - Linkify.gatherLinks snapshot, post, node, i + Linkify.gatherLinks snapshot, post, node, links, i + return range if range.collapsed range.setEndAfter node range - makeLink: (range, post) -> + makeLink: (range) -> link = range.toString() link = if link.contains ':' @@ -129,8 +130,7 @@ Linkify = href: link $.add a, range.extractContents() range.insertNode a - post.nodes.links.push a - return + a services: (link) -> href = link.href From 22c4fdede5e56b858441acfd146ffb2380efde9b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 12 Aug 2013 00:33:34 -0700 Subject: [PATCH 5/5] Range.setEndAfter doesn't work in fragments But Range.setEnd does? --- LICENSE | 2 +- builds/4chan-X.user.js | 4 ++-- builds/crx/script.js | 4 ++-- src/Linkification/Linkify.coffee | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index d2ae960d0..468617e9f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.2.25 - 2013-08-11 +* 4chan X - Version 1.2.25 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index b7c190b1f..5564ab3d3 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -19,7 +19,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.2.25 - 2013-08-11 +* 4chan X - Version 1.2.25 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -4476,7 +4476,7 @@ } } if (range.collapsed) { - range.setEndAfter(node); + range.setEnd(node, node.data.length); } return range; }, diff --git a/builds/crx/script.js b/builds/crx/script.js index d7146a8ab..b2166a115 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.2.25 - 2013-08-11 +* 4chan X - Version 1.2.25 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -4481,7 +4481,7 @@ } } if (range.collapsed) { - range.setEndAfter(node); + range.setEnd(node, node.data.length); } return range; }, diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 74dca4b22..f017b2b3d 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -107,7 +107,7 @@ Linkify = return range if range.collapsed - range.setEndAfter node + range.setEnd node, node.data.length range