rm GM_ get/set Value

This commit is contained in:
James Campos 2011-04-18 00:17:49 -07:00
parent ec27fc47ca
commit 208500d5ea
2 changed files with 15 additions and 48 deletions

View File

@ -71,13 +71,13 @@
checkbox: { 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'],
'Comment Expansion': [true, 'Expand too long comments'], 'Comment Expansion': [true, 'Expand too long comments'],
'Image Auto-Gif': [false, 'Animate gif thumbnails'], 'Image Auto-Gif': [false, 'Animate gif thumbnails'],
'Image Expansion': [true, 'Expand images'], 'Image Expansion': [true, 'Expand images'],
'Image Hover': [false, 'Show full image on mouseover'], 'Image Hover': [false, 'Show full image on mouseover'],
'Image Preloading': [false, 'Preload Images'], 'Image Preloading': [false, 'Preload Images'],
'Keybinds': [true, 'Binds actions to keys'], 'Keybinds': [false, 'Binds actions to keys'],
'Localize Time': [true, 'Show times based on your timezone'], 'Localize Time': [true, 'Show times based on your timezone'],
'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'], 'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'],
'Post in Title': [true, 'Show the op\'s post in the tab title'], 'Post in Title': [true, 'Show the op\'s post in the tab title'],
@ -119,26 +119,6 @@
} }
})(null, config); })(null, config);
if (typeof GM_deleteValue === 'undefined') { if (typeof GM_deleteValue === 'undefined') {
window.GM_setValue = function(name, value) {
value = (typeof value)[0] + value;
return localStorage.setItem(name, value);
};
window.GM_getValue = function(name, defaultValue) {
var type, value;
if (!(value = localStorage.getItem(name))) {
return defaultValue;
}
type = value[0];
value = value.slice(1);
switch (type) {
case 'b':
return value === 'true';
case 'n':
return Number(value);
default:
return value;
}
};
window.GM_openInTab = function(url) { window.GM_openInTab = function(url) {
return window.open(url, "_blank"); return window.open(url, "_blank");
}; };
@ -884,7 +864,7 @@
html += "<div><label title=\"" + title + "\">" + name + "<input name=\"" + name + "\" " + checked + " 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>" + ($.getValue('flavors', g.flavors)) + "</textarea></div>";
hiddenThread = $.getValue("hiddenThread/" + g.BOARD + "/", {}); hiddenThread = $.getValue("hiddenThread/" + g.BOARD + "/", {});
hiddenNum = Object.keys(g.hiddenReply).length + Object.keys(hiddenThread).length; hiddenNum = Object.keys(g.hiddenReply).length + Object.keys(hiddenThread).length;
html += "<div><input type=\"button\" value=\"hidden: " + hiddenNum + "\"></div>"; html += "<div><input type=\"button\" value=\"hidden: " + hiddenNum + "\"></div>";
@ -1020,7 +1000,7 @@
$.remove(span); $.remove(span);
} }
} }
if (g.seconds = GM_getValue('seconds')) { if (g.seconds = $.getValue('seconds')) {
e.preventDefault(); e.preventDefault();
qr.cooldownStart(); qr.cooldownStart();
alert('Stop posting so often!'); alert('Stop posting so often!');
@ -1092,7 +1072,7 @@
submit.value = 'Submit'; submit.value = 'Submit';
} else { } else {
submit.value = g.seconds = g.seconds - 1; submit.value = g.seconds = g.seconds - 1;
GM_setValue('seconds', g.seconds); $.setValue('seconds', g.seconds);
} }
} }
if (g.seconds !== 0) { if (g.seconds !== 0) {
@ -1101,7 +1081,7 @@
}, },
cooldownStart: function() { cooldownStart: function() {
var submit, submits, _i, _len; var submit, submits, _i, _len;
GM_setValue('seconds', g.seconds); $.setValue('seconds', g.seconds);
submits = $$('#qr input[type=submit], form[name=post] input[type=submit]'); submits = $$('#qr input[type=submit], form[name=post] input[type=submit]');
for (_i = 0, _len = submits.length; _i < _len; _i++) { for (_i = 0, _len = submits.length; _i < _len; _i++) {
submit = submits[_i]; submit = submits[_i];

View File

@ -4,24 +4,26 @@
# (floating) qr no-quote button? # (floating) qr no-quote button?
# updater cache hacks # updater cache hacks
# XXX
# flavors saving is broken
# XXX chrome can't into `{log} = console` # XXX chrome can't into `{log} = console`
if console? if console?
log = (arg) -> log = (arg) ->
console.log arg console.log arg
# TODO reset defaults
config = config =
main: main:
checkbox: 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']
'Comment Expansion': [true, 'Expand too long comments'] 'Comment Expansion': [true, 'Expand too long comments']
'Image Auto-Gif': [false, 'Animate gif thumbnails'] 'Image Auto-Gif': [false, 'Animate gif thumbnails']
'Image Expansion': [true, 'Expand images'] 'Image Expansion': [true, 'Expand images']
'Image Hover': [false, 'Show full image on mouseover'] 'Image Hover': [false, 'Show full image on mouseover']
'Image Preloading': [false, 'Preload Images'] 'Image Preloading': [false, 'Preload Images']
'Keybinds': [true, 'Binds actions to keys'] 'Keybinds': [false, 'Binds actions to keys']
'Localize Time': [true, 'Show times based on your timezone'] 'Localize Time': [true, 'Show times based on your timezone']
'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.'] 'Persistent QR': [false, 'Quick reply won\'t disappear after posting. Only in replies.']
'Post in Title': [true, 'Show the op\'s post in the tab title'] 'Post in Title': [true, 'Show the op\'s post in the tab title']
@ -56,21 +58,6 @@ _config = {}
#x-browser #x-browser
if typeof GM_deleteValue is 'undefined' if typeof GM_deleteValue is 'undefined'
window.GM_setValue = (name, value) ->
value = (typeof value)[0] + value
localStorage.setItem name, value
window.GM_getValue = (name, defaultValue) ->
unless value = localStorage.getItem name
return defaultValue
type = value[0]
value = value[1..]
switch type
when 'b'
value == 'true'
when 'n'
Number value
else
value
window.GM_openInTab = (url) -> window.GM_openInTab = (url) ->
window.open url, "_blank" window.open url, "_blank"
@ -659,7 +646,7 @@ options =
checked = if $.config name then "checked" else "" checked = if $.config name then "checked" else ""
html += "<div><label title=\"#{title}\">#{name}<input name=\"#{name}\" #{checked} 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>#{$.getValue 'flavors', g.flavors}</textarea></div>"
hiddenThread = $.getValue "hiddenThread/#{g.BOARD}/", {} hiddenThread = $.getValue "hiddenThread/#{g.BOARD}/", {}
hiddenNum = Object.keys(g.hiddenReply).length + Object.keys(hiddenThread).length hiddenNum = Object.keys(g.hiddenReply).length + Object.keys(hiddenThread).length
@ -768,7 +755,7 @@ qr =
if span = @nextSibling if span = @nextSibling
$.remove span $.remove span
if g.seconds = GM_getValue 'seconds' if g.seconds = $.getValue 'seconds'
e.preventDefault() e.preventDefault()
qr.cooldownStart() qr.cooldownStart()
alert 'Stop posting so often!' alert 'Stop posting so often!'
@ -833,13 +820,13 @@ qr =
submit.value = 'Submit' submit.value = 'Submit'
else else
submit.value = g.seconds = g.seconds - 1 submit.value = g.seconds = g.seconds - 1
GM_setValue 'seconds', g.seconds $.setValue 'seconds', g.seconds
if g.seconds != 0 if g.seconds != 0
window.setTimeout qr.cooldown, 1000 window.setTimeout qr.cooldown, 1000
cooldownStart: -> cooldownStart: ->
GM_setValue 'seconds', g.seconds $.setValue 'seconds', g.seconds
submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]' submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]'
for submit in submits for submit in submits
submit.value = g.seconds submit.value = g.seconds