start thread updater rewrite

This commit is contained in:
James Campos 2011-04-08 22:50:08 -07:00
parent 9b6667be1a
commit de6794515f
2 changed files with 188 additions and 69 deletions

View File

@ -59,36 +59,47 @@
*/ */
(function() { (function() {
var $, $$, NAMESPACE, a, arr, as, autoWatch, callback, changeCheckbox, changeValue, config, d, delform, down, el, expand, expandComment, expandThread, g, getThread, href, i, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, keyModeInsert, keyModeNormal, keydown, keypress, l1, log, navtopr, nodeInserted, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, replyNav, report, request, scroll, scrollThread, span, temp, text, textContent, threadHiding, tzOffset, ui, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updateVerbose, updaterMake, watcher, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4; var $, $$, NAMESPACE, a, arr, as, autoWatch, callback, changeCheckbox, changeValue, config, d, delform, down, el, expand, expandComment, expandThread, g, getThread, href, i, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, keyModeInsert, keyModeNormal, keydown, keypress, l1, log, navtopr, nodeInserted, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, replyNav, report, request, scroll, scrollThread, span, temp, text, textContent, threadHiding, tzOffset, ui, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updateVerbose, updater, updaterMake, watcher, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4;
var __slice = Array.prototype.slice; var __slice = Array.prototype.slice;
if (typeof console != "undefined" && console !== null) { if (typeof console != "undefined" && console !== null) {
log = console.log; log = console.log;
} }
config = { config = {
'404 Redirect': [true, 'Redirect dead threads'], main: {
'Anonymize': [false, 'Make everybody anonymous'], checkbox: {
'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'], '404 Redirect': [true, 'Redirect dead threads'],
'Comment Expansion': [true, 'Expand too long comments'], 'Anonymize': [false, 'Make everybody anonymous'],
'Image Auto-Gif': [false, 'Animate gif thumbnails'], 'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'],
'Image Expansion': [true, 'Expand images'], 'Comment Expansion': [true, 'Expand too long comments'],
'Image Hover': [false, 'Show full image on mouseover'], 'Image Auto-Gif': [false, 'Animate gif thumbnails'],
'Image Preloading': [false, 'Preload Images'], 'Image Expansion': [true, 'Expand images'],
'Keybinds': [false, 'Binds actions to keys'], 'Image Hover': [false, 'Show full image on mouseover'],
'Localize Time': [true, 'Show times based on your timezone'], 'Image Preloading': [false, 'Preload Images'],
'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'], 'Keybinds': [false, 'Binds actions to keys'],
'Post in Title': [true, 'Show the op\'s post in the tab title'], 'Localize Time': [true, 'Show times based on your timezone'],
'Quick Reply': [true, 'Reply without leaving the page'], 'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'],
'Quick Report': [true, 'Add quick report buttons'], 'Post in Title': [true, 'Show the op\'s post in the tab title'],
'Reply Hiding': [true, 'Hide single replies'], 'Quick Reply': [true, 'Reply without leaving the page'],
'Reply Navigation': [false, 'Navigate to the beginning / end of a thread'], 'Quick Report': [true, 'Add quick report buttons'],
'Sauce': [true, 'Add sauce to images'], 'Reply Hiding': [true, 'Hide single replies'],
'Show Stubs': [true, 'Of hidden threads / replies'], 'Reply Navigation': [false, 'Navigate to the beginning / end of a thread'],
'Thread Expansion': [true, 'View all replies'], 'Sauce': [true, 'Add sauce to images'],
'Thread Hiding': [true, 'Hide entire threads'], 'Show Stubs': [true, 'Of hidden threads / replies'],
'Thread Navigation': [true, 'Navigate to previous / next thread'], 'Thread Expansion': [true, 'View all replies'],
'Thread Updater': [true, 'Update threads'], 'Thread Hiding': [true, 'Hide entire threads'],
'Thread Watcher': [true, 'Bookmark threads'], 'Thread Navigation': [true, 'Navigate to previous / next thread'],
'Unread Count': [true, 'Show unread post count in tab title'] 'Thread Updater': [true, 'Update threads'],
'Thread Watcher': [true, 'Bookmark threads'],
'Unread Count': [true, 'Show unread post count in tab title']
}
},
updater: {
checkbox: {
'Verbose': [true, 'Show countdown timer, new post count'],
'Auto Update': [false, 'Automatically fetch new posts']
},
'Interval': 30
}
}; };
if (typeof GM_deleteValue === 'undefined') { if (typeof GM_deleteValue === 'undefined') {
window.GM_setValue = function(name, value) { window.GM_setValue = function(name, value) {
@ -229,10 +240,10 @@
$.extend($, { $.extend($, {
cb: { cb: {
checked: function() { checked: function() {
return GM_setValue(this.name, this.checked); return $.getValue(this.name, this.checked);
}, },
value: function() { value: function() {
return GM_setValue(this.name, this.value); return $.setValue(this.name, this.checked);
} }
}, },
deleteValue: function(name) { deleteValue: function(name) {
@ -259,8 +270,11 @@
style.textContent = css; style.textContent = css;
return $.append(d.head, style); return $.append(d.head, style);
}, },
config: function(name) { config: function(name, conf) {
return GM_getValue(name, config[name][0]); if (conf == null) {
conf = config.main.checkbox;
}
return $.getValue(name, conf[name][0]);
}, },
zeroPad: function(n) { zeroPad: function(n) {
if (n < 10) { if (n < 10) {
@ -917,12 +931,13 @@
} }
}, },
dialog: function() { dialog: function() {
var checked, dialog, hiddenNum, hiddenThread, html, input, name, title, _i, _len, _ref; var checked, conf, dialog, hiddenNum, hiddenThread, html, input, name, title, _i, _len, _ref;
html = "<div class=move>Options <a name=close>X</a></div>"; html = "<div class=move>Options <a name=close>X</a></div>";
for (name in config) { conf = config.main.checkbox;
title = config[name][1]; for (name in conf) {
title = conf[name][1];
checked = $.config(name) ? "checked" : ""; checked = $.config(name) ? "checked" : "";
html += "<div><label title=\"" + title + "\">" + name + "<input " + checked + " name=\"" + name + "\" type=checkbox></label></div>"; html += "<div><label title=\"" + title + "\">" + name + "<input name=\"" + name + "\" " + checked + " type=checkbox></label></div>";
} }
html += "<div><a name=flavors>Flavors</a></div>"; html += "<div><a name=flavors>Flavors</a></div>";
html += "<div><textarea style=\"display: none;\" name=flavors>" + (GM_getValue('flavors', g.flavors)) + "</textarea></div>"; html += "<div><textarea style=\"display: none;\" name=flavors>" + (GM_getValue('flavors', g.flavors)) + "</textarea></div>";
@ -1543,6 +1558,57 @@
return $("#updater #count").textContent = 'Thread Updater'; return $("#updater #count").textContent = 'Thread Updater';
} }
}; };
updater = {
init: function() {
var autoUpT, box, checked, conf, dialog, html, name, title, verbose, _i, _len, _ref;
html = "<div class=move><span id=count></span> <span id=timer></span></div>";
conf = config.updater.checkbox;
for (name in conf) {
title = conf[name][1];
checked = $.config(name, conf) ? "checked" : "";
html += "<div><label title=\"" + title + "\">" + name + "<input name=\"" + name + "\" " + checked + " type=checkbox></label></div>";
}
name = 'Auto Update This';
title = 'Controls whether *this* thread auotmatically updates or not';
checked = $.config('Auto Update', conf) ? 'checked' : '';
html += "<div><label title=\"" + title + "\">" + name + "<input name=\"" + name + "\" " + checked + " type=checkbox></label></div>";
dialog = ui.dialog('updater', {
bottom: '0px',
right: '0px'
}, html);
_ref = $$('input[type=checkbox]', dialog);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
box = _ref[_i];
$.bind(box, 'click', $.cb.checked);
}
verbose = $('input[name=\"Verbose\"]', dialog);
autoUpT = $('input[name=\"Auto Update This\"]', dialog);
$.bind(verbose, 'click', updater.cb.verbose);
$.bind(autoUpT, 'click', updater.cb.autoUpdate);
$.append(d.body, dialog);
return updater.cb.verbose.call(verbose);
},
cb: {
verbose: function(e) {
var t;
if (this.checked) {
$.show($('#count'));
return $('#timer').textContent = (t = updater.timer) ? t : 'Thread Updater';
} else {
$.hide($('#count'));
return $('#timer').textContent = 'Thread Updater';
}
},
autoUpdate: function(e) {
if (this.checked) {
updater.timer = $.config('Interval', config.updater);
return $('#timer').textContent = updater.timer;
} else {
return updater.timer = null;
}
}
}
};
updaterMake = function() { updaterMake = function() {
var div, html, input, interval, name, _i, _len, _ref; var div, html, input, interval, name, _i, _len, _ref;
html = "<div class=move><span id=count>Thread Updater</span> <span id=timer></span></div>"; html = "<div class=move><span id=count>Thread Updater</span> <span id=timer></span></div>";
@ -2029,6 +2095,9 @@
$.bind(d, 'keydown', keydown); $.bind(d, 'keydown', keydown);
$.bind(d, 'keypress', keypress); $.bind(d, 'keypress', keypress);
} }
if ($.config('Thread Updater')) {
updater.init();
}
if (g.REPLY) { if (g.REPLY) {
if ($.config('Image Preloading')) { if ($.config('Image Preloading')) {
g.callbacks.push(function(root) { g.callbacks.push(function(root) {
@ -2045,9 +2114,6 @@
return _results; return _results;
}); });
} }
if ($.config('Thread Updater')) {
updaterMake();
}
if ($.config('Quick Reply') && $.config('Persistent QR')) { if ($.config('Quick Reply') && $.config('Persistent QR')) {
qr.persist(); qr.persist();
} }

View File

@ -7,30 +7,37 @@
{log} = console if console? {log} = console if console?
config = config =
'404 Redirect': [true, 'Redirect dead threads'] main:
'Anonymize': [false, 'Make everybody anonymous'] checkbox:
'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'] '404 Redirect': [true, 'Redirect dead threads']
'Comment Expansion': [true, 'Expand too long comments'] 'Anonymize': [false, 'Make everybody anonymous']
'Image Auto-Gif': [false, 'Animate gif thumbnails'] 'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)']
'Image Expansion': [true, 'Expand images'] 'Comment Expansion': [true, 'Expand too long comments']
'Image Hover': [false, 'Show full image on mouseover'] 'Image Auto-Gif': [false, 'Animate gif thumbnails']
'Image Preloading': [false, 'Preload Images'] 'Image Expansion': [true, 'Expand images']
'Keybinds': [false, 'Binds actions to keys'] 'Image Hover': [false, 'Show full image on mouseover']
'Localize Time': [true, 'Show times based on your timezone'] 'Image Preloading': [false, 'Preload Images']
'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'] 'Keybinds': [false, 'Binds actions to keys']
'Post in Title': [true, 'Show the op\'s post in the tab title'] 'Localize Time': [true, 'Show times based on your timezone']
'Quick Reply': [true, 'Reply without leaving the page'] 'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.']
'Quick Report': [true, 'Add quick report buttons'] 'Post in Title': [true, 'Show the op\'s post in the tab title']
'Reply Hiding': [true, 'Hide single replies'] 'Quick Reply': [true, 'Reply without leaving the page']
'Reply Navigation': [false, 'Navigate to the beginning / end of a thread'] 'Quick Report': [true, 'Add quick report buttons']
'Sauce': [true, 'Add sauce to images'] 'Reply Hiding': [true, 'Hide single replies']
'Show Stubs': [true, 'Of hidden threads / replies'] 'Reply Navigation': [false, 'Navigate to the beginning / end of a thread']
'Thread Expansion': [true, 'View all replies'] 'Sauce': [true, 'Add sauce to images']
'Thread Hiding': [true, 'Hide entire threads'] 'Show Stubs': [true, 'Of hidden threads / replies']
'Thread Navigation': [true, 'Navigate to previous / next thread'] 'Thread Expansion': [true, 'View all replies']
'Thread Updater': [true, 'Update threads'] 'Thread Hiding': [true, 'Hide entire threads']
'Thread Watcher': [true, 'Bookmark threads'] 'Thread Navigation': [true, 'Navigate to previous / next thread']
'Unread Count': [true, 'Show unread post count in tab title'] 'Thread Updater': [true, 'Update threads']
'Thread Watcher': [true, 'Bookmark threads']
'Unread Count': [true, 'Show unread post count in tab title']
updater:
checkbox:
'Verbose': [true, 'Show countdown timer, new post count']
'Auto Update': [false, 'Automatically fetch new posts']
'Interval': 30
#x-browser #x-browser
if typeof GM_deleteValue is 'undefined' if typeof GM_deleteValue is 'undefined'
@ -135,9 +142,9 @@ $.extend = (object, properties) ->
$.extend $, $.extend $,
cb: cb:
checked: -> checked: ->
GM_setValue @name, @checked $.getValue @name, @checked
value: -> value: ->
GM_setValue @name, @value $.setValue @name, @checked
deleteValue: (name) -> deleteValue: (name) ->
name = NAMESPACE + name name = NAMESPACE + name
delete localStorage[name] delete localStorage[name]
@ -155,8 +162,8 @@ $.extend $,
style.type = 'text/css' style.type = 'text/css'
style.textContent = css style.textContent = css
$.append d.head, style $.append d.head, style
config: (name) -> config: (name, conf=config.main.checkbox) ->
GM_getValue name, config[name][0] $.getValue name, conf[name][0]
zeroPad: (n) -> zeroPad: (n) ->
if n < 10 then '0' + n else n if n < 10 then '0' + n else n
x: (path, root=d.body) -> x: (path, root=d.body) ->
@ -675,10 +682,11 @@ options =
dialog: -> dialog: ->
html = "<div class=move>Options <a name=close>X</a></div>" html = "<div class=move>Options <a name=close>X</a></div>"
for name of config conf = config.main.checkbox
title = config[name][1] for name of conf
title = conf[name][1]
checked = if $.config name then "checked" else "" checked = if $.config name then "checked" else ""
html += "<div><label title=\"#{title}\">#{name}<input #{checked} name=\"#{name}\" type=checkbox></label></div>" html += "<div><label title=\"#{title}\">#{name}<input name=\"#{name}\" #{checked} type=checkbox></label></div>"
html += "<div><a name=flavors>Flavors</a></div>" html += "<div><a name=flavors>Flavors</a></div>"
html += "<div><textarea style=\"display: none;\" name=flavors>#{GM_getValue 'flavors', g.flavors}</textarea></div>" html += "<div><textarea style=\"display: none;\" name=flavors>#{GM_getValue 'flavors', g.flavors}</textarea></div>"
@ -1180,6 +1188,50 @@ updateVerbose = ->
timer.hidden = true timer.hidden = true
$("#updater #count").textContent = 'Thread Updater' $("#updater #count").textContent = 'Thread Updater'
updater =
init: ->
html = "<div class=move><span id=count></span> <span id=timer></span></div>"
conf = config.updater.checkbox
for name of conf
title = conf[name][1]
checked = if $.config name, conf then "checked" else ""
html += "<div><label title=\"#{title}\">#{name}<input name=\"#{name}\" #{checked} type=checkbox></label></div>"
name = 'Auto Update This'
title = 'Controls whether *this* thread auotmatically updates or not'
checked = if $.config 'Auto Update', conf then 'checked' else ''
html += "<div><label title=\"#{title}\">#{name}<input name=\"#{name}\" #{checked} type=checkbox></label></div>"
dialog = ui.dialog 'updater', bottom: '0px', right: '0px', html
for box in $$ 'input[type=checkbox]', dialog
$.bind box, 'click', $.cb.checked
verbose = $ 'input[name=\"Verbose\"]', dialog
autoUpT = $ 'input[name=\"Auto Update This\"]', dialog
$.bind verbose, 'click', updater.cb.verbose
$.bind autoUpT, 'click', updater.cb.autoUpdate
$.append d.body, dialog
updater.cb.verbose.call verbose
#updater.cb.autoUpdate.call autoUpT
cb:
verbose: (e) ->
if @checked
$.show $ '#count'
$('#timer').textContent = if t = updater.timer then t else 'Thread Updater'
else
$.hide $ '#count'
$('#timer').textContent = 'Thread Updater'
autoUpdate: (e) ->
if @checked
updater.timer = $.config 'Interval', config.updater
$('#timer').textContent = updater.timer
else
updater.timer = null
updaterMake = -> updaterMake = ->
html = "<div class=move><span id=count>Thread Updater</span> <span id=timer></span></div>" html = "<div class=move><span id=count>Thread Updater</span> <span id=timer></span></div>"
html += "<div><label>Verbose<input type=checkbox name=verbose></label></div>" html += "<div><label>Verbose<input type=checkbox name=verbose></label></div>"
@ -1594,6 +1646,9 @@ if $.config 'Keybinds'
$.bind d, 'keydown', keydown $.bind d, 'keydown', keydown
$.bind d, 'keypress', keypress $.bind d, 'keypress', keypress
if $.config 'Thread Updater'
updater.init()
if g.REPLY if g.REPLY
if $.config 'Image Preloading' if $.config 'Image Preloading'
g.callbacks.push (root) -> g.callbacks.push (root) ->
@ -1601,8 +1656,6 @@ if g.REPLY
for thumb in thumbs for thumb in thumbs
parent = thumb.parentNode parent = thumb.parentNode
el = $.el 'img', src: parent.href el = $.el 'img', src: parent.href
if $.config 'Thread Updater'
updaterMake()
if $.config('Quick Reply') and $.config 'Persistent QR' if $.config('Quick Reply') and $.config 'Persistent QR'
qr.persist() qr.persist()
if $.config 'Post in Title' if $.config 'Post in Title'