Update the threads sticky/closed status on each index refresh.
Also fix the position of the sticky/closed icon.
This commit is contained in:
parent
c8f7eef912
commit
2f9e44a773
@ -227,7 +227,7 @@ Build =
|
|||||||
"<span class='nameBlock#{capcodeClass}'>" +
|
"<span class='nameBlock#{capcodeClass}'>" +
|
||||||
emailStart +
|
emailStart +
|
||||||
"<span class=name>#{name or ''}</span>" + tripcode +
|
"<span class=name>#{name or ''}</span>" + tripcode +
|
||||||
capcodeStart + emailEnd + capcode + userID + flag + sticky + closed +
|
capcodeStart + emailEnd + capcode + userID + flag +
|
||||||
' </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'>" +
|
||||||
@ -238,7 +238,7 @@ Build =
|
|||||||
else
|
else
|
||||||
"/#{boardID}/res/#{threadID}#q#{postID}"
|
"/#{boardID}/res/#{threadID}#q#{postID}"
|
||||||
}' title='Quote this post'>#{postID}</a>" +
|
}' title='Quote this post'>#{postID}</a>" +
|
||||||
replyLink +
|
sticky + closed + replyLink +
|
||||||
'</span>' +
|
'</span>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,35 @@ class Thread
|
|||||||
toString: -> @ID
|
toString: -> @ID
|
||||||
|
|
||||||
constructor: (@ID, @board) ->
|
constructor: (@ID, @board) ->
|
||||||
@fullID = "#{@board}.#{@ID}"
|
@fullID = "#{@board}.#{@ID}"
|
||||||
@posts = {}
|
@posts = {}
|
||||||
|
@isSticky = false
|
||||||
|
@isClosed = false
|
||||||
|
@postLimit = false
|
||||||
|
@fileLimit = false
|
||||||
|
|
||||||
g.threads[@fullID] = board.threads[@] = @
|
g.threads[@fullID] = board.threads[@] = @
|
||||||
|
|
||||||
|
setStatus: (type, status) ->
|
||||||
|
name = "is#{type}"
|
||||||
|
return if @[name] is status
|
||||||
|
@[name] = status
|
||||||
|
return unless @OP
|
||||||
|
typeLC = type.toLowerCase()
|
||||||
|
unless status
|
||||||
|
$.rm $ ".#{typeLC}Icon", @OP.nodes.info
|
||||||
|
return
|
||||||
|
icon = $.el 'img',
|
||||||
|
src: "//static.4chan.org/image/#{typeLC}.gif"
|
||||||
|
alt: type
|
||||||
|
title: type
|
||||||
|
className: "#{typeLC}Icon"
|
||||||
|
root = if type is 'Closed' and @isSticky
|
||||||
|
$ '.stickyIcon', @OP.nodes.info
|
||||||
|
else
|
||||||
|
$ '[title="Quote this post"]', @OP.nodes.info
|
||||||
|
$.after root, [$.tn(' '), icon]
|
||||||
|
|
||||||
kill: ->
|
kill: ->
|
||||||
@isDead = true
|
@isDead = true
|
||||||
@timeOfDeath = Date.now()
|
@timeOfDeath = Date.now()
|
||||||
|
|||||||
@ -118,7 +118,10 @@ Index =
|
|||||||
for threadData in Index.liveThreadData
|
for threadData in Index.liveThreadData
|
||||||
threadRoot = Build.thread g.BOARD, threadData
|
threadRoot = Build.thread g.BOARD, threadData
|
||||||
Index.nodes.push threadRoot, $.el 'hr'
|
Index.nodes.push threadRoot, $.el 'hr'
|
||||||
unless thread = g.BOARD.threads[threadData.no]
|
if thread = g.BOARD.threads[threadData.no]
|
||||||
|
thread.setStatus 'Sticky', !!threadData.sticky
|
||||||
|
thread.setStatus 'Closed', !!threadData.closed
|
||||||
|
else
|
||||||
thread = new Thread threadData.no, g.BOARD
|
thread = new Thread threadData.no, g.BOARD
|
||||||
threads.push thread
|
threads.push thread
|
||||||
postRoots = $$ '.thread > .postContainer', threadRoot
|
postRoots = $$ '.thread > .postContainer', threadRoot
|
||||||
|
|||||||
@ -155,38 +155,27 @@ ThreadUpdater =
|
|||||||
,
|
,
|
||||||
whenModified: true
|
whenModified: true
|
||||||
|
|
||||||
updateThreadStatus: (title, OP) ->
|
updateThreadStatus: (type, status) ->
|
||||||
titleLC = title.toLowerCase()
|
return unless hasChanged = ThreadUpdater.thread["is#{type}"] isnt status
|
||||||
return if ThreadUpdater.thread["is#{title}"] is !!OP[titleLC]
|
ThreadUpdater.thread.setStatus type, status
|
||||||
unless ThreadUpdater.thread["is#{title}"] = !!OP[titleLC]
|
change = if type is 'Sticky'
|
||||||
message = if title is 'Sticky'
|
if status
|
||||||
'The thread is not a sticky anymore.'
|
'now a sticky'
|
||||||
else
|
else
|
||||||
'The thread is not closed anymore.'
|
'not a sticky anymore'
|
||||||
new Notice 'info', message, 30
|
|
||||||
$.rm $ ".#{titleLC}Icon", ThreadUpdater.thread.OP.nodes.info
|
|
||||||
return
|
|
||||||
message = if title is 'Sticky'
|
|
||||||
'The thread is now a sticky.'
|
|
||||||
else
|
else
|
||||||
'The thread is now closed.'
|
if status
|
||||||
new Notice 'info', message, 30
|
'now closed'
|
||||||
icon = $.el 'img',
|
else
|
||||||
src: "//static.4chan.org/image/#{titleLC}.gif"
|
'not closed anymore'
|
||||||
alt: title
|
new Notice 'info', "The thread is #{change}.", 30
|
||||||
title: title
|
|
||||||
className: "#{titleLC}Icon"
|
|
||||||
root = $ '[title="Quote this post"]', ThreadUpdater.thread.OP.nodes.info
|
|
||||||
if title is 'Closed'
|
|
||||||
root = $('.stickyIcon', ThreadUpdater.thread.OP.nodes.info) or root
|
|
||||||
$.after root, [$.tn(' '), icon]
|
|
||||||
|
|
||||||
parse: (postObjects) ->
|
parse: (postObjects) ->
|
||||||
OP = postObjects[0]
|
OP = postObjects[0]
|
||||||
Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler
|
Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler
|
||||||
|
|
||||||
ThreadUpdater.updateThreadStatus 'Sticky', OP
|
ThreadUpdater.updateThreadStatus 'Sticky', !!OP.sticky
|
||||||
ThreadUpdater.updateThreadStatus 'Closed', OP
|
ThreadUpdater.updateThreadStatus 'Closed', !!OP.closed
|
||||||
ThreadUpdater.thread.postLimit = !!OP.bumplimit
|
ThreadUpdater.thread.postLimit = !!OP.bumplimit
|
||||||
ThreadUpdater.thread.fileLimit = !!OP.imagelimit
|
ThreadUpdater.thread.fileLimit = !!OP.imagelimit
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user