From 7a2f43100873e64f4f0b60c13d40b89d518e8e0e Mon Sep 17 00:00:00 2001 From: ebinBuddha <30810167+ebinBuddha@users.noreply.github.com> Date: Tue, 16 Apr 2019 07:28:28 +0200 Subject: [PATCH] Bulk of changes after code review - comment on css and single class for postJumper - single Conf setting - post number sorting - renamed maps - removed selectors from SW.yotsuba.coffee - used the g object and other smarter ways to get the needed stuff --- src/Miscellaneous/PostJumper.coffee | 44 ++++++++++++++++++----------- src/config/Config.coffee | 8 ++---- src/css/style.css | 8 +++--- src/site/SW.yotsuba.coffee | 6 ---- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/Miscellaneous/PostJumper.coffee b/src/Miscellaneous/PostJumper.coffee index 3dd8a6310..52a298653 100644 --- a/src/Miscellaneous/PostJumper.coffee +++ b/src/Miscellaneous/PostJumper.coffee @@ -1,7 +1,7 @@ PostJumper = init: -> - @capcodeMap = new Map() - @uniqueIDMap = new Map() + @capcode = new Map() + @uniqueID = new Map() return unless g.VIEW in ['index', 'thread'] Callbacks.Post.push @@ -9,10 +9,12 @@ PostJumper = cb: @node node: -> - if @nodes.uniqueIDRoot and Conf['Unique ID Navigation'] and not @nodes.uniqueIDJumperRoot + return unless Conf['Unique ID and capcode Navigation'] + + if @nodes.uniqueIDRoot and not @isClone PostJumper.addButtons @,'uniqueID' - if @nodes.capcode and Conf['Capcode Navigation'] and not @nodes.capcodeJumperRoot + if @nodes.capcode and not @isClone PostJumper.addButtons @,'capcode' addButtons: (post,type) -> @@ -21,32 +23,42 @@ PostJumper = $.after post.nodes[type+(if type is 'capcode' then '' else 'Root')], buttons $.on buttons.firstChild, 'click', PostJumper.buttonClick post,type,-1 $.on buttons.lastChild, 'click', PostJumper.buttonClick post,type,1 - if not PostJumper[type+'Map'].has value - PostJumper[type+'Map'].set value, [] - PostJumper[type+'Map'].get(value).push post.nodes.quote.innerText + if not PostJumper[type].has value + PostJumper[type].set value, [] + PostJumper[type].get(value).push {key: post.ID, val: post.fullID} + PostJumper[type].get(value).sort (first,second) -> first.key-second.key buttonClick: (post,type,dir) -> -> - return if PostJumper[type+'Map'].size is 0 + return if PostJumper[type].size is 0 value = (if type is 'capcode' then '## ' else '') + post.info[type] - fromID = post.ID.toString() - idx = PostJumper[type+'Map'].get(value).indexOf(fromID); + fromID = post.ID + idx = PostJumper.indexOfPair PostJumper[type].get(value),fromID + fromID = PostJumper[type].get(value)[idx].val return if idx is -1 - idx = (idx + dir) %% PostJumper[type+'Map'].get(value).length - toID= PostJumper[type+'Map'].get(value)[idx] + idx = (idx + dir) %% PostJumper[type].get(value).length + toID= PostJumper[type].get(value)[idx].val PostJumper.scroll fromID,toID - makeButtons: (cl) -> + makeButtons: -> charPrev = '\u{23EB}' charNext = '\u{23EC}' classPrev = 'prev' classNext = 'next' span = $.el 'span', - className: cl + className: 'postJumper' $.extend span, <%= html('${charPrev}${charNext}') %> span scroll: (fromID,toID) -> - prevPos = $.id("pc"+fromID).getBoundingClientRect().top - destPos = $.id("pc"+toID).getBoundingClientRect().top + prevPos = g.posts[fromID].nodes.root.getBoundingClientRect().top + destPos = g.posts[toID].nodes.root.getBoundingClientRect().top window.scrollBy 0, destPos-prevPos + + indexOfPair: (array,key) -> + result = -1; + for i in [0..array.length-1] by 1 + if array[i].key is key + result = i + break + result \ No newline at end of file diff --git a/src/config/Config.coffee b/src/config/Config.coffee index fec89d1ac..0fd8fba0b 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -92,13 +92,9 @@ Config = false 'Add buttons to navigate to top / bottom of thread.' ] - 'Unique ID Navigation': [ + 'Unique ID and capcode Navigation': [ false - 'Add buttons to navigate to posts having the same unique ID.' - ] - 'Capcode Navigation': [ - false - 'Add buttons to navigate to posts having the same capcode.' + 'Add buttons to navigate to posts having the same unique ID or capcode.' ] 'Custom Board Titles': [ true diff --git a/src/css/style.css b/src/css/style.css index b8245b6e5..9fc9841fa 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -2405,9 +2405,9 @@ a:only-of-type > .remove { :root.gallery-open.fixed #header-bar:not(.autohide) #shortcuts .fa::before { visibility: hidden; } -.capcodeJumper > .prev, -.capcodeJumper > .next, -.uniqueIDJumper > .prev, -.uniqueIDJumper > .next { + +/* PostJumper */ +.postJumper > .prev, +.postJumper > .next { font-size: 120%; } diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee index df0dd4894..cb25f01c9 100644 --- a/src/site/SW.yotsuba.coffee +++ b/src/site/SW.yotsuba.coffee @@ -27,12 +27,6 @@ SW.yotsuba = uniqueIDRoot: '.posteruid' uniqueID: '.posteruid > .hand' capcode: '.capcode.hand' - capcodeJumperRoot: '.capcodeJumper' - capcodeJumperPrev: '.capcodeJumper > .prev' - capcodeJumperNext: '.capcodeJumper > .next' - uniqueIDJumperRoot: '.uniqueIDJumper' - uniqueIDJumperPrev: '.uniqueIDJumper > .prev' - uniqueIDJumperNext: '.uniqueIDJumper > .next' pass: '.n-pu' flag: '.flag, .countryFlag' date: '.dateTime'