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,12 +59,14 @@
*/ */
(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 = {
main: {
checkbox: {
'404 Redirect': [true, 'Redirect dead threads'], '404 Redirect': [true, 'Redirect dead threads'],
'Anonymize': [false, 'Make everybody anonymous'], 'Anonymize': [false, 'Make everybody anonymous'],
'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'], 'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'],
@ -89,6 +91,15 @@
'Thread Updater': [true, 'Update threads'], 'Thread Updater': [true, 'Update threads'],
'Thread Watcher': [true, 'Bookmark threads'], 'Thread Watcher': [true, 'Bookmark threads'],
'Unread Count': [true, 'Show unread post count in tab title'] '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,6 +7,8 @@
{log} = console if console? {log} = console if console?
config = config =
main:
checkbox:
'404 Redirect': [true, 'Redirect dead threads'] '404 Redirect': [true, 'Redirect dead threads']
'Anonymize': [false, 'Make everybody anonymous'] 'Anonymize': [false, 'Make everybody anonymous']
'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)'] 'Auto Watch': [true, 'Automatically watch threads that you start (Firefox only)']
@ -31,6 +33,11 @@ config =
'Thread Updater': [true, 'Update threads'] 'Thread Updater': [true, 'Update threads']
'Thread Watcher': [true, 'Bookmark threads'] 'Thread Watcher': [true, 'Bookmark threads']
'Unread Count': [true, 'Show unread post count in tab title'] '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'