Support refreshing threads in Thread Watcher from any site with 4chan-compatible JSON API.
This commit is contained in:
parent
4c139b3b0f
commit
fbb54b58f7
@ -211,12 +211,14 @@ ThreadWatcher =
|
|||||||
|
|
||||||
fetchStatus: (thread, force) ->
|
fetchStatus: (thread, force) ->
|
||||||
{siteID, boardID, threadID, data} = thread
|
{siteID, boardID, threadID, data} = thread
|
||||||
return unless Conf['siteProperties'][siteID]?.software is 'yotsuba'
|
software = Conf['siteProperties'][siteID]?.software
|
||||||
|
url = SW[software]?.urls.threadJSON?({siteID, boardID, threadID})
|
||||||
|
return unless url
|
||||||
return if data.isDead and not force
|
return if data.isDead and not force
|
||||||
|
return if data.last is -1 # 404 or no JSON API
|
||||||
if ThreadWatcher.requests.length is 0
|
if ThreadWatcher.requests.length is 0
|
||||||
ThreadWatcher.status.textContent = '...'
|
ThreadWatcher.status.textContent = '...'
|
||||||
$.addClass ThreadWatcher.refreshButton, 'fa-spin'
|
$.addClass ThreadWatcher.refreshButton, 'fa-spin'
|
||||||
url = "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.json"
|
|
||||||
if Site.hasCORS?(url) or url.split('/')[...3].join('/') is location.origin
|
if Site.hasCORS?(url) or url.split('/')[...3].join('/') is location.origin
|
||||||
req = $.ajax url,
|
req = $.ajax url,
|
||||||
onloadend: ->
|
onloadend: ->
|
||||||
@ -237,6 +239,8 @@ ThreadWatcher =
|
|||||||
else
|
else
|
||||||
ThreadWatcher.status.textContent = "#{Math.round(ThreadWatcher.fetched / ThreadWatcher.requests.length * 100)}%"
|
ThreadWatcher.status.textContent = "#{Math.round(ThreadWatcher.fetched / ThreadWatcher.requests.length * 100)}%"
|
||||||
|
|
||||||
|
software = Conf['siteProperties'][siteID]?.software
|
||||||
|
|
||||||
if @status is 200 and @response
|
if @status is 200 and @response
|
||||||
last = @response.posts[@response.posts.length-1].no
|
last = @response.posts[@response.posts.length-1].no
|
||||||
isDead = !!@response.posts[0].archived
|
isDead = !!@response.posts[0].archived
|
||||||
@ -265,7 +269,8 @@ ThreadWatcher =
|
|||||||
continue unless !quotingYou and QuoteYou.db and postObj.com
|
continue unless !quotingYou and QuoteYou.db and postObj.com
|
||||||
|
|
||||||
quotesYou = false
|
quotesYou = false
|
||||||
regexp = /<a [^>]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^\/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g
|
regexp = SW[software].regexp.quotelinkHTML
|
||||||
|
regexp.lastIndex = 0
|
||||||
while match = regexp.exec postObj.com
|
while match = regexp.exec postObj.com
|
||||||
if QuoteYou.db.get {
|
if QuoteYou.db.get {
|
||||||
siteID
|
siteID
|
||||||
@ -283,7 +288,9 @@ ThreadWatcher =
|
|||||||
ThreadWatcher.refresh() if updated
|
ThreadWatcher.refresh() if updated
|
||||||
|
|
||||||
else if @status is 404
|
else if @status is 404
|
||||||
if Conf['Auto Prune']
|
if SW[software].mayLackJSON and !data.last?
|
||||||
|
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {last: -1}, rm: ['unread', 'quotingYou']}
|
||||||
|
else if Conf['Auto Prune']
|
||||||
ThreadWatcher.db.delete {siteID, boardID, threadID}
|
ThreadWatcher.db.delete {siteID, boardID, threadID}
|
||||||
else
|
else
|
||||||
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']}
|
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']}
|
||||||
@ -317,7 +324,7 @@ ThreadWatcher =
|
|||||||
title: excerpt
|
title: excerpt
|
||||||
className: 'watcher-link'
|
className: 'watcher-link'
|
||||||
|
|
||||||
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and software is 'yotsuba' and data.unread?
|
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and data.unread?
|
||||||
count = $.el 'span',
|
count = $.el 'span',
|
||||||
textContent: "(#{data.unread})"
|
textContent: "(#{data.unread})"
|
||||||
className: 'watcher-unread'
|
className: 'watcher-unread'
|
||||||
@ -334,7 +341,7 @@ ThreadWatcher =
|
|||||||
div.dataset.siteID = siteID
|
div.dataset.siteID = siteID
|
||||||
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
|
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
|
||||||
$.addClass div, 'dead-thread' if data.isDead
|
$.addClass div, 'dead-thread' if data.isDead
|
||||||
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] and software is 'yotsuba'
|
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
|
||||||
$.addClass div, 'replies-read' if data.unread is 0
|
$.addClass div, 'replies-read' if data.unread is 0
|
||||||
$.addClass div, 'replies-unread' if data.unread
|
$.addClass div, 'replies-unread' if data.unread
|
||||||
$.addClass div, 'replies-quoting-you' if data.quotingYou
|
$.addClass div, 'replies-quoting-you' if data.quotingYou
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
SW.tinyboard =
|
SW.tinyboard =
|
||||||
isOPContainerThread: true
|
isOPContainerThread: true
|
||||||
|
mayLackJSON: true
|
||||||
|
|
||||||
disabledFeatures: [
|
disabledFeatures: [
|
||||||
'Board Configuration'
|
'Board Configuration'
|
||||||
@ -56,6 +57,9 @@ SW.tinyboard =
|
|||||||
|
|
||||||
urls:
|
urls:
|
||||||
thread: ({siteID, boardID, threadID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/res/#{threadID}.html"
|
thread: ({siteID, boardID, threadID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/res/#{threadID}.html"
|
||||||
|
threadJSON: ({siteID, boardID, threadID}) ->
|
||||||
|
root = Conf['siteProperties'][siteID]?.root
|
||||||
|
if root then "#{root}#{boardID}/res/#{threadID}.json" else ''
|
||||||
|
|
||||||
selectors:
|
selectors:
|
||||||
board: 'form[name="postcontrols"]'
|
board: 'form[name="postcontrols"]'
|
||||||
@ -105,6 +109,8 @@ SW.tinyboard =
|
|||||||
(\d+) # postID
|
(\d+) # postID
|
||||||
$
|
$
|
||||||
///
|
///
|
||||||
|
quotelinkHTML:
|
||||||
|
/<a [^>]*\bhref="[^"]*\/([^\/]+)\/res\/(\d+)\.html#(\d+)"/g
|
||||||
|
|
||||||
bgColoredEl: ->
|
bgColoredEl: ->
|
||||||
$.el 'div', className: 'post reply'
|
$.el 'div', className: 'post reply'
|
||||||
|
|||||||
@ -2,7 +2,8 @@ SW.yotsuba =
|
|||||||
isOPContainerThread: false
|
isOPContainerThread: false
|
||||||
|
|
||||||
urls:
|
urls:
|
||||||
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
|
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
|
||||||
|
threadJSON: ({boardID, threadID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.json"
|
||||||
|
|
||||||
selectors:
|
selectors:
|
||||||
board: '.board'
|
board: '.board'
|
||||||
@ -58,6 +59,8 @@ SW.yotsuba =
|
|||||||
)?
|
)?
|
||||||
$
|
$
|
||||||
///
|
///
|
||||||
|
quotelinkHTML:
|
||||||
|
/<a [^>]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^\/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g
|
||||||
|
|
||||||
bgColoredEl: ->
|
bgColoredEl: ->
|
||||||
$.el 'div', className: 'reply'
|
$.el 'div', className: 'reply'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user