Tinyboard compatibility in Get.coffee.

This commit is contained in:
ccd0 2016-10-31 00:09:10 -07:00
parent 5a57879e01
commit c0b0e41187
4 changed files with 22 additions and 12 deletions

View File

@ -9,25 +9,23 @@ Get =
return "#{excerpt[...70]}..." if excerpt.length > 73 return "#{excerpt[...70]}..." if excerpt.length > 73
excerpt excerpt
threadFromRoot: (root) -> threadFromRoot: (root) ->
g.threads["#{g.BOARD}.#{root.id[1..]}"] g.threads["#{g.BOARD}.#{root.id.match(/\d*$/)[0]}"]
threadFromNode: (node) -> threadFromNode: (node) ->
Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node Get.threadFromRoot $.x "ancestor::#{Site.xpath.thread}", node
postFromRoot: (root) -> postFromRoot: (root) ->
return null unless root? return null unless root?
post = g.posts[root.dataset.fullID] post = g.posts[root.dataset.fullID]
index = root.dataset.clone index = root.dataset.clone
if index then post.clones[index] else post if index then post.clones[index] else post
postFromNode: (root) -> postFromNode: (root) ->
Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', root Get.postFromRoot $.x "ancestor::#{Site.xpath.postContainer}[1]", root
postDataFromLink: (link) -> postDataFromLink: (link) ->
if link.hostname is 'boards.4chan.org' if link.dataset.postID # resurrected quote
path = link.pathname.split /\/+/
boardID = path[1]
threadID = path[3]
postID = link.hash[2..]
else # resurrected quote
{boardID, threadID, postID} = link.dataset {boardID, threadID, postID} = link.dataset
threadID or= 0 threadID or= 0
else
match = link.href.match Site.regexp.quotelink
[boardID, threadID, postID] = match[1..]
return { return {
boardID: boardID boardID: boardID
threadID: +threadID threadID: +threadID

View File

@ -151,7 +151,7 @@ class Post
return if @isClone return if @isClone
# ES6 Set when? # ES6 Set when?
fullID = "#{match[1]}.#{match[2]}" fullID = "#{match[1]}.#{match[3]}"
@quotes.push fullID unless fullID in @quotes @quotes.push fullID unless fullID in @quotes
parseFile: -> parseFile: ->

View File

@ -29,12 +29,18 @@ SW.tinyboard =
spoiler: '.spoiler' spoiler: '.spoiler'
quotelink: 'a[onclick^="highlightReply("]' quotelink: 'a[onclick^="highlightReply("]'
xpath:
thread: 'div[starts-with(@id,"thread_")]'
postContainer: 'div[starts-with(@id,"reply_") or starts-with(@id,"thread_")]'
regexp: regexp:
quotelink: quotelink:
/// ///
/ /
([^/]+) # boardID ([^/]+) # boardID
/res/\d+\.html# /res/
(\d+) # threadID
\.html#
(\d+) # postID (\d+) # postID
$ $
/// ///

View File

@ -34,12 +34,18 @@ SW.yotsuba =
spoiler: 's' 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 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: regexp:
quotelink: quotelink:
/// ///
^https?://boards\.4chan\.org/+ ^https?://boards\.4chan\.org/+
([^/]+) # boardID ([^/]+) # boardID
/+thread/+\d+(?:[/?][^#]*)?#p /+thread/+
(\d+) # threadID
(?:[/?][^#]*)?#p
(\d+) # postID (\d+) # postID
$ $
/// ///