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