ThreadUpdater.disconnect()

This commit is contained in:
Zixaphir 2014-01-07 16:30:18 -07:00
parent 32641549f2
commit 798ab20f35
7 changed files with 252 additions and 131 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -408,6 +408,8 @@ Header =
$.add shortcut, el $.add shortcut, el
$.prepend Header.shortcuts, shortcut $.prepend Header.shortcuts, shortcut
rmShortcut: (el) ->
$.rm el.parentElement
menuToggle: (e) -> menuToggle: (e) ->
Header.menu.toggle e, @, g Header.menu.toggle e, @, g

View File

@ -259,19 +259,14 @@ Main =
features: features:
'Polyfill': Polyfill 'Polyfill': Polyfill
'Emoji': Emoji 'Redirect': Redirect
'Style': Style
'Mascots': MascotTools
'Rice': Rice
'Banner': Banner
'Announcements': GlobalMessage
'Archive Redirection': Redirect
'Header': Header 'Header': Header
'Catalog Links': CatalogLinks 'Catalog Links': CatalogLinks
'Settings': Settings 'Settings': Settings
'Index Generator': Index 'Index Generator': Index
'Announcement Hiding': PSAHiding 'Announcement Hiding': PSAHiding
'Fourchan thingies': Fourchan 'Fourchan thingies': Fourchan
'Emoji': Emoji
'Color User IDs': IDColor 'Color User IDs': IDColor
'Custom CSS': CustomCSS 'Custom CSS': CustomCSS
'Linkify': Linkify 'Linkify': Linkify
@ -315,13 +310,14 @@ Main =
'Favicon': Favicon 'Favicon': Favicon
'Unread': Unread 'Unread': Unread
'Quote Threading': QuoteThreading 'Quote Threading': QuoteThreading
'Thread Updater': ThreadUpdater
'Thread Stats': ThreadStats 'Thread Stats': ThreadStats
'Thread Updater': ThreadUpdater
'Thread Watcher': ThreadWatcher 'Thread Watcher': ThreadWatcher
'Thread Watcher (Menu)': ThreadWatcher.menu 'Thread Watcher (Menu)': ThreadWatcher.menu
'Index Navigation': Nav 'Index Navigation': Nav
'Keybinds': Keybinds 'Keybinds': Keybinds
'Show Dice Roll': Dice 'Show Dice Roll': Dice
'Banner': Banner
clean: -> clean: ->
delete g.posts[id] for id of g.posts delete g.posts[id] for id of g.posts

View File

@ -24,6 +24,7 @@ UI = do ->
constructor: (@type) -> constructor: (@type) ->
# Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API # Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API
$.on d, 'AddMenuEntry', @addEntry $.on d, 'AddMenuEntry', @addEntry
$.on d, 'rmMenuEntry', @rmEntry
@entries = [] @entries = []
makeMenu: -> makeMenu: ->
@ -189,6 +190,12 @@ UI = do ->
@parseEntry entry @parseEntry entry
@entries.push entry @entries.push entry
rmEntry: (e) =>
entry = e.detail
return if entry.type isnt @type
index = @entries.indexOf entry
@entries.splice index, 1
parseEntry: (entry) -> parseEntry: (entry) ->
{el, subEntries} = entry {el, subEntries} = entry
$.addClass el, 'entry' $.addClass el, 'entry'

View File

@ -2,6 +2,9 @@ ThreadUpdater =
init: -> init: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Updater'] return if g.VIEW isnt 'thread' or !Conf['Thread Updater']
ThreadUpdater.connect.call @
connect: ->
if Conf['Updater and Stats in Header'] if Conf['Updater and Stats in Header']
@dialog = sc = $.el 'span', @dialog = sc = $.el 'span',
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>" innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>"
@ -22,10 +25,10 @@ ThreadUpdater =
@status = $ '#update-status', sc @status = $ '#update-status', sc
@isUpdating = Conf['Auto Update'] @isUpdating = Conf['Auto Update']
$.on @timer, 'click', ThreadUpdater.update $.on @timer, 'click', @update
$.on @status, 'click', ThreadUpdater.update $.on @status, 'click', @update
subEntries = [] @subEntries = []
for name, conf of Config.updater.checkbox for name, conf of Config.updater.checkbox
checked = if Conf[name] then 'checked' else '' checked = if Conf[name] then 'checked' else ''
el = $.el 'label', el = $.el 'label',
@ -34,20 +37,20 @@ ThreadUpdater =
input = el.firstElementChild input = el.firstElementChild
$.on input, 'change', $.cb.checked $.on input, 'change', $.cb.checked
if input.name is 'Scroll BG' if input.name is 'Scroll BG'
$.on input, 'change', ThreadUpdater.cb.scrollBG $.on input, 'change', @cb.scrollBG
ThreadUpdater.cb.scrollBG() @cb.scrollBG()
else if input.name is 'Auto Update' else if input.name is 'Auto Update'
$.on input, 'change', ThreadUpdater.cb.update $.on input, 'change', @cb.update
subEntries.push el: el subEntries.push el: el
settings = $.el 'span', @settings = $.el 'span',
innerHTML: '<a href=javascript:;>Interval</a>' innerHTML: '<a href=javascript:;>Interval</a>'
$.on settings, 'click', @intervalShortcut $.on @settings, 'click', @intervalShortcut
subEntries.push el: settings subEntries.push el: settings
$.event 'AddMenuEntry', $.event 'AddMenuEntry', @entry =
type: 'header' type: 'header'
el: $.el 'span', el: $.el 'span',
textContent: 'Updater' textContent: 'Updater'
@ -58,6 +61,35 @@ ThreadUpdater =
name: 'Thread Updater' name: 'Thread Updater'
cb: @node cb: @node
disconnect: ->
if Conf['Updater and Stats in Header']
Header.rmShortcut @dialog
else
$.rmClass doc, 'float'
$.rm @dialog
$.off @timer, 'click', @update
$.off @status, 'click', @update
for entry in @entry.subEntries
{el} = entry
input = el.firstElementChild
$.off input, 'change', $.cb.checked
$.off input, 'change', @cb.scrollBG
$.off input, 'change', @cb.update
$.off @settings, 'click', @intervalShortcut
$.event 'rmMenuEntry', @entry
delete @checkPostCount
delete @timer
delete @status
delete @isUpdating
delete @entry
Thread.callbacks.rm 'Thread Updater'
node: -> node: ->
ThreadUpdater.thread = @ ThreadUpdater.thread = @
ThreadUpdater.root = @OP.nodes.root.parentNode ThreadUpdater.root = @OP.nodes.root.parentNode

View File

@ -2,7 +2,7 @@ Unread =
init: -> init: ->
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications'] return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications']
Unread.connect() Unread.connect.call this
connect: -> connect: ->
@db = new DataBoard 'lastReadPosts', @sync @db = new DataBoard 'lastReadPosts', @sync
@ -21,12 +21,12 @@ Unread =
Unread.db.disconnect() Unread.db.disconnect()
$.rm hr, parent if parent = (hr = Unread.hr).parentElement $.rm hr, parent if parent = (hr = Unread.hr).parentElement
delete Unread[name] for name in ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost'] delete @[name] for name in ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost']
$.off d, '4chanXInitFinished', Unread.ready $.off d, '4chanXInitFinished', @ready
$.off d, 'ThreadUpdate', Unread.onUpdate $.off d, 'ThreadUpdate', @onUpdate
$.off d, 'scroll visibilitychange', Unread.read $.off d, 'scroll visibilitychange', @read
$.off d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] $.off d, 'visibilitychange', @setLine if Conf['Unread Line']
Thread.callbacks.rm 'Unread' Thread.callbacks.rm 'Unread'