From d0b492760c1fe8ec57cfa74a7f5729b69e8b6740 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 1 Apr 2020 02:52:24 -0700 Subject: [PATCH] Preliminary support for new Kissu UI. --- src/main/Main.coffee | 26 +++++++++++++++++++++++--- src/site/SW.tinyboard.coffee | 12 +++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/Main.coffee b/src/main/Main.coffee index cab6eea76..0e79a5d73 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -30,6 +30,15 @@ Main = new Notice 'error', 'Error: Multiple copies of 4chan X are enabled.' $.addClass doc, 'tainted' + # Detect "mounted" event from Kissu + mountedCB = -> + d.removeEventListener 'mounted', mountedCB, true + Main.isMounted = true + for cb in Main.mountedCBs + try + cb() + d.addEventListener 'mounted', mountedCB, true + # Flatten default values from Config into Conf flatten = (parent, obj) -> if obj instanceof Array @@ -332,14 +341,17 @@ Main = if g.VIEW is 'catalog' Main.initCatalog() else if !Index.enabled - Main.initThread() + if g.SITE.awaitBoard + g.SITE.awaitBoard Main.initThread + else + Main.initThread() else Main.expectInitFinished = true $.event '4chanXInitFinished' initThread: -> s = g.SITE.selectors - if (board = $ s.board) + if (board = $ (s.boardFor?[g.VIEW] or s.board)) threads = [] posts = [] errors = [] @@ -388,7 +400,7 @@ Main = Main.addPostsObserver.observe threadRoot, {childList: true} parsePosts: (postRoots, thread, posts, errors) -> - for postRoot in postRoots when !postRoot.dataset.fullID and $(g.SITE.selectors.comment, postRoot) + for postRoot in postRoots when !(postRoot.dataset.fullID and g.posts.get(postRoot.dataset.fullID)) and $(g.SITE.selectors.comment, postRoot) try posts.push new Post postRoot, thread, thread.board catch err @@ -601,6 +613,14 @@ Main = $.ready -> (cb() if Main.isThisPageLegit()) + mounted: (cb) -> + if Main.isMounted + cb() + else + Main.mountedCBs.push cb + + mountedCBs: [] + features: [ ['Polyfill', Polyfill] ['Board Configuration', BoardConfig] diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 8d809ff54..de0b5c9bd 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -40,6 +40,16 @@ SW.tinyboard = return properties false + awaitBoard: (cb) -> + if (reactUI = $.id('react-ui')) + s = @selectors = Object.create @selectors + s.boardFor = {index: '.page-container'} + s.thread = 'div[id^="thread_"]' + s.threadDivider = 'page-container > hr' + Main.mounted cb + else + cb() + urls: thread: ({siteID, boardID, threadID}, isArchived) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/#{if isArchived then 'archive/' else ''}res/#{threadID}.html" @@ -196,7 +206,7 @@ SW.tinyboard = {text, link, thumb} = file return false if $.x("ancestor::#{@xpath.postContainer}[1]", text) isnt post.nodes.root # file belongs to a reply return false if not (infoNode = if '(' in link.nextSibling?.textContent then link.nextSibling else link.nextElementSibling) - return false if not (info = infoNode.textContent.match /\((.*,\s*)?([\d.]+ [KMG]?B).*\)/) + return false if not (info = infoNode.textContent.match /\((.*,\s*)?([\d.]+ ?[KMG]?B).*\)/) nameNode = $ '.postfilename', text $.extend file, name: if nameNode then (nameNode.title or nameNode.textContent) else link.pathname.match(/[^/]*$/)[0]