From fb8a856fbab5e82324f5fb345a297ba2c2f5951f Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Aug 2013 19:24:13 -0700 Subject: [PATCH] Come on, I'm smarter than this --- builds/4chan-X.user.js | 14 ++------------ builds/crx/script.js | 14 ++------------ src/Linkification/Linkify.coffee | 8 +------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 659f6ceab..9916f84e2 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4525,7 +4525,7 @@ return range; }, makeLink: function(range) { - var a, char, i, len, text, toggle, trim; + var a, char, len, text, trim; text = range.toString(); trim = function() { @@ -4541,20 +4541,10 @@ } } while (/[)\]}>.,]/.test(char = text.charAt((len = text.length) - 1))) { - if (/[.,]/.test(char)) { + if (/[.,]/.test(char) || (text.match(/[()\[\]{}<>]/)).length % 2) { trim(); continue; } - i = 0; - toggle = false; - while (i < len) { - if (/[()\[\]{}<>]/.test(text[i++])) { - toggle = !toggle; - } - } - if (toggle) { - trim(); - } break; } text = text.contains(':') ? text : (text.contains('@') ? 'mailto:' : 'http://') + text; diff --git a/builds/crx/script.js b/builds/crx/script.js index d31066840..1b4513959 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4531,7 +4531,7 @@ return range; }, makeLink: function(range) { - var a, char, i, len, text, toggle, trim; + var a, char, len, text, trim; text = range.toString(); trim = function() { @@ -4547,20 +4547,10 @@ } } while (/[)\]}>.,]/.test(char = text.charAt((len = text.length) - 1))) { - if (/[.,]/.test(char)) { + if (/[.,]/.test(char) || (text.match(/[()\[\]{}<>]/)).length % 2) { trim(); continue; } - i = 0; - toggle = false; - while (i < len) { - if (/[()\[\]{}<>]/.test(text[i++])) { - toggle = !toggle; - } - } - if (toggle) { - trim(); - } break; } text = text.contains(':') ? text : (text.contains('@') ? 'mailto:' : 'http://') + text; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 0f935cea9..ea7c3c902 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -118,15 +118,9 @@ Linkify = # Clean hanging brackets, commas, periods while /[)\]}>.,]/.test char = text.charAt (len = text.length) - 1 - if /[.,]/.test char + if /[.,]/.test(char) or (text.match /[()\[\]{}<>]/).length % 2 trim() continue - i = 0 - toggle = false - while i < len - if /[()\[\]{}<>]/.test text[i++] then toggle = !toggle - if toggle - trim() break text =