From 4ff91c52c2cbd9756efbc549cc3d2027279edbe9 Mon Sep 17 00:00:00 2001 From: Jordan Bates Date: Wed, 1 May 2013 14:18:29 -0700 Subject: [PATCH] Close #46 --- CHANGELOG.md | 1 + builds/4chan-X.js | 17 +++++++++++++---- builds/4chan-X.user.js | 17 +++++++++++++---- builds/crx/script.js | 17 +++++++++++++---- src/General/Config.coffee | 4 ++++ src/Linkification/Linkify.coffee | 17 ++++++++++++++--- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30d1165c2..a2b72942d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ seaweedchan: - Once again remove /v/ and /vg/ archiving... ;_; - Add paste.installgentoo.com embedding - Added `Posting Success Notifications` option to make "Post Successful!" and "_____ uploaded" notifications optional +- Added `Allow False Positives` option under Linkification, giving the user more control over what's linkified. ### 1.1.6 - 2013-05-01 seaweedchan: diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 1a4e281cc..fcc42e793 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -137,6 +137,7 @@ }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], + 'Allow False Positives': [false, 'Linkify everything, allowing more false positives but reducing missed links'], 'Embedding': [true, 'Embed supported services.'], 'Auto-embed': [false, 'Auto-embed Linkify Embeds.'], 'Link Title': [true, 'Replace the link of a supported site with its actual title. Currently Supported: YouTube, Vimeo, SoundCloud, and Github gists'] @@ -4115,6 +4116,7 @@ }); }, regString: /(\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?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, + regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; @@ -4135,10 +4137,17 @@ nodes = $.frag(); node = snapshot.snapshotItem(i); data = node.data; - if (!(node.parentNode && Linkify.regString.test(data))) { - continue; + if (Conf['Allow False Positives']) { + if (!(node.parentNode && Linkify.regString.test(data))) { + continue; + } + Linkify.regString.lastIndex = 0; + } else { + if (!(node.parentNode && Linkify.regAltString.test(data))) { + continue; + } + Linkify.regAltString.lastIndex = 0; } - Linkify.regString.lastIndex = 0; cypherText = []; if (next = node.nextSibling) { cypher.textContent = node.textContent; @@ -4160,7 +4169,7 @@ if (cypherText.length) { data = cypherText.join(''); } - links = data.match(Linkify.regString); + links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString); for (_j = 0, _len1 = links.length; _j < _len1; _j++) { link = links[_j]; index = data.indexOf(link); diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 5045fd805..186efab94 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -137,6 +137,7 @@ }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], + 'Allow False Positives': [false, 'Linkify everything, allowing more false positives but reducing missed links'], 'Embedding': [true, 'Embed supported services.'], 'Auto-embed': [false, 'Auto-embed Linkify Embeds.'], 'Link Title': [true, 'Replace the link of a supported site with its actual title. Currently Supported: YouTube, Vimeo, SoundCloud, and Github gists'] @@ -4111,6 +4112,7 @@ }); }, regString: /(\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?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, + regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; @@ -4131,10 +4133,17 @@ nodes = $.frag(); node = snapshot.snapshotItem(i); data = node.data; - if (!(node.parentNode && Linkify.regString.test(data))) { - continue; + if (Conf['Allow False Positives']) { + if (!(node.parentNode && Linkify.regString.test(data))) { + continue; + } + Linkify.regString.lastIndex = 0; + } else { + if (!(node.parentNode && Linkify.regAltString.test(data))) { + continue; + } + Linkify.regAltString.lastIndex = 0; } - Linkify.regString.lastIndex = 0; cypherText = []; if (next = node.nextSibling) { cypher.textContent = node.textContent; @@ -4156,7 +4165,7 @@ if (cypherText.length) { data = cypherText.join(''); } - links = data.match(Linkify.regString); + links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString); for (_j = 0, _len1 = links.length; _j < _len1; _j++) { link = links[_j]; index = data.indexOf(link); diff --git a/builds/crx/script.js b/builds/crx/script.js index 85ec6ca8b..fb450a981 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -118,6 +118,7 @@ }, 'Linkification': { 'Linkify': [true, 'Convert text into links where applicable.'], + 'Allow False Positives': [false, 'Linkify everything, allowing more false positives but reducing missed links'], 'Embedding': [true, 'Embed supported services.'], 'Auto-embed': [false, 'Auto-embed Linkify Embeds.'], 'Link Title': [true, 'Replace the link of a supported site with its actual title. Currently Supported: YouTube, Vimeo, SoundCloud, and Github gists'] @@ -4113,6 +4114,7 @@ }); }, regString: /(\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?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi, + regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi, cypher: $.el('div'), node: function() { var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; @@ -4133,10 +4135,17 @@ nodes = $.frag(); node = snapshot.snapshotItem(i); data = node.data; - if (!(node.parentNode && Linkify.regString.test(data))) { - continue; + if (Conf['Allow False Positives']) { + if (!(node.parentNode && Linkify.regString.test(data))) { + continue; + } + Linkify.regString.lastIndex = 0; + } else { + if (!(node.parentNode && Linkify.regAltString.test(data))) { + continue; + } + Linkify.regAltString.lastIndex = 0; } - Linkify.regString.lastIndex = 0; cypherText = []; if (next = node.nextSibling) { cypher.textContent = node.textContent; @@ -4158,7 +4167,7 @@ if (cypherText.length) { data = cypherText.join(''); } - links = data.match(Linkify.regString); + links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString); for (_j = 0, _len1 = links.length; _j < _len1; _j++) { link = links[_j]; index = data.indexOf(link); diff --git a/src/General/Config.coffee b/src/General/Config.coffee index a2151fee1..11183bb45 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -79,6 +79,10 @@ Config = true 'Convert text into links where applicable.' ] + 'Allow False Positives': [ + false + 'Linkify everything, allowing more false positives but reducing missed links' + ] 'Embedding': [ true 'Embed supported services.' diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index d65153dfa..6e8babf86 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -26,6 +26,8 @@ Linkify = [^\s'"]+ )///gi + regAltString: ///(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\://){1}\S+)///gi + cypher: $.el 'div' node: -> @@ -44,9 +46,15 @@ Linkify = data = node.data # Test for valid links - continue unless node.parentNode and Linkify.regString.test data + if Conf['Allow False Positives'] + continue unless node.parentNode and Linkify.regString.test data - Linkify.regString.lastIndex = 0 + Linkify.regString.lastIndex = 0 + + else + continue unless node.parentNode and Linkify.regAltString.test data + + Linkify.regAltString.lastIndex = 0 cypherText = [] @@ -70,7 +78,10 @@ Linkify = if cypherText.length data = cypherText.join '' - links = data.match Linkify.regString + links = if Conf['Allow False Positives'] + data.match Linkify.regString + else + data.match Linkify.regAltString for link in links index = data.indexOf link