Make 4chan X tolerant of redundant slashes in 4chan URLs, part 2. #499

Stuff I missed in 2379b0f31da60a03f0dd9e0350b8dde3d3fe64e8.
This commit is contained in:
ccd0 2015-10-04 13:12:14 -07:00
parent 6a24c53ce0
commit 972a40b572
4 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@ Get =
Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node
postFromRoot: (root) -> postFromRoot: (root) ->
link = $ '.postNum > a[href*="#"]', root link = $ '.postNum > a[href*="#"]', root
boardID = link.pathname.split('/')[1] boardID = link.pathname.split(/\/+/)[1]
postID = link.hash[2..] postID = link.hash[2..]
index = root.dataset.clone index = root.dataset.clone
post = g.posts["#{boardID}.#{postID}"] post = g.posts["#{boardID}.#{postID}"]
@ -24,7 +24,7 @@ Get =
Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', node Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', node
postDataFromLink: (link) -> postDataFromLink: (link) ->
if link.hostname is 'boards.4chan.org' if link.hostname is 'boards.4chan.org'
path = link.pathname.split '/' path = link.pathname.split /\/+/
boardID = path[1] boardID = path[1]
threadID = path[3] threadID = path[3]
postID = link.hash[2..] postID = link.hash[2..]

View File

@ -162,9 +162,9 @@ class Post
# - rules links. (>>>/a/rules) # - rules links. (>>>/a/rules)
# - text-board quotelinks. (>>>/img/1234) # - text-board quotelinks. (>>>/img/1234)
return unless match = quotelink.href.match /// return unless match = quotelink.href.match ///
boards\.4chan\.org/ ^https?://boards\.4chan\.org/+
([^/]+) # boardID ([^/]+) # boardID
/(?:res|thread)/\d+(?:\/[^#]*)?#p /+(?:res|thread)/+\d+(?:/[^#]*)?#p
(\d+) # postID (\d+) # postID
$ $
/// ///

View File

@ -7,7 +7,7 @@ CatalogLinks =
when 'index' then '#ctrl-top > a, .cataloglink > a' when 'index' then '#ctrl-top > a, .cataloglink > a'
$.ready -> $.ready ->
for link in $$ selector for link in $$ selector
switch link.pathname switch link.pathname.replace /\/+/g, '/'
when "/#{g.BOARD}/" when "/#{g.BOARD}/"
link.textContent = 'Index' if Conf['JSON Navigation'] link.textContent = 'Index' if Conf['JSON Navigation']
link.href = CatalogLinks.index() link.href = CatalogLinks.index()

View File

@ -26,7 +26,7 @@ ExpandComment =
return return
return unless a = $ '.abbr > a', post.nodes.comment return unless a = $ '.abbr > a', post.nodes.comment
a.textContent = "Post No.#{post} Loading..." a.textContent = "Post No.#{post} Loading..."
$.cache "//a.4cdn.org#{a.pathname.split('/').splice(0,4).join('/')}.json", -> ExpandComment.parse @, a, post $.cache "//a.4cdn.org#{a.pathname.split(/\/+/).splice(0,4).join('/')}.json", -> ExpandComment.parse @, a, post
contract: (post) -> contract: (post) ->
return unless post.nodes.shortComment return unless post.nodes.shortComment
@ -59,9 +59,9 @@ ExpandComment =
href = quote.getAttribute 'href' href = quote.getAttribute 'href'
continue if href[0] is '/' # Cross-board quote, or board link continue if href[0] is '/' # Cross-board quote, or board link
if href[0] is '#' if href[0] is '#'
quote.href = "#{a.pathname.split('/').splice(0,4).join('/')}#{href}" quote.href = "#{a.pathname.split(/\/+/).splice(0,4).join('/')}#{href}"
else else
quote.href = "#{a.pathname.split('/').splice(0,3).join('/')}/#{href}" quote.href = "#{a.pathname.split(/\/+/).splice(0,3).join('/')}/#{href}"
post.nodes.shortComment = comment post.nodes.shortComment = comment
$.replace comment, clone $.replace comment, clone
post.nodes.comment = post.nodes.longComment = clone post.nodes.comment = post.nodes.longComment = clone