diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 5ec262c5c..613512b68 100755 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4525,7 +4525,7 @@ return range; }, makeLink: function(range) { - var a, char, len, text, toggle, trim; + var a, char, text, trim; text = range.toString(); trim = function() { @@ -4535,35 +4535,13 @@ return text = text.slice(0, -1); }; if (/[(\[{<]/.test(text.charAt(0))) { - if (/[\)\]}>]/.test(text.charAt(text.length - 1))) { - trim(); - } - text.slice(1); + text = text.slice(1); if (range.startOffset !== range.startContainer.data.length) { range.setStart(range.startContainer, range.startOffset + 1); } } - while (/[\)\]}>,]/.exec(char = text.charAt(text.length - 1))) { - if (char === ',') { - trim(); - continue; - } - len = text.length; - while (i < len) { - toggle = false; - switch (text[i++]) { - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - toggle = !toggle; - } - } - if (toggle) { + while (/[)\]}>.,]/.test(char = text.charAt(text.length - 1))) { + if (/[.,]/.test(char) || (text.match(/[()\[\]{}<>]/g)).length % 2) { trim(); continue; } diff --git a/builds/crx/script.js b/builds/crx/script.js index f808b5d67..565ea23ee 100755 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4531,7 +4531,7 @@ return range; }, makeLink: function(range) { - var a, char, len, text, toggle, trim; + var a, char, text, trim; text = range.toString(); trim = function() { @@ -4541,35 +4541,13 @@ return text = text.slice(0, -1); }; if (/[(\[{<]/.test(text.charAt(0))) { - if (/[\)\]}>]/.test(text.charAt(text.length - 1))) { - trim(); - } - text.slice(1); + text = text.slice(1); if (range.startOffset !== range.startContainer.data.length) { range.setStart(range.startContainer, range.startOffset + 1); } } - while (/[\)\]}>,]/.exec(char = text.charAt(text.length - 1))) { - if (char === ',') { - trim(); - continue; - } - len = text.length; - while (i < len) { - toggle = false; - switch (text[i++]) { - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - toggle = !toggle; - } - } - if (toggle) { + while (/[)\]}>.,]/.test(char = text.charAt(text.length - 1))) { + if (/[.,]/.test(char) || (text.match(/[()\[\]{}<>]/g)).length % 2) { trim(); continue; } diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 6be4c648b..5593e6bb5 100755 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -110,27 +110,20 @@ Linkify = range.setEnd range.endContainer, range.endOffset - 1 unless range.endOffset < 1 text = text.slice 0, -1 - # Clean brackets, hanging commas + # Clean leading brackets if /[(\[{<]/.test text.charAt 0 - trim() if /[\)\]}>]/.test text.charAt text.length - 1 - text.slice 1 + text = text.slice 1 unless range.startOffset is range.startContainer.data.length range.setStart range.startContainer, range.startOffset + 1 - while /[\)\]}>,]/.exec char = text.charAt text.length - 1 - if char is ',' - trim() - continue - len = text.length - while i < len - toggle = false - switch text[i++] - when '(', ')', '[', ']', '{', '}', '<', '>' then toggle = !toggle - if toggle + # Clean hanging brackets, commas, periods + while /[)\]}>.,]/.test char = text.charAt text.length - 1 + if /[.,]/.test(char) or (text.match /[()\[\]{}<>]/g).length % 2 trim() continue break + # This is the only piece of code left based on Anthony Lieuallen's Linkify text = if text.contains ':' text