Don't polute the localStorage too much.
This commit is contained in:
parent
2660ccb89a
commit
7f4070ec37
@ -20,7 +20,7 @@
|
||||
// @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7
|
||||
// ==/UserScript==
|
||||
|
||||
/* 4chan X Beta - Version 3.0.0 - 2013-03-10
|
||||
/* 4chan X Beta - Version 3.0.0 - 2013-03-11
|
||||
* http://mayhemydg.github.com/4chan-x/
|
||||
*
|
||||
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
|
||||
@ -1976,15 +1976,9 @@
|
||||
return $.prepend(this.OP.nodes.root, ThreadHiding.makeButton(this, 'hide'));
|
||||
},
|
||||
getHiddenThreads: function() {
|
||||
var hiddenThreads;
|
||||
hiddenThreads = $.get("hiddenThreads." + g.BOARD);
|
||||
if (!hiddenThreads) {
|
||||
hiddenThreads = {
|
||||
threads: {}
|
||||
};
|
||||
$.set("hiddenThreads." + g.BOARD, hiddenThreads);
|
||||
}
|
||||
return ThreadHiding.hiddenThreads = hiddenThreads;
|
||||
return ThreadHiding.hiddenThreads = $.get("hiddenThreads." + g.BOARD, {
|
||||
threads: {}
|
||||
});
|
||||
},
|
||||
syncFromCatalog: function() {
|
||||
var hiddenThreadsOnCatalog, threadID, threads;
|
||||
@ -2002,7 +1996,11 @@
|
||||
}
|
||||
delete threads[threadID];
|
||||
}
|
||||
return $.set("hiddenThreads." + g.BOARD, ThreadHiding.hiddenThreads);
|
||||
if (Object.keys(threads).length) {
|
||||
return $.set("hiddenThreads." + g.BOARD, ThreadHiding.hiddenThreads);
|
||||
} else {
|
||||
return $["delete"]("hiddenThreads." + g.BOARD);
|
||||
}
|
||||
},
|
||||
menu: {
|
||||
init: function() {
|
||||
@ -2168,15 +2166,9 @@
|
||||
return $.replace($('.sideArrows', this.nodes.root), ReplyHiding.makeButton(this, 'hide'));
|
||||
},
|
||||
getHiddenPosts: function() {
|
||||
var hiddenPosts;
|
||||
hiddenPosts = $.get("hiddenPosts." + g.BOARD);
|
||||
if (!hiddenPosts) {
|
||||
hiddenPosts = {
|
||||
threads: {}
|
||||
};
|
||||
$.set("hiddenPosts." + g.BOARD, hiddenPosts);
|
||||
}
|
||||
return ReplyHiding.hiddenPosts = hiddenPosts;
|
||||
return ReplyHiding.hiddenPosts = $.get("hiddenPosts." + g.BOARD, {
|
||||
threads: {}
|
||||
});
|
||||
},
|
||||
menu: {
|
||||
init: function() {
|
||||
@ -3691,22 +3683,15 @@
|
||||
|
||||
Misc = {
|
||||
clearThreads: function(key) {
|
||||
var data, now;
|
||||
now = Date.now();
|
||||
data = $.get(key, {
|
||||
threads: {}
|
||||
});
|
||||
if (!data.lastChecked) {
|
||||
data.lastChecked = now;
|
||||
$.set(key, data);
|
||||
var data;
|
||||
if (!(data = $.get(key))) {
|
||||
return;
|
||||
}
|
||||
if (data.lastChecked > now - $.DAY) {
|
||||
return;
|
||||
}
|
||||
data.lastChecked = now;
|
||||
if (!Object.keys(data.threads).length) {
|
||||
$.set(key, data);
|
||||
$["delete"](key);
|
||||
return;
|
||||
}
|
||||
if (data.lastChecked > Date.now() - 12 * $.HOUR) {
|
||||
return;
|
||||
}
|
||||
return $.ajax("//api.4chan.org/" + g.BOARD + "/catalog.json", {
|
||||
@ -3724,7 +3709,12 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Object.keys(threads).length) {
|
||||
$["delete"](key);
|
||||
return;
|
||||
}
|
||||
data.threads = threads;
|
||||
data.lastChecked = Date.now();
|
||||
return $.set(key, data);
|
||||
}
|
||||
});
|
||||
@ -5841,6 +5831,9 @@
|
||||
var watched;
|
||||
watched = $.get('WatchedThreads', {});
|
||||
delete watched[board][threadID];
|
||||
if (!Object.keys(watched[board]).length) {
|
||||
delete watched[board];
|
||||
}
|
||||
ThreadWatcher.refresh(watched);
|
||||
return $.set('WatchedThreads', watched);
|
||||
},
|
||||
@ -6097,7 +6090,11 @@
|
||||
},
|
||||
unset: function(id) {
|
||||
delete QR.cooldown.cooldowns[id];
|
||||
return $.set("cooldown." + g.BOARD, QR.cooldown.cooldowns);
|
||||
if (Object.keys(QR.cooldown.cooldowns).length) {
|
||||
return $.set("cooldown." + g.BOARD, QR.cooldown.cooldowns);
|
||||
} else {
|
||||
return $["delete"]("cooldown." + g.BOARD);
|
||||
}
|
||||
},
|
||||
count: function() {
|
||||
var cooldown, cooldowns, elapsed, hasFile, isReply, isSage, now, post, seconds, start, type, types, upSpd, upSpdAccuracy, update, _ref;
|
||||
|
||||
@ -927,11 +927,7 @@ ThreadHiding =
|
||||
$.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide'
|
||||
|
||||
getHiddenThreads: ->
|
||||
hiddenThreads = $.get "hiddenThreads.#{g.BOARD}"
|
||||
unless hiddenThreads
|
||||
hiddenThreads = threads: {}
|
||||
$.set "hiddenThreads.#{g.BOARD}", hiddenThreads
|
||||
ThreadHiding.hiddenThreads = hiddenThreads
|
||||
ThreadHiding.hiddenThreads = $.get "hiddenThreads.#{g.BOARD}", threads: {}
|
||||
|
||||
syncFromCatalog: ->
|
||||
# Sync hidden threads from the catalog into the index.
|
||||
@ -948,7 +944,10 @@ ThreadHiding =
|
||||
continue if threadID of threads
|
||||
delete threads[threadID]
|
||||
|
||||
$.set "hiddenThreads.#{g.BOARD}", ThreadHiding.hiddenThreads
|
||||
if Object.keys(threads).length
|
||||
$.set "hiddenThreads.#{g.BOARD}", ThreadHiding.hiddenThreads
|
||||
else
|
||||
$.delete "hiddenThreads.#{g.BOARD}"
|
||||
|
||||
menu:
|
||||
init: ->
|
||||
@ -1075,11 +1074,7 @@ ReplyHiding =
|
||||
$.replace $('.sideArrows', @nodes.root), ReplyHiding.makeButton @, 'hide'
|
||||
|
||||
getHiddenPosts: ->
|
||||
hiddenPosts = $.get "hiddenPosts.#{g.BOARD}"
|
||||
unless hiddenPosts
|
||||
hiddenPosts = threads: {}
|
||||
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
|
||||
ReplyHiding.hiddenPosts = hiddenPosts
|
||||
ReplyHiding.hiddenPosts = $.get "hiddenPosts.#{g.BOARD}", threads: {}
|
||||
|
||||
menu:
|
||||
init: ->
|
||||
@ -2364,29 +2359,25 @@ Get =
|
||||
|
||||
Misc = # super semantic
|
||||
clearThreads: (key) ->
|
||||
now = Date.now()
|
||||
data = $.get key, threads: {}
|
||||
|
||||
unless data.lastChecked
|
||||
data.lastChecked = now
|
||||
$.set key, data
|
||||
return
|
||||
|
||||
return if data.lastChecked > now - $.DAY
|
||||
|
||||
data.lastChecked = now
|
||||
return unless data = $.get key
|
||||
|
||||
unless Object.keys(data.threads).length
|
||||
$.set key, data
|
||||
$.delete key
|
||||
return
|
||||
|
||||
return if data.lastChecked > Date.now() - 12 * $.HOUR
|
||||
|
||||
$.ajax "//api.4chan.org/#{g.BOARD}/catalog.json", onload: ->
|
||||
threads = {}
|
||||
for obj in JSON.parse @response
|
||||
for thread in obj.threads
|
||||
if thread.no of data.threads
|
||||
threads[thread.no] = data.threads[thread.no]
|
||||
data.threads = threads
|
||||
unless Object.keys(threads).length
|
||||
$.delete key
|
||||
return
|
||||
data.threads = threads
|
||||
data.lastChecked = Date.now()
|
||||
$.set key, data
|
||||
|
||||
Quotify =
|
||||
@ -4012,6 +4003,7 @@ ThreadWatcher =
|
||||
unwatch: (board, threadID) ->
|
||||
watched = $.get 'WatchedThreads', {}
|
||||
delete watched[board][threadID]
|
||||
delete watched[board] unless Object.keys(watched[board]).length
|
||||
ThreadWatcher.refresh watched
|
||||
$.set 'WatchedThreads', watched
|
||||
|
||||
|
||||
@ -192,7 +192,10 @@ QR =
|
||||
QR.cooldown.start()
|
||||
unset: (id) ->
|
||||
delete QR.cooldown.cooldowns[id]
|
||||
$.set "cooldown.#{g.BOARD}", QR.cooldown.cooldowns
|
||||
if Object.keys(QR.cooldown.cooldowns).length
|
||||
$.set "cooldown.#{g.BOARD}", QR.cooldown.cooldowns
|
||||
else
|
||||
$.delete "cooldown.#{g.BOARD}"
|
||||
count: ->
|
||||
unless Object.keys(QR.cooldown.cooldowns).length
|
||||
$.delete "#{g.BOARD}.cooldown"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user