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
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

View File

@ -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: ->

View File

@ -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
$
///

View File

@ -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
$
///