From 202d7617e3e213fdd1510d2c741db42edb9f4555 Mon Sep 17 00:00:00 2001 From: noface Date: Tue, 18 Jun 2013 19:42:42 +0200 Subject: [PATCH 01/13] Add Linkification. --- Gruntfile.coffee | 1 + src/General/Config.coffee | 3 + src/General/Main.coffee | 1 + src/Linkification/Linkify.coffee | 92 ++++++++++++++++++++++++++ src/Miscellaneous/ExpandComment.coffee | 2 + 5 files changed, 99 insertions(+) create mode 100644 src/Linkification/Linkify.coffee diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 2c0ff150b..753ac3df2 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -31,6 +31,7 @@ module.exports = (grunt) -> 'src/Quotelinks/**/*' 'src/Posting/**/*' 'src/Images/**/*' + 'src/Linkification/**/*' 'src/Menu/**/*' 'src/Monitoring/**/*' 'src/Archive/**/*' diff --git a/src/General/Config.coffee b/src/General/Config.coffee index fc174dcfb..b35d0a399 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -27,6 +27,9 @@ Config = 'Image Hover': [false, 'Show a floating expanded image on hover.'] 'Sauce': [true, 'Add sauce links to images.'] 'Reveal Spoilers': [false, 'Reveal spoiler thumbnails.'] + 'Linkification': + 'Linkify': [true, 'Convert text links into hyperlinks.'] + 'Clean Links': [true, 'Remove spoiler texts commonly used to bypass banned links.'] 'Menu': 'Menu': [true, 'Add a drop-down menu to posts.'] 'Report Link': [true, 'Add a report link to the menu.'] diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 4c1be0574..1aeaafa1f 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -128,6 +128,7 @@ Main = initFeature 'Index Navigation', Nav initFeature 'Keybinds', Keybinds initFeature 'Show Dice Roll', Dice + initFeature 'Linkify', Linkify # c.timeEnd 'All initializations' $.on d, 'AddCallback', Main.addCallback diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee new file mode 100644 index 000000000..febbc3e42 --- /dev/null +++ b/src/Linkification/Linkify.coffee @@ -0,0 +1,92 @@ +Linkify = + init: -> + return if g.VIEW is 'catalog' or !Conf['Linkify'] + + @catchAll = /\b(?:([a-z][\w-]+):(?:\/{1,3}|[a-z0-9%]|(\?(?:dn|xl|xt|as|xs|kt|mt|tr)=))|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])/i + + @globalCatchAll = ///#{@catchAll.source}///g + + Post::callbacks.push + name: 'Linkify' + cb: @node + + node: -> + return if @isClone or !links = @info.comment.match Linkify.globalCatchAll + walker = d.createTreeWalker @nodes.comment, 4, null, false + anchor = false + while (node = walker.nextNode())? + {parentNode} = node + if parentNode.nodeName is 'A' + # prettyprint has some issues + if parentNode.textContent is links[0] + delete links[0] + walker.currentNode = parentNode.lastChild + continue + continue unless data = node.data + while !anchor + return unless link = links.shift() + [anchor, link] = Linkify.parseLink link + if data.length >= link.length and (index = data.indexOf link) >= 0 + walker.currentNode = Linkify.sourround anchor, link, index, index + link.length, node + anchor = false + continue + index = found = 0 + nextContent = node.nextSibling?.textContent + while index isnt data.length + start = data[index++..] + startLength = start.length + threshold = startLength is 2 + if threshold and nextContent and link[...startLength + nextContent.length] is start + nextContent + found = true + if threshold or found = link[...startLength] is start + index-- + break + continue unless found + startNode = node + while start.length < link.length + start += data = (node = walker.nextNode())?.data + {parentNode} = node + if parentNode.nodeName is 'S' and Conf['Clean Links'] + $.replace parentNode, node + continue unless start[...link.length] is link + endIndex = link[start.length - data.length...].length + walker.currentNode = Linkify.sourround anchor, link, index, endIndex, startNode, node + anchor = false + return + + parseLink: (link) -> + unless result = link.match @catchAll + return false + [link, protocol, isMagnet] = result + try + decodeURIComponent link + catch + return false + target = if isMagnet or /^(irc|ftps?)$/.test protocol + '_self' + else + '_blank' + href = if protocol + link + else + "http://#{link}" + anchor = $.el 'a', + target: target + href: href + rel: 'noreferrer' + [anchor, link] + + sourround: (anchor, link, startIndex, endIndex, startNode, endNode = startNode) -> + parent = startNode.parentNode + if parent?.nodeName is 'S' and parent.textContent.length < link.length + parentClone = parent.cloneNode true + $.replace parent, startNode + range = d.createRange() + range.setStart startNode, startIndex + range.setEnd endNode, endIndex + try + range.surroundContents anchor + if !Conf['Clean Links'] and parentClone and anchor.firstChild + $.replace anchor.firstChild, parentClone + catch + endNode diff --git a/src/Miscellaneous/ExpandComment.coffee b/src/Miscellaneous/ExpandComment.coffee index 8d87de91e..3567e9f84 100644 --- a/src/Miscellaneous/ExpandComment.coffee +++ b/src/Miscellaneous/ExpandComment.coffee @@ -72,3 +72,5 @@ ExpandComment = Fourchan.code.call post if g.BOARD.ID is 'sci' Fourchan.math.call post + if Conf['Linkify'] + Linkify.node.call post From 7b842c01bea8a418af5ec0c246575a6812186d00 Mon Sep 17 00:00:00 2001 From: noface Date: Sun, 18 Aug 2013 16:56:01 +0200 Subject: [PATCH 02/13] Fix spoiler issue. --- src/Linkification/Linkify.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index febbc3e42..0e3d8602d 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -45,9 +45,10 @@ Linkify = startNode = node while start.length < link.length start += data = (node = walker.nextNode())?.data - {parentNode} = node - if parentNode.nodeName is 'S' and Conf['Clean Links'] - $.replace parentNode, node + if Conf['Clean Links'] + {parentNode} = node + if parentNode.nodeName is 'S' and parentNode.textContent.length < link.length + $.replace parentNode, node continue unless start[...link.length] is link endIndex = link[start.length - data.length...].length walker.currentNode = Linkify.sourround anchor, link, index, endIndex, startNode, node @@ -88,5 +89,4 @@ Linkify = range.surroundContents anchor if !Conf['Clean Links'] and parentClone and anchor.firstChild $.replace anchor.firstChild, parentClone - catch endNode From 58531319ca86d1e55c39b65b41b9f37c3ce5f163 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sun, 18 Aug 2013 20:55:23 +0200 Subject: [PATCH 03/13] sourround -> surround --- src/Linkification/Linkify.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 0e3d8602d..6093e5e26 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -27,7 +27,7 @@ Linkify = return unless link = links.shift() [anchor, link] = Linkify.parseLink link if data.length >= link.length and (index = data.indexOf link) >= 0 - walker.currentNode = Linkify.sourround anchor, link, index, index + link.length, node + walker.currentNode = Linkify.surround anchor, link, index, index + link.length, node anchor = false continue index = found = 0 @@ -51,7 +51,7 @@ Linkify = $.replace parentNode, node continue unless start[...link.length] is link endIndex = link[start.length - data.length...].length - walker.currentNode = Linkify.sourround anchor, link, index, endIndex, startNode, node + walker.currentNode = Linkify.surround anchor, link, index, endIndex, startNode, node anchor = false return @@ -77,7 +77,7 @@ Linkify = rel: 'noreferrer' [anchor, link] - sourround: (anchor, link, startIndex, endIndex, startNode, endNode = startNode) -> + surround: (anchor, link, startIndex, endIndex, startNode, endNode = startNode) -> parent = startNode.parentNode if parent?.nodeName is 'S' and parent.textContent.length < link.length parentClone = parent.cloneNode true From 6d5f422c3f228911ac9438034ce4be26b48adcf5 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 12:21:49 +0200 Subject: [PATCH 04/13] Tweak/rewrite Linkify. --- src/Linkification/Linkify.coffee | 134 +++++++++++++------------------ 1 file changed, 58 insertions(+), 76 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 6093e5e26..a8ad3dc4b 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -2,91 +2,73 @@ Linkify = init: -> return if g.VIEW is 'catalog' or !Conf['Linkify'] - @catchAll = /\b(?:([a-z][\w-]+):(?:\/{1,3}|[a-z0-9%]|(\?(?:dn|xl|xt|as|xs|kt|mt|tr)=))|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])/i - - @globalCatchAll = ///#{@catchAll.source}///g + # gruber revised + magnet support + # http://rodneyrehm.de/t/url-regex.html + @catchAll = /\b([a-z][\w-]+:(\/{1,3}|[a-z0-9%]|\?(dn|x[lts]|as|kt|mt|tr)=)|www\d{0,3}\.|[a-z0-9.\-]+\.[a-z]{2,4}\/)([^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])/g Post::callbacks.push name: 'Linkify' cb: @node node: -> - return if @isClone or !links = @info.comment.match Linkify.globalCatchAll - walker = d.createTreeWalker @nodes.comment, 4, null, false - anchor = false - while (node = walker.nextNode())? - {parentNode} = node - if parentNode.nodeName is 'A' - # prettyprint has some issues - if parentNode.textContent is links[0] - delete links[0] - walker.currentNode = parentNode.lastChild - continue - continue unless data = node.data - while !anchor - return unless link = links.shift() - [anchor, link] = Linkify.parseLink link - if data.length >= link.length and (index = data.indexOf link) >= 0 - walker.currentNode = Linkify.surround anchor, link, index, index + link.length, node - anchor = false - continue - index = found = 0 - nextContent = node.nextSibling?.textContent - while index isnt data.length - start = data[index++..] - startLength = start.length - threshold = startLength is 2 - if threshold and nextContent and link[...startLength + nextContent.length] is start + nextContent - found = true - if threshold or found = link[...startLength] is start - index-- - break - continue unless found - startNode = node - while start.length < link.length - start += data = (node = walker.nextNode())?.data - if Conf['Clean Links'] - {parentNode} = node - if parentNode.nodeName is 'S' and parentNode.textContent.length < link.length - $.replace parentNode, node - continue unless start[...link.length] is link - endIndex = link[start.length - data.length...].length - walker.currentNode = Linkify.surround anchor, link, index, endIndex, startNode, node - anchor = false + return if @isClone or !links = @info.comment.match Linkify.catchAll + walker = d.createTreeWalker @nodes.comment, 4 + for link in links + boundaries = Linkify.find link, walker + # continue unless boundaries + anchor = Linkify.createLink link + if Linkify.surround anchor, link, boundaries + Linkify.cleanLink anchor if Conf['Clean Links'] + walker.currentNode = anchor.lastChild + else + walker.currentNode = boundaries.endNode return - parseLink: (link) -> - unless result = link.match @catchAll - return false - [link, protocol, isMagnet] = result - try - decodeURIComponent link - catch - return false - target = if isMagnet or /^(irc|ftps?)$/.test protocol - '_self' - else - '_blank' - href = if protocol - link - else - "http://#{link}" - anchor = $.el 'a', - target: target - href: href - rel: 'noreferrer' - [anchor, link] + find: (link, walker) -> + # Walk through the nodes until we find the entire link. + text = '' + while node = walker.nextNode() + {data} = node + text += node.data + if text.indexOf(link) > -1 + startNode = endNode = node + break - surround: (anchor, link, startIndex, endIndex, startNode, endNode = startNode) -> - parent = startNode.parentNode - if parent?.nodeName is 'S' and parent.textContent.length < link.length - parentClone = parent.cloneNode true - $.replace parent, startNode + # Walk backwards to find the startNode. + text = data + until (index = text.indexOf link) > -1 + startNode = walker.previousNode() + text = "#{startNode.data}#{text}" + + return { + startNode, endNode + startOffset: index + endOffset: endNode.length - (text.length - index - link.length) + } + + createLink: (link) -> + unless /^[a-z][\w-]+:/.test link + link = "http://#{link}" + a = $.el 'a', + href: link + target: '_blank' + a + + surround: (anchor, link, {startOffset, endOffset, startNode, endNode}) -> + # parent = startNode.parentNode + # if parent?.nodeName is 'S' and parent.textContent.length < link.length + # parentClone = parent.cloneNode true + # $.replace parent, startNode range = d.createRange() - range.setStart startNode, startIndex - range.setEnd endNode, endIndex + range.setStart startNode, startOffset + range.setEnd endNode, endOffset try range.surroundContents anchor - if !Conf['Clean Links'] and parentClone and anchor.firstChild - $.replace anchor.firstChild, parentClone - endNode + # if !Conf['Clean Links'] and parentClone and anchor.firstChild + # $.replace anchor.firstChild, parentClone + true + catch + false + + cleanLink: (anchor) -> + # TODO From a5adff0ab63709f0aa74ddc534833dd8ea39420d Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 12:27:04 +0200 Subject: [PATCH 05/13] Fix parsing of empty text nodes in Post::parseComment(). --- src/General/Post.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/General/Post.coffee b/src/General/Post.coffee index 1b890c2ec..7319235fd 100644 --- a/src/General/Post.coffee +++ b/src/General/Post.coffee @@ -56,6 +56,8 @@ class Post @kill() if that.isArchived parseComment: -> + # Merge text nodes and remove empty ones. + @nodes.comment.normalize() # Get the comment's text. #
-> \n # Remove: From 27c1a77b863e6cbb2ffcf0822bfb55e0c1f65287 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 12:32:15 +0200 Subject: [PATCH 06/13] Create a single range per post, and detach it when we're done. --- src/Linkification/Linkify.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index a8ad3dc4b..fad3c8c41 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -13,16 +13,17 @@ Linkify = node: -> return if @isClone or !links = @info.comment.match Linkify.catchAll walker = d.createTreeWalker @nodes.comment, 4 + range = d.createRange() for link in links boundaries = Linkify.find link, walker # continue unless boundaries anchor = Linkify.createLink link - if Linkify.surround anchor, link, boundaries + if Linkify.surround anchor, link, range, boundaries Linkify.cleanLink anchor if Conf['Clean Links'] walker.currentNode = anchor.lastChild else walker.currentNode = boundaries.endNode - return + range.detach() find: (link, walker) -> # Walk through the nodes until we find the entire link. @@ -54,12 +55,11 @@ Linkify = target: '_blank' a - surround: (anchor, link, {startOffset, endOffset, startNode, endNode}) -> + surround: (anchor, link, range, {startOffset, endOffset, startNode, endNode}) -> # parent = startNode.parentNode # if parent?.nodeName is 'S' and parent.textContent.length < link.length # parentClone = parent.cloneNode true # $.replace parent, startNode - range = d.createRange() range.setStart startNode, startOffset range.setEnd endNode, endOffset try From b378db78f5b0719293ba6d3babb68337228e07ec Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 17:15:57 +0200 Subject: [PATCH 07/13] Linkify: Attempt to handle un-surroundable contents. --- src/Linkification/Linkify.coffee | 49 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index fad3c8c41..1a7f421e7 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -16,9 +16,9 @@ Linkify = range = d.createRange() for link in links boundaries = Linkify.find link, walker - # continue unless boundaries + # break unless boundaries anchor = Linkify.createLink link - if Linkify.surround anchor, link, range, boundaries + if Linkify.surround anchor, range, boundaries Linkify.cleanLink anchor if Conf['Clean Links'] walker.currentNode = anchor.lastChild else @@ -29,14 +29,13 @@ Linkify = # Walk through the nodes until we find the entire link. text = '' while node = walker.nextNode() - {data} = node text += node.data - if text.indexOf(link) > -1 - startNode = endNode = node - break + break if text.indexOf(link) > -1 + # return unless node + startNode = endNode = node # Walk backwards to find the startNode. - text = data + text = node.data until (index = text.indexOf link) > -1 startNode = walker.previousNode() text = "#{startNode.data}#{text}" @@ -55,20 +54,40 @@ Linkify = target: '_blank' a - surround: (anchor, link, range, {startOffset, endOffset, startNode, endNode}) -> - # parent = startNode.parentNode - # if parent?.nodeName is 'S' and parent.textContent.length < link.length - # parentClone = parent.cloneNode true - # $.replace parent, startNode + surround: (anchor, range, boundaries) -> + {startOffset, endOffset, startNode, endNode} = boundaries range.setStart startNode, startOffset range.setEnd endNode, endOffset try range.surroundContents anchor - # if !Conf['Clean Links'] and parentClone and anchor.firstChild - # $.replace anchor.firstChild, parentClone true catch - false + # Attempt to handle cases such as: + # [spoiler]www.[/spoiler]example.com # + # www.example[spoiler].com[/spoiler] # + return false if boundaries.areRelocated + Linkify.relocate boundaries + Linkify.surround anchor, range, boundaries + + relocate: (boundaries) -> + # What do you mean, "silly"? + boundaries.areRelocated = true + + if boundaries.startOffset is 0 + parentNode = boundaries.startNode + until parentNode.previousSibling + {parentNode} = parentNode + parent = parentNode.parentNode + boundaries.startNode = parent + boundaries.startOffset = [parent.childNodes...].indexOf parentNode + + if boundaries.endOffset is boundaries.endNode.length + parentNode = boundaries.endNode + until parentNode.nextSibling + {parentNode} = parentNode + parent = parentNode.parentNode + boundaries.endNode = parent + boundaries.endOffset = [parent.childNodes...].indexOf parentNode cleanLink: (anchor) -> # TODO From 19524d26b64288e4abb131a22db5eaf3698b6ce6 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 17:41:31 +0200 Subject: [PATCH 08/13] Fix endOffset when relocating. --- src/Linkification/Linkify.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 1a7f421e7..61bde6fe8 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -87,7 +87,7 @@ Linkify = {parentNode} = parentNode parent = parentNode.parentNode boundaries.endNode = parent - boundaries.endOffset = [parent.childNodes...].indexOf parentNode + boundaries.endOffset = [parent.childNodes...].indexOf(parentNode) + 1 cleanLink: (anchor) -> # TODO From 7ee6b24606972c39ca9904d4b40728b38b772e4b Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 22:09:52 +0200 Subject: [PATCH 09/13] Handle a Chrome/WebKit/Blink bug. --- src/Linkification/Linkify.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 61bde6fe8..bce234d20 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -62,6 +62,10 @@ Linkify = range.surroundContents anchor true catch + <% if (type === 'crx') { %> + # Chrome bug: crbug.com/275848 + return true if anchor.parentNode + <% } %> # Attempt to handle cases such as: # [spoiler]www.[/spoiler]example.com # # www.example[spoiler].com[/spoiler] # From fc745767c4d9ab689ad99b8bd0f3d3531bceaf69 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 19 Aug 2013 23:15:54 +0200 Subject: [PATCH 10/13] Replace already-linkified links. --- src/Linkification/Linkify.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index bce234d20..1665e276a 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -19,6 +19,10 @@ Linkify = # break unless boundaries anchor = Linkify.createLink link if Linkify.surround anchor, range, boundaries + if (parent = anchor.parentNode).href is anchor.href + # Replace already-linkified links, + # f.e.: https://boards.4chan.org/b/% + $.replace parent, anchor Linkify.cleanLink anchor if Conf['Clean Links'] walker.currentNode = anchor.lastChild else From abfbd734aa7c2cf78a1875d4d1f85177656769ab Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 20 Aug 2013 00:05:41 +0200 Subject: [PATCH 11/13] Add a 'linkified' class. --- src/Linkification/Linkify.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 1665e276a..ba9125f5a 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -53,10 +53,10 @@ Linkify = createLink: (link) -> unless /^[a-z][\w-]+:/.test link link = "http://#{link}" - a = $.el 'a', + $.el 'a', href: link + className: 'linkified' target: '_blank' - a surround: (anchor, range, boundaries) -> {startOffset, endOffset, startNode, endNode} = boundaries From 4196ce2600d986ad68bf27b83a40ab3c5da9301e Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 20 Aug 2013 00:33:56 +0200 Subject: [PATCH 12/13] Clean links from spoiler and code tags. --- src/General/Config.coffee | 2 +- src/Linkification/Linkify.coffee | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index b35d0a399..24fa40faf 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -29,7 +29,7 @@ Config = 'Reveal Spoilers': [false, 'Reveal spoiler thumbnails.'] 'Linkification': 'Linkify': [true, 'Convert text links into hyperlinks.'] - 'Clean Links': [true, 'Remove spoiler texts commonly used to bypass banned links.'] + 'Clean Links': [true, 'Remove spoiler and code tags commonly used to bypass blocked links.'] 'Menu': 'Menu': [true, 'Add a drop-down menu to posts.'] 'Report Link': [true, 'Add a report link to the menu.'] diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index ba9125f5a..99f667fbe 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -23,7 +23,7 @@ Linkify = # Replace already-linkified links, # f.e.: https://boards.4chan.org/b/% $.replace parent, anchor - Linkify.cleanLink anchor if Conf['Clean Links'] + Linkify.cleanLink anchor, link if Conf['Clean Links'] walker.currentNode = anchor.lastChild else walker.currentNode = boundaries.endNode @@ -97,5 +97,8 @@ Linkify = boundaries.endNode = parent boundaries.endOffset = [parent.childNodes...].indexOf(parentNode) + 1 - cleanLink: (anchor) -> - # TODO + cleanLink: (anchor, link) -> + {length} = link + for node in $$ 's, .prettyprint', anchor + $.replace node, [node.childNodes...] if length > node.textContent.length + return From 8b6647b3448881e67d32c9cecb867ed0a31cdc0b Mon Sep 17 00:00:00 2001 From: Mayhem Date: Tue, 20 Aug 2013 00:45:14 +0200 Subject: [PATCH 13/13] Changelog. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bbdbb486..7a9b09c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +- **New feature**: `Linkify` and `Clean Links`, enabled by default + - Linkify will turn text URLs into working links. + - Clean Links will get rid of spoiler and code tags in linkified URLs used to bypass spam blocks. + ## 3.9.0 - *2013-08-18* - **New feature**: `Desktop Notifications`