Add Misc.clearThreads, remove redundant code.
This commit is contained in:
parent
09854dd3aa
commit
a7d89fbd88
119
4chan_x.user.js
119
4chan_x.user.js
@ -43,7 +43,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g,
|
var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Misc, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g,
|
||||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
||||||
__hasProp = {}.hasOwnProperty,
|
__hasProp = {}.hasOwnProperty,
|
||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||||
@ -1897,9 +1897,9 @@
|
|||||||
if (g.VIEW !== 'index' || !Conf['Thread Hiding']) {
|
if (g.VIEW !== 'index' || !Conf['Thread Hiding']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Misc.clearThreads("hiddenThreads." + g.BOARD);
|
||||||
this.getHiddenThreads();
|
this.getHiddenThreads();
|
||||||
this.syncFromCatalog();
|
this.syncFromCatalog();
|
||||||
this.clean();
|
|
||||||
return Thread.prototype.callbacks.push({
|
return Thread.prototype.callbacks.push({
|
||||||
name: 'Thread Hiding',
|
name: 'Thread Hiding',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
@ -1920,8 +1920,7 @@
|
|||||||
hiddenThreads = $.get("hiddenThreads." + g.BOARD);
|
hiddenThreads = $.get("hiddenThreads." + g.BOARD);
|
||||||
if (!hiddenThreads) {
|
if (!hiddenThreads) {
|
||||||
hiddenThreads = {
|
hiddenThreads = {
|
||||||
threads: {},
|
threads: {}
|
||||||
lastChecked: Date.now()
|
|
||||||
};
|
};
|
||||||
$.set("hiddenThreads." + g.BOARD, hiddenThreads);
|
$.set("hiddenThreads." + g.BOARD, hiddenThreads);
|
||||||
}
|
}
|
||||||
@ -1945,38 +1944,6 @@
|
|||||||
}
|
}
|
||||||
return $.set("hiddenThreads." + g.BOARD, ThreadHiding.hiddenThreads);
|
return $.set("hiddenThreads." + g.BOARD, ThreadHiding.hiddenThreads);
|
||||||
},
|
},
|
||||||
clean: function() {
|
|
||||||
var hiddenThreads, lastChecked, now;
|
|
||||||
hiddenThreads = ThreadHiding.hiddenThreads;
|
|
||||||
lastChecked = hiddenThreads.lastChecked;
|
|
||||||
hiddenThreads.lastChecked = now = Date.now();
|
|
||||||
if (lastChecked > now - $.DAY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Object.keys(hiddenThreads.threads).length) {
|
|
||||||
$.set("hiddenThreads." + g.BOARD, hiddenThreads);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return $.ajax("//api.4chan.org/" + g.BOARD + "/catalog.json", {
|
|
||||||
onload: function() {
|
|
||||||
var obj, thread, threads, _i, _j, _len, _len1, _ref, _ref1;
|
|
||||||
threads = {};
|
|
||||||
_ref = JSON.parse(this.response);
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
obj = _ref[_i];
|
|
||||||
_ref1 = obj.threads;
|
|
||||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
||||||
thread = _ref1[_j];
|
|
||||||
if (thread.no in hiddenThreads.threads) {
|
|
||||||
threads[thread.no] = hiddenThreads.threads[thread.no];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hiddenThreads.threads = threads;
|
|
||||||
return $.set("hiddenThreads." + g.BOARD, hiddenThreads);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
menu: {
|
menu: {
|
||||||
init: function() {
|
init: function() {
|
||||||
var apply, div, makeStub;
|
var apply, div, makeStub;
|
||||||
@ -2111,8 +2078,8 @@
|
|||||||
if (g.VIEW === 'catalog' || !Conf['Reply Hiding']) {
|
if (g.VIEW === 'catalog' || !Conf['Reply Hiding']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Misc.clearThreads("hiddenPosts." + g.BOARD);
|
||||||
this.getHiddenPosts();
|
this.getHiddenPosts();
|
||||||
this.clean();
|
|
||||||
return Post.prototype.callbacks.push({
|
return Post.prototype.callbacks.push({
|
||||||
name: 'Reply Hiding',
|
name: 'Reply Hiding',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
@ -2142,45 +2109,12 @@
|
|||||||
hiddenPosts = $.get("hiddenPosts." + g.BOARD);
|
hiddenPosts = $.get("hiddenPosts." + g.BOARD);
|
||||||
if (!hiddenPosts) {
|
if (!hiddenPosts) {
|
||||||
hiddenPosts = {
|
hiddenPosts = {
|
||||||
threads: {},
|
threads: {}
|
||||||
lastChecked: Date.now()
|
|
||||||
};
|
};
|
||||||
$.set("hiddenPosts." + g.BOARD, hiddenPosts);
|
$.set("hiddenPosts." + g.BOARD, hiddenPosts);
|
||||||
}
|
}
|
||||||
return ReplyHiding.hiddenPosts = hiddenPosts;
|
return ReplyHiding.hiddenPosts = hiddenPosts;
|
||||||
},
|
},
|
||||||
clean: function() {
|
|
||||||
var hiddenPosts, lastChecked, now;
|
|
||||||
hiddenPosts = ReplyHiding.hiddenPosts;
|
|
||||||
lastChecked = hiddenPosts.lastChecked;
|
|
||||||
hiddenPosts.lastChecked = now = Date.now();
|
|
||||||
if (lastChecked > now - $.DAY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Object.keys(hiddenPosts.threads).length) {
|
|
||||||
$.set("hiddenPosts." + g.BOARD, hiddenPosts);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return $.ajax("//api.4chan.org/" + g.BOARD + "/catalog.json", {
|
|
||||||
onload: function() {
|
|
||||||
var obj, thread, threads, _i, _j, _len, _len1, _ref, _ref1;
|
|
||||||
threads = {};
|
|
||||||
_ref = JSON.parse(this.response);
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
obj = _ref[_i];
|
|
||||||
_ref1 = obj.threads;
|
|
||||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
||||||
thread = _ref1[_j];
|
|
||||||
if (thread.no in hiddenPosts.threads) {
|
|
||||||
threads[thread.no] = hiddenPosts.threads[thread.no];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hiddenPosts.threads = threads;
|
|
||||||
return $.set("hiddenPosts." + g.BOARD, hiddenPosts);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
menu: {
|
menu: {
|
||||||
init: function() {
|
init: function() {
|
||||||
var apply, div, makeStub, replies, thisPost;
|
var apply, div, makeStub, replies, thisPost;
|
||||||
@ -3582,6 +3516,48 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Misc = {
|
||||||
|
clearThreads: function(key) {
|
||||||
|
var data, now;
|
||||||
|
now = Date.now();
|
||||||
|
data = $.get(key, {
|
||||||
|
threads: {}
|
||||||
|
});
|
||||||
|
if (!data.lastChecked) {
|
||||||
|
data.lastChecked = now;
|
||||||
|
$.set(key, data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.lastChecked > now - $.DAY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data.lastChecked = now;
|
||||||
|
if (!Object.keys(data.threads).length) {
|
||||||
|
$.set(key, data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return $.ajax("//api.4chan.org/" + g.BOARD + "/catalog.json", {
|
||||||
|
onload: function() {
|
||||||
|
var obj, thread, threads, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
|
threads = {};
|
||||||
|
_ref = JSON.parse(this.response);
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
obj = _ref[_i];
|
||||||
|
_ref1 = obj.threads;
|
||||||
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
|
thread = _ref1[_j];
|
||||||
|
if (thread.no in data.threads) {
|
||||||
|
threads[thread.no] = data.threads[thread.no];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.threads = threads;
|
||||||
|
return $.set(key, data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Quotify = {
|
Quotify = {
|
||||||
init: function() {
|
init: function() {
|
||||||
if (g.VIEW === 'catalog' || !Conf['Resurrect Quotes']) {
|
if (g.VIEW === 'catalog' || !Conf['Resurrect Quotes']) {
|
||||||
@ -4939,6 +4915,7 @@
|
|||||||
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Tab Icon']) {
|
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Tab Icon']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Misc.clearThreads("lastReadPosts." + g.BOARD);
|
||||||
return Thread.prototype.callbacks.push({
|
return Thread.prototype.callbacks.push({
|
||||||
name: 'Unread',
|
name: 'Unread',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
|
|||||||
@ -878,9 +878,9 @@ ThreadHiding =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'index' or !Conf['Thread Hiding']
|
return if g.VIEW isnt 'index' or !Conf['Thread Hiding']
|
||||||
|
|
||||||
|
Misc.clearThreads "hiddenThreads.#{g.BOARD}"
|
||||||
@getHiddenThreads()
|
@getHiddenThreads()
|
||||||
@syncFromCatalog()
|
@syncFromCatalog()
|
||||||
@clean()
|
|
||||||
Thread::callbacks.push
|
Thread::callbacks.push
|
||||||
name: 'Thread Hiding'
|
name: 'Thread Hiding'
|
||||||
cb: @node
|
cb: @node
|
||||||
@ -894,9 +894,7 @@ ThreadHiding =
|
|||||||
getHiddenThreads: ->
|
getHiddenThreads: ->
|
||||||
hiddenThreads = $.get "hiddenThreads.#{g.BOARD}"
|
hiddenThreads = $.get "hiddenThreads.#{g.BOARD}"
|
||||||
unless hiddenThreads
|
unless hiddenThreads
|
||||||
hiddenThreads =
|
hiddenThreads = threads: {}
|
||||||
threads: {}
|
|
||||||
lastChecked: Date.now()
|
|
||||||
$.set "hiddenThreads.#{g.BOARD}", hiddenThreads
|
$.set "hiddenThreads.#{g.BOARD}", hiddenThreads
|
||||||
ThreadHiding.hiddenThreads = hiddenThreads
|
ThreadHiding.hiddenThreads = hiddenThreads
|
||||||
|
|
||||||
@ -917,26 +915,6 @@ ThreadHiding =
|
|||||||
|
|
||||||
$.set "hiddenThreads.#{g.BOARD}", ThreadHiding.hiddenThreads
|
$.set "hiddenThreads.#{g.BOARD}", ThreadHiding.hiddenThreads
|
||||||
|
|
||||||
clean: ->
|
|
||||||
{hiddenThreads} = ThreadHiding
|
|
||||||
{lastChecked} = hiddenThreads
|
|
||||||
hiddenThreads.lastChecked = now = Date.now()
|
|
||||||
|
|
||||||
return if lastChecked > now - $.DAY
|
|
||||||
|
|
||||||
unless Object.keys(hiddenThreads.threads).length
|
|
||||||
$.set "hiddenThreads.#{g.BOARD}", hiddenThreads
|
|
||||||
return
|
|
||||||
|
|
||||||
$.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 hiddenThreads.threads
|
|
||||||
threads[thread.no] = hiddenThreads.threads[thread.no]
|
|
||||||
hiddenThreads.threads = threads
|
|
||||||
$.set "hiddenThreads.#{g.BOARD}", hiddenThreads
|
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding']
|
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding']
|
||||||
@ -1040,8 +1018,8 @@ ReplyHiding =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW is 'catalog' or !Conf['Reply Hiding']
|
return if g.VIEW is 'catalog' or !Conf['Reply Hiding']
|
||||||
|
|
||||||
|
Misc.clearThreads "hiddenPosts.#{g.BOARD}"
|
||||||
@getHiddenPosts()
|
@getHiddenPosts()
|
||||||
@clean()
|
|
||||||
Post::callbacks.push
|
Post::callbacks.push
|
||||||
name: 'Reply Hiding'
|
name: 'Reply Hiding'
|
||||||
cb: @node
|
cb: @node
|
||||||
@ -1060,32 +1038,10 @@ ReplyHiding =
|
|||||||
getHiddenPosts: ->
|
getHiddenPosts: ->
|
||||||
hiddenPosts = $.get "hiddenPosts.#{g.BOARD}"
|
hiddenPosts = $.get "hiddenPosts.#{g.BOARD}"
|
||||||
unless hiddenPosts
|
unless hiddenPosts
|
||||||
hiddenPosts =
|
hiddenPosts = threads: {}
|
||||||
threads: {}
|
|
||||||
lastChecked: Date.now()
|
|
||||||
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
|
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
|
||||||
ReplyHiding.hiddenPosts = hiddenPosts
|
ReplyHiding.hiddenPosts = hiddenPosts
|
||||||
|
|
||||||
clean: ->
|
|
||||||
{hiddenPosts} = ReplyHiding
|
|
||||||
{lastChecked} = hiddenPosts
|
|
||||||
hiddenPosts.lastChecked = now = Date.now()
|
|
||||||
|
|
||||||
return if lastChecked > now - $.DAY
|
|
||||||
|
|
||||||
unless Object.keys(hiddenPosts.threads).length
|
|
||||||
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
|
|
||||||
return
|
|
||||||
|
|
||||||
$.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 hiddenPosts.threads
|
|
||||||
threads[thread.no] = hiddenPosts.threads[thread.no]
|
|
||||||
hiddenPosts.threads = threads
|
|
||||||
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
|
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW is 'catalog' or !Conf['Menu'] or !Conf['Reply Hiding']
|
return if g.VIEW is 'catalog' or !Conf['Menu'] or !Conf['Reply Hiding']
|
||||||
@ -2285,6 +2241,33 @@ Get =
|
|||||||
Main.callbackNodes Post, [post]
|
Main.callbackNodes Post, [post]
|
||||||
Get.insert post, root, context
|
Get.insert post, root, context
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
unless Object.keys(data.threads).length
|
||||||
|
$.set key, data
|
||||||
|
return
|
||||||
|
|
||||||
|
$.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
|
||||||
|
$.set key, data
|
||||||
|
|
||||||
Quotify =
|
Quotify =
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW is 'catalog' or !Conf['Resurrect Quotes']
|
return if g.VIEW is 'catalog' or !Conf['Resurrect Quotes']
|
||||||
@ -3288,6 +3271,7 @@ Unread =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Tab Icon']
|
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Tab Icon']
|
||||||
|
|
||||||
|
Misc.clearThreads "lastReadPosts.#{g.BOARD}"
|
||||||
Thread::callbacks.push
|
Thread::callbacks.push
|
||||||
name: 'Unread'
|
name: 'Unread'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user