From c0b0e4118788c5bc71720ec64a024014208e00c8 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 31 Oct 2016 00:09:10 -0700 Subject: [PATCH] Tinyboard compatibility in Get.coffee. --- src/General/Get.coffee | 16 +++++++--------- src/classes/Post.coffee | 2 +- src/site/SW.tinyboard.coffee | 8 +++++++- src/site/SW.yotsuba.coffee | 8 +++++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/General/Get.coffee b/src/General/Get.coffee index 240760d1d..777a5b767 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -9,25 +9,23 @@ Get = return "#{excerpt[...70]}..." if excerpt.length > 73 excerpt threadFromRoot: (root) -> - g.threads["#{g.BOARD}.#{root.id[1..]}"] + g.threads["#{g.BOARD}.#{root.id.match(/\d*$/)[0]}"] threadFromNode: (node) -> - Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node + Get.threadFromRoot $.x "ancestor::#{Site.xpath.thread}", node postFromRoot: (root) -> return null unless root? post = g.posts[root.dataset.fullID] index = root.dataset.clone if index then post.clones[index] else post postFromNode: (root) -> - Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', root + Get.postFromRoot $.x "ancestor::#{Site.xpath.postContainer}[1]", root postDataFromLink: (link) -> - if link.hostname is 'boards.4chan.org' - path = link.pathname.split /\/+/ - boardID = path[1] - threadID = path[3] - postID = link.hash[2..] - else # resurrected quote + if link.dataset.postID # resurrected quote {boardID, threadID, postID} = link.dataset threadID or= 0 + else + match = link.href.match Site.regexp.quotelink + [boardID, threadID, postID] = match[1..] return { boardID: boardID threadID: +threadID diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index d9725d699..c0146b9df 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -151,7 +151,7 @@ class Post return if @isClone # ES6 Set when? - fullID = "#{match[1]}.#{match[2]}" + fullID = "#{match[1]}.#{match[3]}" @quotes.push fullID unless fullID in @quotes parseFile: -> diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 5036580bd..ea0f24231 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -29,12 +29,18 @@ SW.tinyboard = spoiler: '.spoiler' quotelink: 'a[onclick^="highlightReply("]' + xpath: + thread: 'div[starts-with(@id,"thread_")]' + postContainer: 'div[starts-with(@id,"reply_") or starts-with(@id,"thread_")]' + regexp: quotelink: /// / ([^/]+) # boardID - /res/\d+\.html# + /res/ + (\d+) # threadID + \.html# (\d+) # postID $ /// diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee index 53ef5216a..c534168d8 100644 --- a/src/site/SW.yotsuba.coffee +++ b/src/site/SW.yotsuba.coffee @@ -34,12 +34,18 @@ SW.yotsuba = spoiler: 's' quotelink: ':not(pre) > .quotelink' # XXX https://github.com/4chan/4chan-JS/issues/77: 4chan currently creates quote links inside [code] tags; ignore them + xpath: + thread: 'div[@class="thread"]' + postContainer: 'div[contains(@class,"postContainer")]' + regexp: quotelink: /// ^https?://boards\.4chan\.org/+ ([^/]+) # boardID - /+thread/+\d+(?:[/?][^#]*)?#p + /+thread/+ + (\d+) # threadID + (?:[/?][^#]*)?#p (\d+) # postID $ ///