From 56e583c87f894ad8f2b29bb3ca446f1830b927e8 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 10 Aug 2011 19:29:58 -0700 Subject: [PATCH] {get,set,delete}Value -> {get,set,delete}; $.get -> $.xhr --- 4chan_x.user.js | 94 ++++++++++++++++++++++++------------------------- script.coffee | 92 +++++++++++++++++++++++------------------------ 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 42d0af6e0..e62aa5283 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -308,7 +308,7 @@ $.append(d.head, script); return $.rm(script); }, - get: function(url, cb) { + xhr: function(url, cb) { var r; r = new XMLHttpRequest(); r.onload = cb; @@ -325,7 +325,7 @@ return req.callbacks.push(cb); } } else { - req = $.get(url, (function() { + req = $.xhr(url, (function() { var cb, _i, _len, _ref, _results; _ref = this.callbacks; _results = []; @@ -341,10 +341,10 @@ }, cb: { checked: function() { - return $.setValue(this.name, this.checked); + return $.set(this.name, this.checked); }, value: function() { - return $.setValue(this.name, this.value); + return $.set(this.name, this.value); } }, addStyle: function(css) { @@ -461,11 +461,11 @@ $.cache.requests = {}; if (typeof GM_deleteValue !== "undefined" && GM_deleteValue !== null) { $.extend($, { - deleteValue: function(name) { + "delete": function(name) { name = NAMESPACE + name; return GM_deleteValue(name); }, - getValue: function(name, defaultValue) { + get: function(name, defaultValue) { var value; name = NAMESPACE + name; if (value = GM_getValue(name)) { @@ -477,7 +477,7 @@ openInTab: function(url) { return GM_openInTab(url); }, - setValue: function(name, value) { + set: function(name, value) { name = NAMESPACE + name; localStorage[name] = JSON.stringify(value); return GM_setValue(name, JSON.stringify(value)); @@ -485,11 +485,11 @@ }); } else { $.extend($, { - deleteValue: function(name) { + "delete": function(name) { name = NAMESPACE + name; return delete localStorage[name]; }, - getValue: function(name, defaultValue) { + get: function(name, defaultValue) { var value; name = NAMESPACE + name; if (value = localStorage[name]) { @@ -501,7 +501,7 @@ openInTab: function(url) { return window.open(url, "_blank"); }, - setValue: function(name, value) { + set: function(name, value) { name = NAMESPACE + name; return localStorage[name] = JSON.stringify(value); } @@ -509,7 +509,7 @@ } for (key in conf) { val = conf[key]; - conf[key] = $.getValue(key, val); + conf[key] = $.get(key, val); } $$ = function(selector, root) { if (root == null) { @@ -720,14 +720,14 @@ } id = reply.id; g.hiddenReplies[id] = Date.now(); - return $.setValue("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); }, show: function(table) { var id; $.show(table); id = $('td[id]', table).id; delete g.hiddenReplies[id]; - return $.setValue("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); } }; keybinds = { @@ -1056,7 +1056,7 @@ }, dialog: function() { var arr, checked, description, dialog, hiddenNum, hiddenThreads, hidingul, html, input, key, li, link, main, obj, overlay, ul, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; - hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; html = "

"; dialog = $.el('div', { @@ -1137,8 +1137,8 @@ return _results; }, clearHidden: function(e) { - $.deleteValue("hiddenReplies/" + g.BOARD + "/"); - $.deleteValue("hiddenThreads/" + g.BOARD + "/"); + $["delete"]("hiddenReplies/" + g.BOARD + "/"); + $["delete"]("hiddenThreads/" + g.BOARD + "/"); this.value = "hidden: 0"; return g.hiddenReplies = {}; }, @@ -1149,11 +1149,11 @@ return; } this.value = key; - $.setValue(this.name, key); + $.set(this.name, key); return conf[this.name] = key; }, time: function(e) { - $.setValue('time', this.value); + $.set('time', this.value); conf['time'] = this.value; Time.foo(); Time.date = new Date(); @@ -1165,11 +1165,11 @@ var match, time, _; if (match = location.search.match(/cooldown=(\d+)/)) { _ = match[0], time = match[1]; - if ($.getValue(g.BOARD + '/cooldown', 0) < time) { - $.setValue(g.BOARD + '/cooldown', time); + if ($.get(g.BOARD + '/cooldown', 0) < time) { + $.set(g.BOARD + '/cooldown', time); } } - if (Date.now() < $.getValue(g.BOARD + '/cooldown', 0)) { + if (Date.now() < $.get(g.BOARD + '/cooldown', 0)) { cooldown.start(); } $.bind(window, 'storage', function(e) { @@ -1181,7 +1181,7 @@ }, start: function() { var submit, _i, _len, _ref; - cooldown.duration = Math.ceil(($.getValue(g.BOARD + '/cooldown', 0) - Date.now()) / 1000); + cooldown.duration = Math.ceil(($.get(g.BOARD + '/cooldown', 0) - Date.now()) / 1000); _ref = $$('#com_submit'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { submit = _ref[_i]; @@ -1254,13 +1254,13 @@ */ var captcha, captchas, cutoff, responseField; cutoff = Date.now() - 5 * HOUR + 5 * MINUTE; - captchas = $.getValue('captchas', []); + captchas = $.get('captchas', []); while (captcha = captchas.shift()) { if (captcha.time > cutoff) { break; } } - $.setValue('captchas', captchas); + $.set('captchas', captchas); responseField = $('#recaptcha_response_field', qr.el); responseField.nextSibling.textContent = captchas.length + ' captchas'; if (!captcha) { @@ -1293,7 +1293,7 @@ if (conf['Auto Hide QR']) { $('#autohide', qr.el).checked = true; } - captcha = $.getValue('captcha', []); + captcha = $.get('captcha', []); l = captcha.push({ challenge: $('#recaptcha_challenge_field', qr.el).value, response: this.value, @@ -1314,7 +1314,7 @@ THREAD_ID = g.THREAD_ID || $.x('ancestor::div[@class="thread"]/div', link).id; spoiler = $('.postarea label') ? '' : ''; challenge = $('#recaptcha_challenge_field').value; - html = " X
Quick Reply
" + spoiler + "
" + ($.getValue('captcha', []).length) + " captcha cached
attach another file
"; + html = " X
Quick Reply
" + spoiler + "
" + ($.get('captcha', []).length) + " captcha cached
attach another file
"; qr.el = ui.dialog('qr', { top: '0px', left: '0px' @@ -1365,7 +1365,7 @@ } if (conf['Cooldown']) { duration = qr.sage ? 60 : 30; - $.setValue(g.BOARD + '/cooldown', Date.now() + duration * 1000); + $.set(g.BOARD + '/cooldown', Date.now() + duration * 1000); return cooldown.start(); } }, @@ -1542,7 +1542,7 @@ threadHiding = { init: function() { var a, hiddenThreads, op, thread, _i, _len, _ref, _results; - hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); _ref = $$('div.thread'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1580,9 +1580,9 @@ var hiddenThreads, id; threadHiding.hideHide(thread); id = thread.firstChild.id; - hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); hiddenThreads[id] = Date.now(); - return $.setValue("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); }, hideHide: function(thread) { var a, div, name, num, span, text, trip, _ref; @@ -1618,9 +1618,9 @@ $.show(thread); $.show(thread.nextSibling); id = thread.firstChild.id; - hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); delete hiddenThreads[id]; - return $.setValue("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); } }; updater = { @@ -1766,7 +1766,7 @@ } url = location.pathname + '?' + Date.now(); cb = updater.cb.update; - return updater.request = $.get(url, cb); + return updater.request = $.xhr(url, cb); } }; watcher = { @@ -1796,7 +1796,7 @@ }, refresh: function() { var board, div, favicon, id, link, props, watched, watchedBoard, x, _i, _j, _len, _len2, _ref, _ref2, _ref3, _results; - watched = $.getValue('watched', {}); + watched = $.get('watched', {}); _ref = $$('div:not(.move)', watcher.dialog); for (_i = 0, _len = _ref.length; _i < _len; _i++) { div = _ref[_i]; @@ -1848,9 +1848,9 @@ }, unwatch: function(board, id) { var watched; - watched = $.getValue('watched', {}); + watched = $.get('watched', {}); delete watched[board][id]; - $.setValue('watched', watched); + $.set('watched', watched); return watcher.refresh(); }, watch: function(thread, id) { @@ -1860,10 +1860,10 @@ textContent: "/" + g.BOARD + "/ - " + tc.slice(0, 25), href: "/" + g.BOARD + "/res/" + id }; - watched = $.getValue('watched', {}); + watched = $.get('watched', {}); watched[_name = g.BOARD] || (watched[_name] = {}); watched[g.BOARD][id] = props; - $.setValue('watched', watched); + $.set('watched', watched); return watcher.refresh(); } }; @@ -2658,7 +2658,7 @@ id: 'imgControls', innerHTML: " " }); - imageType = $.getValue('imageType', 'full'); + imageType = $.get('imageType', 'full'); _ref2 = $$('option', controls); for (_i = 0, _len = _ref2.length; _i < _len; _i++) { option = _ref2[_i]; @@ -2693,7 +2693,7 @@ return $.bind(window, 'click', firstRun.close); }, close: function() { - $.setValue('firstrun', true); + $.set('firstrun', true); $.rm($('style.firstrun', d.head)); $.rm($('#overlay')); return $.unbind(window, 'click', firstRun.close); @@ -2723,17 +2723,17 @@ } Favicon.halo = /ws/.test(Favicon["default"]) ? Favicon.haloSFW : Favicon.haloNSFW; $('link[rel="shortcut icon"]', d.head).setAttribute('type', 'image/x-icon'); - g.hiddenReplies = $.getValue("hiddenReplies/" + g.BOARD + "/", {}); + g.hiddenReplies = $.get("hiddenReplies/" + g.BOARD + "/", {}); tzOffset = (new Date()).getTimezoneOffset() / 60; g.chanOffset = 5 - tzOffset; if ($.isDST()) { g.chanOffset -= 1; } - lastChecked = $.getValue('lastChecked', 0); + lastChecked = $.get('lastChecked', 0); now = Date.now(); if (lastChecked < now - 1 * DAY) { cutoff = now - 7 * DAY; - hiddenThreads = $.getValue("hiddenThreads/" + g.BOARD + "/", {}); + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); for (id in hiddenThreads) { timestamp = hiddenThreads[id]; if (timestamp < cutoff) { @@ -2747,9 +2747,9 @@ delete g.hiddenReplies[id]; } } - $.setValue("hiddenThreads/" + g.BOARD + "/", hiddenThreads); - $.setValue("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); - $.setValue('lastChecked', now); + $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); + $.set('lastChecked', now); } $.addStyle(main.css); if ((form = $('form[name=post]')) && (canPost = !!$('#recaptcha_response_field'))) { @@ -2879,7 +2879,7 @@ } $.bind($('form[name=delform]'), 'DOMNodeInserted', nodeInserted); options.init(); - if (!$.getValue('firstrun')) { + if (!$.get('firstrun')) { return firstRun.init(); } }, diff --git a/script.coffee b/script.coffee index aa5c57906..578a37640 100644 --- a/script.coffee +++ b/script.coffee @@ -213,7 +213,7 @@ $.extend $, textContent: "(#{code})()" $.append d.head, script $.rm script - get: (url, cb) -> + xhr: (url, cb) -> r = new XMLHttpRequest() r.onload = cb r.open 'get', url, true @@ -226,14 +226,14 @@ $.extend $, else req.callbacks.push cb else - req = $.get url, (-> cb.call @ for cb in @callbacks) + req = $.xhr url, (-> cb.call @ for cb in @callbacks) req.callbacks = [cb] $.cache.requests[url] = req cb: checked: -> - $.setValue @name, @checked + $.set @name, @checked value: -> - $.setValue @name, @value + $.set @name, @value addStyle: (css) -> style = $.el 'style', textContent: css @@ -327,10 +327,10 @@ $.cache.requests = {} if GM_deleteValue? $.extend $, - deleteValue: (name) -> + delete: (name) -> name = NAMESPACE + name GM_deleteValue name - getValue: (name, defaultValue) -> + get: (name, defaultValue) -> name = NAMESPACE + name if value = GM_getValue name JSON.parse value @@ -338,17 +338,17 @@ if GM_deleteValue? defaultValue openInTab: (url) -> GM_openInTab url - setValue: (name, value) -> + set: (name, value) -> name = NAMESPACE + name # for `storage` events localStorage[name] = JSON.stringify value GM_setValue name, JSON.stringify value else $.extend $, - deleteValue: (name) -> + delete: (name) -> name = NAMESPACE + name delete localStorage[name] - getValue: (name, defaultValue) -> + get: (name, defaultValue) -> name = NAMESPACE + name if value = localStorage[name] JSON.parse value @@ -356,13 +356,13 @@ else defaultValue openInTab: (url) -> window.open url, "_blank" - setValue: (name, value) -> + set: (name, value) -> name = NAMESPACE + name localStorage[name] = JSON.stringify value #load values from localStorage for key, val of conf - conf[key] = $.getValue key, val + conf[key] = $.get key, val $$ = (selector, root=d.body) -> Array::slice.call root.querySelectorAll selector @@ -514,14 +514,14 @@ replyHiding = id = reply.id g.hiddenReplies[id] = Date.now() - $.setValue "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies show: (table) -> $.show table id = $('td[id]', table).id delete g.hiddenReplies[id] - $.setValue "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies keybinds = init: -> @@ -773,7 +773,7 @@ options = $.replace home, a dialog: -> - hiddenThreads = $.getValue "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length html = "
@@ -907,8 +907,8 @@ options = clearHidden: (e) -> #'hidden' might be misleading; it's the number of IDs we're *looking* for, # not the number of posts actually hidden on the page. - $.deleteValue "hiddenReplies/#{g.BOARD}/" - $.deleteValue "hiddenThreads/#{g.BOARD}/" + $.delete "hiddenReplies/#{g.BOARD}/" + $.delete "hiddenThreads/#{g.BOARD}/" @value = "hidden: 0" g.hiddenReplies = {} keybind: (e) -> @@ -916,10 +916,10 @@ options = e.stopPropagation() return unless (key = keybinds.keyCode e)? @value = key - $.setValue @name, key + $.set @name, key conf[@name] = key time: (e) -> - $.setValue 'time', @value + $.set 'time', @value conf['time'] = @value Time.foo() Time.date = new Date() @@ -929,13 +929,13 @@ cooldown = init: -> if match = location.search.match /cooldown=(\d+)/ [_, time] = match - $.setValue g.BOARD+'/cooldown', time if $.getValue(g.BOARD+'/cooldown', 0) < time - cooldown.start() if Date.now() < $.getValue g.BOARD+'/cooldown', 0 + $.set g.BOARD+'/cooldown', time if $.get(g.BOARD+'/cooldown', 0) < time + cooldown.start() if Date.now() < $.get g.BOARD+'/cooldown', 0 $.bind window, 'storage', (e) -> cooldown.start() if e.key is "#{NAMESPACE}#{g.BOARD}/cooldown" $('.postarea form').action += '?cooldown' start: -> - cooldown.duration = Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000 + cooldown.duration = Math.ceil ($.get(g.BOARD+'/cooldown', 0) - Date.now()) / 1000 for submit in $$ '#com_submit' submit.value = cooldown.duration submit.disabled = true @@ -994,13 +994,13 @@ qr = ### cutoff = Date.now() - 5*HOUR + 5*MINUTE - captchas = $.getValue 'captchas', [] + captchas = $.get 'captchas', [] while captcha = captchas.shift() if captcha.time > cutoff break - $.setValue 'captchas', captchas + $.set 'captchas', captchas responseField = $ '#recaptcha_response_field', qr.el responseField.nextSibling.textContent = captchas.length + ' captchas' @@ -1026,7 +1026,7 @@ qr = $('#auto', qr.el).checked = true $('#autohide', qr.el).checked = true if conf['Auto Hide QR'] - captcha = $.getValue 'captcha', [] + captcha = $.get 'captcha', [] l = captcha.push challenge: $('#recaptcha_challenge_field', qr.el).value response: @value @@ -1060,7 +1060,7 @@ qr =
-
#{$.getValue('captcha', []).length} captcha cached
+
#{$.get('captcha', []).length} captcha cached
attach another file
@@ -1111,7 +1111,7 @@ qr = qr.close() if conf['Cooldown'] duration = if qr.sage then 60 else 30 - $.setValue g.BOARD+'/cooldown', Date.now() + duration * 1000 + $.set g.BOARD+'/cooldown', Date.now() + duration * 1000 cooldown.start() node: (root) -> @@ -1259,7 +1259,7 @@ threading = threadHiding = init: -> - hiddenThreads = $.getValue "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} for thread in $$ 'div.thread' op = thread.firstChild a = $.el 'a', @@ -1289,9 +1289,9 @@ threadHiding = id = thread.firstChild.id - hiddenThreads = $.getValue "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} hiddenThreads[id] = Date.now() - $.setValue "hiddenThreads/#{g.BOARD}/", hiddenThreads + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads hideHide: (thread) -> if conf['Show Stubs'] @@ -1326,9 +1326,9 @@ threadHiding = id = thread.firstChild.id - hiddenThreads = $.getValue "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} delete hiddenThreads[id] - $.setValue "hiddenThreads/#{g.BOARD}/", hiddenThreads + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads updater = init: -> @@ -1448,7 +1448,7 @@ updater = updater.request?.abort() url = location.pathname + '?' + Date.now() # fool the cache cb = updater.cb.update - updater.request = $.get url, cb + updater.request = $.xhr url, cb watcher = init: -> @@ -1470,7 +1470,7 @@ watcher = $.bind window, 'storage', (e) -> watcher.refresh() if e.key is "#{NAMESPACE}watched" refresh: -> - watched = $.getValue 'watched', {} + watched = $.get 'watched', {} for div in $$ 'div:not(.move)', watcher.dialog $.rm div for board of watched @@ -1509,9 +1509,9 @@ watcher = watcher.unwatch g.BOARD, id unwatch: (board, id) -> - watched = $.getValue 'watched', {} + watched = $.get 'watched', {} delete watched[board][id] - $.setValue 'watched', watched + $.set 'watched', watched watcher.refresh() watch: (thread, id) -> @@ -1520,10 +1520,10 @@ watcher = textContent: "/#{g.BOARD}/ - #{tc[...25]}" href: "/#{g.BOARD}/res/#{id}" - watched = $.getValue 'watched', {} + watched = $.get 'watched', {} watched[g.BOARD] or= {} watched[g.BOARD][id] = props - $.setValue 'watched', watched + $.set 'watched', watched watcher.refresh() anonymize = @@ -2012,7 +2012,7 @@ imgExpand = innerHTML: " " - imageType = $.getValue 'imageType', 'full' + imageType = $.get 'imageType', 'full' for option in $$ 'option', controls if option.textContent is imageType option.selected = true @@ -2104,7 +2104,7 @@ firstRun = $.bind window, 'click', firstRun.close close: -> - $.setValue 'firstrun', true + $.set 'firstrun', true $.rm $ 'style.firstrun', d.head $.rm $ '#overlay' $.unbind window, 'click', firstRun.close @@ -2130,17 +2130,17 @@ main = Favicon.halo = if /ws/.test Favicon.default then Favicon.haloSFW else Favicon.haloNSFW $('link[rel="shortcut icon"]', d.head).setAttribute 'type', 'image/x-icon' - g.hiddenReplies = $.getValue "hiddenReplies/#{g.BOARD}/", {} + g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} tzOffset = (new Date()).getTimezoneOffset() / 60 # GMT -8 is given as +480; would GMT +8 be -480 ? g.chanOffset = 5 - tzOffset# 4chan = EST = GMT -5 if $.isDST() then g.chanOffset -= 1 - lastChecked = $.getValue 'lastChecked', 0 + lastChecked = $.get 'lastChecked', 0 now = Date.now() if lastChecked < now - 1*DAY cutoff = now - 7*DAY - hiddenThreads = $.getValue "hiddenThreads/#{g.BOARD}/", {} + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} for id, timestamp of hiddenThreads if timestamp < cutoff @@ -2150,9 +2150,9 @@ main = if timestamp < cutoff delete g.hiddenReplies[id] - $.setValue "hiddenThreads/#{g.BOARD}/", hiddenThreads - $.setValue "hiddenReplies/#{g.BOARD}/", g.hiddenReplies - $.setValue 'lastChecked', now + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads + $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies + $.set 'lastChecked', now $.addStyle main.css @@ -2276,7 +2276,7 @@ main = $.bind $('form[name=delform]'), 'DOMNodeInserted', nodeInserted options.init() - unless $.getValue 'firstrun' + unless $.get 'firstrun' firstRun.init() css: '