diff --git a/LICENSE b/LICENSE index eed859386..4ae7b6127 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.3.1 - 2013-08-11 +* appchan x - Version 2.3.1 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 9f95c99b1..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-10 +* 4chan X - Version 1.2.25 - 2013-08-12 * * 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); } @@ -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']) { @@ -4403,16 +4403,21 @@ } 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)) { + links = []; + if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(node, this); + Linkify.gatherLinks(snapshot, this, node, links, i); + } + _ref = links.reverse(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + range = _ref[_i]; + this.nodes.links.push(Linkify.makeLink(range, this)); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -4431,12 +4436,11 @@ } } }, - gatherLinks: function(node, post) { - var data, index, len, len2, link, links, match, range, _i, _len, _ref; + gatherLinks: function(snapshot, post, node, links, i) { + 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]; @@ -4451,34 +4455,32 @@ } Linkify.regString.lastIndex = 0; if (match) { - Linkify.seek(match, node, post); - } - _ref = links.reverse(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - range = _ref[_i]; - Linkify.makeLink(range, post); + links.push(Linkify.seek(snapshot, post, node, links, match, i)); } }, - seek: function(match, node, post) { + seek: function(snapshot, post, node, links, match, i) { var data, index, 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)) { - range.setEnd(node, result.index); + index = result.index; + range.setEnd(node, index); + Linkify.regString.lastIndex = index; + Linkify.gatherLinks(snapshot, post, node, links, i); + return range; } } if (range.collapsed) { - range.setEndAfter(node); + range.setEnd(node, node.data.length); } - return Linkify.makeLink(range, post); + return range; }, - makeLink: function(range, post) { + makeLink: function(range) { var a, link; link = range.toString(); @@ -4489,8 +4491,9 @@ target: '_blank', href: link }); - range.surroundContents(a); - post.nodes.links.push(a); + $.add(a, range.extractContents()); + range.insertNode(a); + return a; }, services: function(link) { var href, key, match, type, _ref; diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index b9697add4..016133d3a 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -18,7 +18,7 @@ // ==/UserScript== /* -* appchan x - Version 2.3.1 - 2013-08-11 +* appchan x - Version 2.3.1 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -6674,7 +6674,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); } @@ -6687,7 +6687,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']) { @@ -6702,16 +6702,21 @@ } 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)) { + links = []; + if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(node, this); + Linkify.gatherLinks(snapshot, this, node, links, i); + } + _ref = links.reverse(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + range = _ref[_i]; + this.nodes.links.push(Linkify.makeLink(range, this)); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -6730,12 +6735,11 @@ } } }, - gatherLinks: function(node, post) { - var data, index, len, len2, link, links, match, range, _i, _len, _ref; + gatherLinks: function(snapshot, post, node, links, i) { + 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]; @@ -6750,34 +6754,32 @@ } Linkify.regString.lastIndex = 0; if (match) { - Linkify.seek(match, node, post); - } - _ref = links.reverse(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - range = _ref[_i]; - Linkify.makeLink(range, post); + links.push(Linkify.seek(snapshot, post, node, links, match, i)); } }, - seek: function(match, node, post) { + seek: function(snapshot, post, node, links, match, i) { var data, index, 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)) { - range.setEnd(node, result.index); + index = result.index; + range.setEnd(node, index); + Linkify.regString.lastIndex = index; + Linkify.gatherLinks(snapshot, post, node, links, i); + return range; } } if (range.collapsed) { - range.setEndAfter(node); + range.setEnd(node, node.data.length); } - return Linkify.makeLink(range, post); + return range; }, - makeLink: function(range, post) { + makeLink: function(range) { var a, link; link = range.toString(); @@ -6788,8 +6790,9 @@ target: '_blank', href: link }); - range.surroundContents(a); - post.nodes.links.push(a); + $.add(a, range.extractContents()); + range.insertNode(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 be1289ad1..052a1525c 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.3.1 - 2013-08-11 +* appchan x - Version 2.3.1 - 2013-08-12 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -6681,7 +6681,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); } @@ -6694,7 +6694,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']) { @@ -6709,16 +6709,21 @@ } 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)) { + links = []; + if (Linkify.regString.test(node.data)) { Linkify.regString.lastIndex = 0; - Linkify.gatherLinks(node, this); + Linkify.gatherLinks(snapshot, this, node, links, i); + } + _ref = links.reverse(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + range = _ref[_i]; + this.nodes.links.push(Linkify.makeLink(range, this)); } } if (!(Conf['Embedding'] || Conf['Link Title'])) { @@ -6737,12 +6742,11 @@ } } }, - gatherLinks: function(node, post) { - var data, index, len, len2, link, links, match, range, _i, _len, _ref; + gatherLinks: function(snapshot, post, node, links, i) { + 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]; @@ -6757,34 +6761,32 @@ } Linkify.regString.lastIndex = 0; if (match) { - Linkify.seek(match, node, post); - } - _ref = links.reverse(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - range = _ref[_i]; - Linkify.makeLink(range, post); + links.push(Linkify.seek(snapshot, post, node, links, match, i)); } }, - seek: function(match, node, post) { + seek: function(snapshot, post, node, links, match, i) { var data, index, 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)) { - range.setEnd(node, result.index); + index = result.index; + range.setEnd(node, index); + Linkify.regString.lastIndex = index; + Linkify.gatherLinks(snapshot, post, node, links, i); + return range; } } if (range.collapsed) { - range.setEndAfter(node); + range.setEnd(node, node.data.length); } - return Linkify.makeLink(range, post); + return range; }, - makeLink: function(range, post) { + makeLink: function(range) { var a, link; link = range.toString(); @@ -6795,8 +6797,9 @@ target: '_blank', href: link }); - range.surroundContents(a); - post.nodes.links.push(a); + $.add(a, range.extractContents()); + range.insertNode(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 b935fba66..f017b2b3d 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,19 @@ 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" + links = [] - 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, links, i + + for range in links.reverse() + @nodes.links.push Linkify.makeLink range, @ return unless Conf['Embedding'] or Conf['Link Title'] @@ -66,10 +68,9 @@ Linkify = return - gatherLinks: (node, post) -> + gatherLinks: (snapshot, post, node, links, i) -> {data} = node len = data.length - links = [] while (match = Linkify.regString.exec data) {index} = match @@ -86,31 +87,31 @@ Linkify = Linkify.regString.lastIndex = 0 if match - Linkify.seek match, node, post - - for range in links.reverse() - Linkify.makeLink range, post + links.push Linkify.seek snapshot, post, node, links, match, i return - seek: (match, node, post) -> - {index} = match + seek: (snapshot, post, node, links, 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 - range.setEnd node, result.index + {index} = result + range.setEnd node, index + Linkify.regString.lastIndex = index + Linkify.gatherLinks snapshot, post, node, links, i + return range if range.collapsed - range.setEndAfter node + range.setEnd node, node.data.length - Linkify.makeLink range, post + range - makeLink: (range, post) -> + makeLink: (range) -> link = range.toString() link = if link.contains ':' @@ -127,9 +128,9 @@ Linkify = rel: 'nofollow noreferrer' target: '_blank' href: link - range.surroundContents a - post.nodes.links.push a - return + $.add a, range.extractContents() + range.insertNode a + a services: (link) -> href = link.href