Better consistency with board and boardID.

This commit is contained in:
Nicolas Stepien 2013-04-02 11:04:18 +02:00
parent c15c7230db
commit a961c993a2
2 changed files with 87 additions and 87 deletions

View File

@ -1642,8 +1642,8 @@ ArchiveLink =
type: 'post' type: 'post'
el: div el: div
order: 90 order: 90
open: ({ID: postID, thread: threadID, board}) -> open: ({ID, thread, board}) ->
redirect = Redirect.to {postID, threadID, board} redirect = Redirect.to {ID, threadID: thread.ID, boardID: board.ID}
redirect isnt "//boards.4chan.org/#{board}/" redirect isnt "//boards.4chan.org/#{board}/"
subEntries: [] subEntries: []
@ -1667,8 +1667,8 @@ ArchiveLink =
target: '_blank' target: '_blank'
if type is 'post' if type is 'post'
open = ({ID: postID, thread: threadID, board}) -> open: ({ID, thread, board}) ->
el.href = Redirect.to {postID, threadID, board} el.href = Redirect.to {ID, threadID: thread.ID, boardID: board.ID}
true true
else else
open = (post) -> open = (post) ->
@ -1676,7 +1676,7 @@ ArchiveLink =
# We want to parse the exact same stuff as the filter does already. # We want to parse the exact same stuff as the filter does already.
return false unless value return false unless value
el.href = Redirect.to el.href = Redirect.to
board: post.board boardID: post.board.ID
type: type type: type
value: value value: value
isSearch: true isSearch: true
@ -1934,36 +1934,36 @@ Nav =
window.scrollBy 0, top window.scrollBy 0, top
Redirect = Redirect =
image: (board, filename) -> image: (boardID, filename) ->
# Do not use g.BOARD, the image url can originate from a cross-quote. # Do not use g.BOARD, the image url can originate from a cross-quote.
switch "#{board}" switch boardID
when 'a', 'gd', 'jp', 'm', 'q', 'tg', 'vg', 'vp', 'vr', 'wsg' when 'a', 'gd', 'jp', 'm', 'q', 'tg', 'vg', 'vp', 'vr', 'wsg'
"//archive.foolz.us/#{board}/full_image/#{filename}" "//archive.foolz.us/#{boardID}/full_image/#{filename}"
when 'u' when 'u'
"//nsfw.foolz.us/#{board}/full_image/#{filename}" "//nsfw.foolz.us/#{boardID}/full_image/#{filename}"
when 'po' when 'po'
"//archive.thedarkcave.org/#{board}/full_image/#{filename}" "//archive.thedarkcave.org/#{boardID}/full_image/#{filename}"
when 'ck', 'lit' when 'ck', 'lit'
"//fuuka.warosu.org/#{board}/full_image/#{filename}" "//fuuka.warosu.org/#{boardID}/full_image/#{filename}"
when 'cgl', 'g', 'mu', 'w' when 'cgl', 'g', 'mu', 'w'
"//rbt.asia/#{board}/full_image/#{filename}" "//rbt.asia/#{boardID}/full_image/#{filename}"
when 'an', 'k', 'toy', 'x' when 'an', 'k', 'toy', 'x'
"http://archive.heinessen.com/#{board}/full_image/#{filename}" "http://archive.heinessen.com/#{boardID}/full_image/#{filename}"
when 'c' when 'c'
"//archive.nyafuu.org/#{board}/full_image/#{filename}" "//archive.nyafuu.org/#{boardID}/full_image/#{filename}"
post: (board, postID) -> post: (boardID, postID) ->
switch "#{board}" switch boardID
when 'a', 'co', 'gd', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'vp', 'vr', 'wsg' when 'a', 'co', 'gd', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'vp', 'vr', 'wsg'
"//archive.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" "//archive.foolz.us/_/api/chan/post/?board=#{boardID}&num=#{postID}"
when 'u' when 'u'
"//nsfw.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" "//nsfw.foolz.us/_/api/chan/post/?board=#{boardID}&num=#{postID}"
when 'c', 'int', 'out', 'po' when 'c', 'int', 'out', 'po'
"//archive.thedarkcave.org/_/api/chan/post/?board=#{board}&num=#{postID}" "//archive.thedarkcave.org/_/api/chan/post/?board=#{boardID}&num=#{postID}"
# for fuuka-based archives: # for fuuka-based archives:
# https://github.com/eksopl/fuuka/issues/27 # https://github.com/eksopl/fuuka/issues/27
to: (data) -> to: (data) ->
{board} = data {boardID} = data
switch "#{board}" switch boardID
when 'a', 'co', 'gd', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'vp', 'vr', 'wsg' when 'a', 'co', 'gd', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'vp', 'vr', 'wsg'
url = Redirect.path '//archive.foolz.us', 'foolfuuka', data url = Redirect.path '//archive.foolz.us', 'foolfuuka', data
when 'u' when 'u'
@ -1982,11 +1982,11 @@ Redirect =
url = Redirect.path '//archive.nyafuu.org', 'fuuka', data url = Redirect.path '//archive.nyafuu.org', 'fuuka', data
else else
if data.threadID if data.threadID
url = "//boards.4chan.org/#{board}/" url = "//boards.4chan.org/#{boardID}/"
url or '' url or ''
path: (base, archiver, data) -> path: (base, archiver, data) ->
if data.isSearch if data.isSearch
{board, type, value} = data {boardID, type, value} = data
type = type =
if type is 'name' if type is 'name'
'username' 'username'
@ -1996,20 +1996,20 @@ Redirect =
type type
value = encodeURIComponent value value = encodeURIComponent value
return if archiver is 'foolfuuka' return if archiver is 'foolfuuka'
"#{base}/#{board}/search/#{type}/#{value}" "#{base}/#{boardID}/search/#{type}/#{value}"
else if type is 'image' else if type is 'image'
"#{base}/#{board}/?task=search2&search_media_hash=#{value}" "#{base}/#{boardID}/?task=search2&search_media_hash=#{value}"
else else
"#{base}/#{board}/?task=search2&search_#{type}=#{value}" "#{base}/#{boardID}/?task=search2&search_#{type}=#{value}"
{board, threadID, postID} = data {boardID, threadID, postID} = data
# keep the number only if the location.hash was sent f.e. # keep the number only if the location.hash was sent f.e.
postID = postID.match(/\d+/)[0] if postID and typeof postID is 'string' postID = postID.match(/\d+/)[0] if postID and typeof postID is 'string'
path = path =
if threadID if threadID
"#{board}/thread/#{threadID}" "#{boardID}/thread/#{threadID}"
else else
"#{board}/post/#{postID}" "#{boardID}/post/#{postID}"
if archiver is 'foolfuuka' if archiver is 'foolfuuka'
path += '/' path += '/'
if threadID and postID if threadID and postID
@ -2031,12 +2031,12 @@ Build =
"#{filename[...threshold - 5]}(...).#{filename[-3..]}" "#{filename[...threshold - 5]}(...).#{filename[-3..]}"
else else
filename filename
postFromObject: (data, board) -> postFromObject: (data, boardID) ->
o = o =
# id # id
postID: data.no postID: data.no
threadID: data.resto or data.no threadID: data.resto or data.no
board: board boardID: boardID
# info # info
name: data.name name: data.name
capcode: data.capcode capcode: data.capcode
@ -2057,12 +2057,12 @@ Build =
o.file = o.file =
name: data.filename + data.ext name: data.filename + data.ext
timestamp: "#{data.tim}#{data.ext}" timestamp: "#{data.tim}#{data.ext}"
url: "//images.4chan.org/#{board}/src/#{data.tim}#{data.ext}" url: "//images.4chan.org/#{boardID}/src/#{data.tim}#{data.ext}"
height: data.h height: data.h
width: data.w width: data.w
MD5: data.md5 MD5: data.md5
size: data.fsize size: data.fsize
turl: "//thumbs.4chan.org/#{board}/thumb/#{data.tim}s.jpg" turl: "//thumbs.4chan.org/#{boardID}/thumb/#{data.tim}s.jpg"
theight: data.tn_h theight: data.tn_h
twidth: data.tn_w twidth: data.tn_w
isSpoiler: !!data.spoiler isSpoiler: !!data.spoiler
@ -2074,7 +2074,7 @@ Build =
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
### ###
{ {
postID, threadID, board postID, threadID, boardID
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC
isSticky, isClosed isSticky, isClosed
comment comment
@ -2129,7 +2129,7 @@ Build =
flag = flag =
if flagCode if flagCode
" <img src='#{staticPath}/image/country/#{if board.ID is 'pol' then 'troll/' else ''}" + " <img src='#{staticPath}/image/country/#{if boardID is 'pol' then 'troll/' else ''}" +
flagCode.toLowerCase() + ".gif' alt=#{flagCode} title='#{flagName}' class=countryFlag>" flagCode.toLowerCase() + ".gif' alt=#{flagCode} title='#{flagName}' class=countryFlag>"
else else
'' ''
@ -2157,13 +2157,13 @@ Build =
fileSize = "Spoiler Image, #{fileSize}" fileSize = "Spoiler Image, #{fileSize}"
unless isArchived unless isArchived
fileThumb = '//static.4chan.org/image/spoiler' fileThumb = '//static.4chan.org/image/spoiler'
if spoilerRange = Build.spoilerRange[board] if spoilerRange = Build.spoilerRange[boardID]
# Randomize the spoiler image. # Randomize the spoiler image.
fileThumb += "-#{board}" + Math.floor 1 + spoilerRange * Math.random() fileThumb += "-#{boardID}" + Math.floor 1 + spoilerRange * Math.random()
fileThumb += '.png' fileThumb += '.png'
file.twidth = file.theight = 100 file.twidth = file.theight = 100
if board.ID isnt 'f' if boardID.ID isnt 'f'
imgSrc = "<a class='fileThumb#{if file.isSpoiler then ' imgspoiler' else ''}' href='#{file.url}' target=_blank>" + imgSrc = "<a class='fileThumb#{if file.isSpoiler then ' imgspoiler' else ''}' href='#{file.url}' target=_blank>" +
"<img src='#{fileThumb}' alt='#{fileSize}' data-md5=#{file.MD5} style='height: #{file.theight}px; width: #{file.twidth}px;'></a>" "<img src='#{fileThumb}' alt='#{fileSize}' data-md5=#{file.MD5} style='height: #{file.theight}px; width: #{file.twidth}px;'></a>"
@ -2228,12 +2228,12 @@ Build =
capcodeStart + capcode + userID + flag + sticky + closed + capcodeStart + capcode + userID + flag + sticky + closed +
"<br>#{subject}" + "<br>#{subject}" +
"</span><span class='dateTime postNum' data-utc=#{dateUTC}>#{date}" + "</span><span class='dateTime postNum' data-utc=#{dateUTC}>#{date}" +
"<a href=#{"/#{board}/res/#{threadID}#p#{postID}"}>No.</a>" + "<a href=#{"/#{boardID}/res/#{threadID}#p#{postID}"}>No.</a>" +
"<a href='#{ "<a href='#{
if g.VIEW is 'thread' and g.THREAD is +threadID if g.VIEW is 'thread' and g.THREAD is +threadID
"javascript:quote(#{postID})" "javascript:quote(#{postID})"
else else
"/#{board}/res/#{threadID}#q#{postID}" "/#{boardID}/res/#{threadID}#q#{postID}"
}'>#{postID}</a>" + }'>#{postID}</a>" +
'</span>' + '</span>' +
'</div>' + '</div>' +
@ -2250,12 +2250,12 @@ Build =
' </span> ' + ' </span> ' +
"<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " + "<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " +
"<span class='postNum desktop'>" + "<span class='postNum desktop'>" +
"<a href=#{"/#{board}/res/#{threadID}#p#{postID}"} title='Highlight this post'>No.</a>" + "<a href=#{"/#{boardID}/res/#{threadID}#p#{postID}"} title='Highlight this post'>No.</a>" +
"<a href='#{ "<a href='#{
if g.VIEW is 'thread' and g.THREAD is +threadID if g.VIEW is 'thread' and g.THREAD is +threadID
"javascript:quote(#{postID})" "javascript:quote(#{postID})"
else else
"/#{board}/res/#{threadID}#q#{postID}" "/#{boardID}/res/#{threadID}#q#{postID}"
}' title='Quote this post'>#{postID}</a>" + }' title='Quote this post'>#{postID}</a>" +
'</span>' + '</span>' +
'</div>' + '</div>' +
@ -2269,7 +2269,7 @@ Build =
for quote in $$ '.quotelink', container for quote in $$ '.quotelink', container
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
quote.href = "/#{board}/res/#{href}" # Fix pathnames quote.href = "/#{boardID}/res/#{href}" # Fix pathnames
container container
@ -2282,11 +2282,11 @@ Get =
$('.nameBlock', OP.nodes.info).textContent.trim() $('.nameBlock', OP.nodes.info).textContent.trim()
"/#{thread.board}/ - #{excerpt}" "/#{thread.board}/ - #{excerpt}"
postFromRoot: (root) -> postFromRoot: (root) ->
link = $ 'a[title="Highlight this post"]', root link = $ 'a[title="Highlight this post"]', root
board = 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["#{board}.#{postID}"] post = g.posts["#{boardID}.#{postID}"]
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::div[contains(@class,"postContainer")][1]', root
@ -2299,7 +2299,7 @@ Get =
threadID = path[3] threadID = path[3]
postID = link.hash[2..] postID = link.hash[2..]
else # resurrected quote else # resurrected quote
boardID = link.dataset.board boardID = link.dataset.boardid
threadID = link.dataset.threadid or 0 threadID = link.dataset.threadid or 0
postID = link.dataset.postid postID = link.dataset.postid
return { return {
@ -2333,18 +2333,18 @@ Get =
quotelinks.filter (quotelink) -> quotelinks.filter (quotelink) ->
{boardID, postID} = Get.postDataFromLink quotelink {boardID, postID} = Get.postDataFromLink quotelink
boardID is post.board.ID and postID is post.ID boardID is post.board.ID and postID is post.ID
postClone: (board, threadID, postID, root, context) -> postClone: (boardID, threadID, postID, root, context) ->
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{boardID}.#{postID}"]
Get.insert post, root, context Get.insert post, root, context
return return
root.textContent = "Loading post No.#{postID}..." root.textContent = "Loading post No.#{postID}..."
if threadID if threadID
$.cache "//api.4chan.org/#{board}/res/#{threadID}.json", -> $.cache "//api.4chan.org/#{boardID}/res/#{threadID}.json", ->
Get.fetchedPost @, board, threadID, postID, root, context Get.fetchedPost @, boardID, threadID, postID, root, context
else if url = Redirect.post board, postID else if url = Redirect.post boardID, postID
$.cache url, -> $.cache url, ->
Get.archivedPost @, board, postID, root, context Get.archivedPost @, boardID, postID, root, context
insert: (post, root, context) -> insert: (post, root, context) ->
# Stop here if the container has been removed while loading. # Stop here if the container has been removed while loading.
return unless root.parentNode return unless root.parentNode
@ -2358,19 +2358,19 @@ Get =
root.innerHTML = null root.innerHTML = null
$.add root, nodes.root $.add root, nodes.root
fetchedPost: (req, board, threadID, postID, root, context) -> fetchedPost: (req, boardID, threadID, postID, root, context) ->
# In case of multiple callbacks for the same request, # In case of multiple callbacks for the same request,
# don't parse the same original post more than once. # don't parse the same original post more than once.
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{boardID}.#{postID}"]
Get.insert post, root, context Get.insert post, root, context
return return
{status} = req {status} = req
if status not in [200, 304] if status not in [200, 304]
# The thread can die by the time we check a quote. # The thread can die by the time we check a quote.
if url = Redirect.post board, postID if url = Redirect.post boardID, postID
$.cache url, -> $.cache url, ->
Get.archivedPost @, board, postID, root, context Get.archivedPost @, boardID, postID, root, context
else else
$.addClass root, 'warning' $.addClass root, 'warning'
root.textContent = root.textContent =
@ -2381,30 +2381,30 @@ Get =
return return
posts = JSON.parse(req.response).posts posts = JSON.parse(req.response).posts
Build.spoilerRange[board] = posts[0].custom_spoiler Build.spoilerRange[boardID] = posts[0].custom_spoiler
for post in posts for post in posts
break if post.no is postID # we found it! break if post.no is postID # we found it!
if post.no > postID if post.no > postID
# The post can be deleted by the time we check a quote. # The post can be deleted by the time we check a quote.
if url = Redirect.post board, postID if url = Redirect.post boardID, postID
$.cache url, -> $.cache url, ->
Get.archivedPost @, board, postID, root, context Get.archivedPost @, boardID, postID, root, context
else else
$.addClass root, 'warning' $.addClass root, 'warning'
root.textContent = "Post No.#{postID} was not found." root.textContent = "Post No.#{postID} was not found."
return return
board = g.boards[board] or board = g.boards[boardID] or
new Board board new Board boardID
thread = g.threads["#{board}.#{threadID}"] or thread = g.threads["#{boardID}.#{threadID}"] or
new Thread threadID, board new Thread threadID, board
post = new Post Build.postFromObject(post, board), thread, board post = new Post Build.postFromObject(post, boardID), thread, board
Main.callbackNodes Post, [post] Main.callbackNodes Post, [post]
Get.insert post, root, context Get.insert post, root, context
archivedPost: (req, board, postID, root, context) -> archivedPost: (req, boardID, postID, root, context) ->
# In case of multiple callbacks for the same request, # In case of multiple callbacks for the same request,
# don't parse the same original post more than once. # don't parse the same original post more than once.
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{boardID}.#{postID}"]
Get.insert post, root, context Get.insert post, root, context
return return
@ -2461,7 +2461,7 @@ Get =
# id # id
postID: "#{postID}" postID: "#{postID}"
threadID: "#{threadID}" threadID: "#{threadID}"
board: board boardID: boardID
# info # info
name: data.name_processed name: data.name_processed
capcode: switch data.capcode capcode: switch data.capcode
@ -2487,14 +2487,14 @@ Get =
width: data.media.media_w width: data.media.media_w
MD5: data.media.media_hash MD5: data.media.media_hash
size: data.media.media_size size: data.media.media_size
turl: data.media.thumb_link or "//thumbs.4chan.org/#{board}/thumb/#{data.media.preview_orig}" turl: data.media.thumb_link or "//thumbs.4chan.org/#{boardID}/thumb/#{data.media.preview_orig}"
theight: data.media.preview_h theight: data.media.preview_h
twidth: data.media.preview_w twidth: data.media.preview_w
isSpoiler: data.media.spoiler is '1' isSpoiler: data.media.spoiler is '1'
board = g.boards[board] or board = g.boards[boardID] or
new Board board new Board boardID
thread = g.threads["#{board}.#{threadID}"] or thread = g.threads["#{boardID}.#{threadID}"] or
new Thread threadID, board new Thread threadID, board
post = new Post Build.post(o, true), thread, board, post = new Post Build.post(o, true), thread, board,
isArchived: true isArchived: true
@ -2518,13 +2518,13 @@ Quotify =
continue continue
quote = deadlink.textContent quote = deadlink.textContent
continue unless ID = quote.match(/\d+$/)?[0] continue unless postID = quote.match(/\d+$/)?[0]
board = boardID =
if m = quote.match /^>>>\/([a-z\d]+)/ if m = quote.match /^>>>\/([a-z\d]+)/
m[1] m[1]
else else
@board.ID @board.ID
quoteID = "#{board}.#{ID}" quoteID = "#{boardID}.#{postID}"
# \u00A0 is nbsp # \u00A0 is nbsp
if post = g.posts[quoteID] if post = g.posts[quoteID]
@ -2532,31 +2532,31 @@ Quotify =
# Don't (Dead) when quotifying in an archived post, # Don't (Dead) when quotifying in an archived post,
# and we know the post still exists. # and we know the post still exists.
a = $.el 'a', a = $.el 'a',
href: "/#{board}/#{post.thread}/res/#p#{ID}" href: "/#{boardID}/#{post.thread}/res/#p#{postID}"
className: 'quotelink' className: 'quotelink'
textContent: quote textContent: quote
else else
# Replace the .deadlink span if we can redirect. # Replace the .deadlink span if we can redirect.
a = $.el 'a', a = $.el 'a',
href: "/#{board}/#{post.thread}/res/#p#{ID}" href: "/#{boardID}/#{post.thread}/res/#p#{postID}"
className: 'quotelink deadlink' className: 'quotelink deadlink'
target: '_blank' target: '_blank'
textContent: "#{quote}\u00A0(Dead)" textContent: "#{quote}\u00A0(Dead)"
a.setAttribute 'data-board', board a.setAttribute 'data-boardid', boardID
a.setAttribute 'data-threadid', post.thread.ID a.setAttribute 'data-threadid', post.thread.ID
a.setAttribute 'data-postid', ID a.setAttribute 'data-postid', postID
else if redirect = Redirect.to {board, threadID: 0, postID: ID} else if redirect = Redirect.to {boardID, threadID: 0, postID}
# Replace the .deadlink span if we can redirect. # Replace the .deadlink span if we can redirect.
a = $.el 'a', a = $.el 'a',
href: redirect href: redirect
className: 'deadlink' className: 'deadlink'
target: '_blank' target: '_blank'
textContent: "#{quote}\u00A0(Dead)" textContent: "#{quote}\u00A0(Dead)"
if Redirect.post board, ID if Redirect.post boardID, postID
# Make it function as a normal quote if we can fetch the post. # Make it function as a normal quote if we can fetch the post.
$.addClass a, 'quotelink' $.addClass a, 'quotelink'
a.setAttribute 'data-board', board a.setAttribute 'data-boardid', boardID
a.setAttribute 'data-postid', ID a.setAttribute 'data-postid', postID
unless quoteID in @quotes unless quoteID in @quotes
@quotes.push quoteID @quotes.push quoteID

View File

@ -428,9 +428,9 @@ Main =
if d.title is '4chan - 404 Not Found' if d.title is '4chan - 404 Not Found'
if Conf['404 Redirect'] and g.VIEW is 'thread' if Conf['404 Redirect'] and g.VIEW is 'thread'
href = Redirect.to href = Redirect.to
board: g.BOARD boardID: g.BOARD.ID
threadID: g.THREAD threadID: g.THREAD.ID
postID: location.hash postID: location.hash
location.href = href or "/#{g.BOARD}/" location.href = href or "/#{g.BOARD}/"
return return