From aaeff46c2b0c433566f12e9babbd17e439479463 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 2 Nov 2014 18:15:12 -0800 Subject: [PATCH] Fix ID highlighting. --- src/General/Main.coffee | 1 + src/General/lib/clone.class | 4 ++-- src/Miscellaneous/ExpandThread.coffee | 2 -- src/Miscellaneous/Fourchan.coffee | 27 +++++++++++++++++---------- src/Miscellaneous/IDHighlight.coffee | 23 +++++++++++++++++++++++ src/Monitoring/ThreadUpdater.coffee | 6 ------ 6 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/Miscellaneous/IDHighlight.coffee diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 0c195804e..0ca9fc619 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -282,6 +282,7 @@ Main = ['Announcement Hiding', PSAHiding] ['Fourchan thingies', Fourchan] ['Color User IDs', IDColor] + ['Highlight by User ID', IDHighlight] ['Custom CSS', CustomCSS] ['Linkify', Linkify] ['Reveal Spoilers', RemoveSpoilers] diff --git a/src/General/lib/clone.class b/src/General/lib/clone.class index 762ce5fbe..43ec53bd3 100755 --- a/src/General/lib/clone.class +++ b/src/General/lib/clone.class @@ -40,9 +40,9 @@ class Clone extends Post if nodes.uniqueID @nodes.uniqueID = $ '.posteruid', info if nodes.capcode - @nodes.capcode = $ '.capcode', info + @nodes.capcode = $ '.capcode.hand', info if nodes.flag - @nodes.flag = $ '.countryFlag', info + @nodes.flag = $ '.flag, .countryFlag', info if nodes.date @nodes.date = $ '.dateTime', info diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index 65746e55c..87e219421 100755 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -105,5 +105,3 @@ ExpandThread = postsCount = postsRoot.length a.textContent = ExpandThread.text '-', postsCount, filesCount - - Fourchan.parseThread thread.ID, 1, postsCount diff --git a/src/Miscellaneous/Fourchan.coffee b/src/Miscellaneous/Fourchan.coffee index 1e70fc2ce..f190290f4 100755 --- a/src/Miscellaneous/Fourchan.coffee +++ b/src/Miscellaneous/Fourchan.coffee @@ -2,8 +2,7 @@ Fourchan = init: -> return if g.VIEW is 'catalog' - board = g.BOARD.ID - if board is 'g' + if g.BOARD.ID is 'g' $.globalEval ''' window.addEventListener('prettyprint', function(e) { window.dispatchEvent(new CustomEvent('prettyprint:cb', { @@ -14,7 +13,8 @@ Fourchan = Post.callbacks.push name: 'Parse /g/ code' cb: @code - if board is 'sci' + + if g.BOARD.ID is 'sci' # https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562 $.globalEval ''' window.addEventListener('jsmath', function(e) { @@ -35,6 +35,19 @@ Fourchan = CatalogThread.callbacks.push name: 'Parse /sci/ math' cb: @math + + # Disable 4chan's ID highlighting (replaced by IDHighlight). + $.ready -> + $.globalEval ''' + (function() { + clickable_ids = false; + var nodes = document.querySelectorAll('.posteruid, .capcode'); + for (var i = 0; i < nodes.length; i++) { + nodes[i].removeEventListener("click", idClick, false); + } + })(); + ''' + code: -> return if @isClone apply = (e) -> @@ -45,14 +58,8 @@ Fourchan = $.event 'prettyprint', pre.innerHTML, window $.off window, 'prettyprint:cb', apply return + math: -> return if (@isClone and doc.contains @origin.nodes.root) or !$ '.math', @nodes.comment $.asap (=> doc.contains @nodes.comment), => $.event 'jsmath', null, @nodes.comment - parseThread: (threadID, offset, limit) -> - # Fix /sci/ - # Fix /g/ - $.event '4chanParsingDone', - threadId: threadID - offset: offset - limit: limit diff --git a/src/Miscellaneous/IDHighlight.coffee b/src/Miscellaneous/IDHighlight.coffee new file mode 100644 index 000000000..697692e1d --- /dev/null +++ b/src/Miscellaneous/IDHighlight.coffee @@ -0,0 +1,23 @@ +IDHighlight = + init: -> + return if g.VIEW is 'catalog' + + Post.callbacks.push + name: 'Highlight by User ID' + cb: @node + + uniqueID: null + + node: -> + $.on @nodes.uniqueID, 'click', IDHighlight.click @ if @nodes.uniqueID + $.on @nodes.capcode, 'click', IDHighlight.click @ if @nodes.capcode + IDHighlight.set @ unless @isClone + + set: (post) -> + match = (post.info.uniqueID or post.info.capcode) is IDHighlight.uniqueID + $[if match then 'addClass' else 'rmClass'] post.nodes.post, 'highlight' + + click: (post) -> -> + uniqueID = post.info.uniqueID or post.info.capcode + IDHighlight.uniqueID = if IDHighlight.uniqueID is uniqueID then null else uniqueID + g.posts.forEach IDHighlight.set diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 4853c71fb..b27755ca7 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -333,12 +333,6 @@ ThreadUpdater = else Header.scrollTo root if root - $.queueTask -> - # Enable 4chan features. - threadID = ThreadUpdater.thread.ID - {length} = $$ '.thread > .postContainer', ThreadUpdater.root - Fourchan.parseThread threadID, length - count, length - $.event 'ThreadUpdate', 404: false threadID: ThreadUpdater.thread.fullID