Start catalog support. Close #834.
This commit is contained in:
parent
fdaee4641e
commit
65b1e168b3
@ -318,8 +318,9 @@
|
|||||||
return $.on(d, 'DOMContentLoaded', cb);
|
return $.on(d, 'DOMContentLoaded', cb);
|
||||||
},
|
},
|
||||||
sync: function(key, cb) {
|
sync: function(key, cb) {
|
||||||
|
key = Main.namespace + key;
|
||||||
return $.on(window, 'storage', function(e) {
|
return $.on(window, 'storage', function(e) {
|
||||||
if (e.key === ("" + Main.namespace + key)) {
|
if (e.key === key) {
|
||||||
return cb(JSON.parse(e.newValue));
|
return cb(JSON.parse(e.newValue));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1042,7 +1043,10 @@
|
|||||||
ThreadHiding = {
|
ThreadHiding = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var a, hiddenThreads, thread, _i, _len, _ref;
|
var a, hiddenThreads, thread, _i, _len, _ref;
|
||||||
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
|
hiddenThreads = ThreadHiding.sync();
|
||||||
|
if (g.CATALOG) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_ref = $$('.thread');
|
_ref = $$('.thread');
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
thread = _ref[_i];
|
thread = _ref[_i];
|
||||||
@ -1058,6 +1062,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
sync: function() {
|
||||||
|
var hiddenThreads, hiddenThreadsCatalog, id;
|
||||||
|
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
|
||||||
|
hiddenThreadsCatalog = JSON.parse(localStorage.getItem("4chan-hide-t-" + g.BOARD));
|
||||||
|
if (g.CATALOG) {
|
||||||
|
for (id in hiddenThreads) {
|
||||||
|
hiddenThreadsCatalog[id] = true;
|
||||||
|
}
|
||||||
|
localStorage.setItem("4chan-hide-t-" + g.BOARD, JSON.stringify(hiddenThreadsCatalog));
|
||||||
|
} else {
|
||||||
|
for (id in hiddenThreadsCatalog) {
|
||||||
|
if (!(id in hiddenThreads)) {
|
||||||
|
hiddenThreads[id] = Date.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads);
|
||||||
|
}
|
||||||
|
return hiddenThreads;
|
||||||
|
},
|
||||||
cb: function() {
|
cb: function() {
|
||||||
return ThreadHiding.toggle($.x('ancestor::div[parent::div[@class="board"]]', this));
|
return ThreadHiding.toggle($.x('ancestor::div[parent::div[@class="board"]]', this));
|
||||||
},
|
},
|
||||||
@ -5157,14 +5180,18 @@
|
|||||||
|
|
||||||
Main = {
|
Main = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var cutoff, hiddenThreads, id, key, now, path, pathname, settings, temp, timestamp, val, _ref;
|
var key, path, pathname, settings, temp, val;
|
||||||
Main.flatten(null, Config);
|
Main.flatten(null, Config);
|
||||||
path = location.pathname;
|
path = location.pathname;
|
||||||
pathname = path.slice(1).split('/');
|
pathname = path.slice(1).split('/');
|
||||||
g.BOARD = pathname[0], temp = pathname[1];
|
g.BOARD = pathname[0], temp = pathname[1];
|
||||||
if (temp === 'res') {
|
switch (temp) {
|
||||||
g.REPLY = true;
|
case 'res':
|
||||||
g.THREAD_ID = pathname[2];
|
g.REPLY = true;
|
||||||
|
g.THREAD_ID = pathname[2];
|
||||||
|
break;
|
||||||
|
case 'catalog':
|
||||||
|
g.CATALOG = true;
|
||||||
}
|
}
|
||||||
for (key in Conf) {
|
for (key in Conf) {
|
||||||
val = Conf[key];
|
val = Conf[key];
|
||||||
@ -5212,6 +5239,19 @@
|
|||||||
settings.disableAll = true;
|
settings.disableAll = true;
|
||||||
localStorage.setItem('4chan-settings', JSON.stringify(settings));
|
localStorage.setItem('4chan-settings', JSON.stringify(settings));
|
||||||
}
|
}
|
||||||
|
if (g.CATALOG) {
|
||||||
|
return $.ready(Main.catalog);
|
||||||
|
} else {
|
||||||
|
return Main.features();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
catalog: function() {
|
||||||
|
if (Conf['Thread Hiding']) {
|
||||||
|
return ThreadHiding.init();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
features: function() {
|
||||||
|
var cutoff, hiddenThreads, id, now, timestamp, _ref;
|
||||||
Options.init();
|
Options.init();
|
||||||
if (Conf['Quick Reply'] && Conf['Hide Original Post Form']) {
|
if (Conf['Quick Reply'] && Conf['Hide Original Post Form']) {
|
||||||
Main.css += '#postForm { display: none; }';
|
Main.css += '#postForm { display: none; }';
|
||||||
@ -5314,9 +5354,9 @@
|
|||||||
if (Conf['Indicate Cross-thread Quotes']) {
|
if (Conf['Indicate Cross-thread Quotes']) {
|
||||||
QuoteCT.init();
|
QuoteCT.init();
|
||||||
}
|
}
|
||||||
return $.ready(Main.ready);
|
return $.ready(Main.featuresReady);
|
||||||
},
|
},
|
||||||
ready: function() {
|
featuresReady: function() {
|
||||||
var MutationObserver, a, board, nav, node, nodes, observer, _i, _j, _len, _len1, _ref, _ref1;
|
var MutationObserver, a, board, nav, node, nodes, observer, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
if (/^4chan - 404/.test(d.title)) {
|
if (/^4chan - 404/.test(d.title)) {
|
||||||
if (Conf['404 Redirect'] && /^\d+$/.test(g.THREAD_ID)) {
|
if (Conf['404 Redirect'] && /^\d+$/.test(g.THREAD_ID)) {
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
master
|
master
|
||||||
|
- Mayhem
|
||||||
|
Added catalog support:
|
||||||
|
Sync thread hiding between index and catalog.
|
||||||
|
|
||||||
2.36.3
|
2.36.3
|
||||||
- Mayhem
|
- Mayhem
|
||||||
|
|||||||
@ -269,8 +269,9 @@ $.extend $,
|
|||||||
fc()
|
fc()
|
||||||
$.on d, 'DOMContentLoaded', cb
|
$.on d, 'DOMContentLoaded', cb
|
||||||
sync: (key, cb) ->
|
sync: (key, cb) ->
|
||||||
|
key = Main.namespace + key
|
||||||
$.on window, 'storage', (e) ->
|
$.on window, 'storage', (e) ->
|
||||||
cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}"
|
cb JSON.parse e.newValue if e.key is key
|
||||||
id: (id) ->
|
id: (id) ->
|
||||||
d.getElementById id
|
d.getElementById id
|
||||||
formData: (arg) ->
|
formData: (arg) ->
|
||||||
@ -832,7 +833,8 @@ ExpandThread =
|
|||||||
|
|
||||||
ThreadHiding =
|
ThreadHiding =
|
||||||
init: ->
|
init: ->
|
||||||
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
|
hiddenThreads = ThreadHiding.sync()
|
||||||
|
return if g.CATALOG
|
||||||
for thread in $$ '.thread'
|
for thread in $$ '.thread'
|
||||||
a = $.el 'a',
|
a = $.el 'a',
|
||||||
className: 'hide_thread_button'
|
className: 'hide_thread_button'
|
||||||
@ -845,6 +847,20 @@ ThreadHiding =
|
|||||||
ThreadHiding.hide thread
|
ThreadHiding.hide thread
|
||||||
return
|
return
|
||||||
|
|
||||||
|
sync: ->
|
||||||
|
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
|
||||||
|
hiddenThreadsCatalog = JSON.parse localStorage.getItem "4chan-hide-t-#{g.BOARD}"
|
||||||
|
if g.CATALOG
|
||||||
|
for id of hiddenThreads
|
||||||
|
hiddenThreadsCatalog[id] = true
|
||||||
|
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify hiddenThreadsCatalog
|
||||||
|
else
|
||||||
|
for id of hiddenThreadsCatalog
|
||||||
|
unless id of hiddenThreads
|
||||||
|
hiddenThreads[id] = Date.now()
|
||||||
|
$.set "hiddenThreads/#{g.BOARD}/", hiddenThreads
|
||||||
|
hiddenThreads
|
||||||
|
|
||||||
cb: ->
|
cb: ->
|
||||||
ThreadHiding.toggle $.x 'ancestor::div[parent::div[@class="board"]]', @
|
ThreadHiding.toggle $.x 'ancestor::div[parent::div[@class="board"]]', @
|
||||||
|
|
||||||
@ -4178,9 +4194,12 @@ Main =
|
|||||||
path = location.pathname
|
path = location.pathname
|
||||||
pathname = path[1..].split '/'
|
pathname = path[1..].split '/'
|
||||||
[g.BOARD, temp] = pathname
|
[g.BOARD, temp] = pathname
|
||||||
if temp is 'res'
|
switch temp
|
||||||
g.REPLY = true
|
when 'res'
|
||||||
g.THREAD_ID = pathname[2]
|
g.REPLY = true
|
||||||
|
g.THREAD_ID = pathname[2]
|
||||||
|
when 'catalog'
|
||||||
|
g.CATALOG = true
|
||||||
|
|
||||||
# Load values from localStorage.
|
# Load values from localStorage.
|
||||||
for key, val of Conf
|
for key, val of Conf
|
||||||
@ -4213,6 +4232,16 @@ Main =
|
|||||||
settings.disableAll = true
|
settings.disableAll = true
|
||||||
localStorage.setItem '4chan-settings', JSON.stringify settings
|
localStorage.setItem '4chan-settings', JSON.stringify settings
|
||||||
|
|
||||||
|
if g.CATALOG
|
||||||
|
$.ready Main.catalog
|
||||||
|
else
|
||||||
|
Main.features()
|
||||||
|
|
||||||
|
catalog: ->
|
||||||
|
if Conf['Thread Hiding']
|
||||||
|
ThreadHiding.init()
|
||||||
|
|
||||||
|
features: ->
|
||||||
Options.init()
|
Options.init()
|
||||||
|
|
||||||
if Conf['Quick Reply'] and Conf['Hide Original Post Form']
|
if Conf['Quick Reply'] and Conf['Hide Original Post Form']
|
||||||
@ -4314,9 +4343,9 @@ Main =
|
|||||||
if Conf['Indicate Cross-thread Quotes']
|
if Conf['Indicate Cross-thread Quotes']
|
||||||
QuoteCT.init()
|
QuoteCT.init()
|
||||||
|
|
||||||
$.ready Main.ready
|
$.ready Main.featuresReady
|
||||||
|
|
||||||
ready: ->
|
featuresReady: ->
|
||||||
if /^4chan - 404/.test d.title
|
if /^4chan - 404/.test d.title
|
||||||
if Conf['404 Redirect'] and /^\d+$/.test g.THREAD_ID
|
if Conf['404 Redirect'] and /^\d+$/.test g.THREAD_ID
|
||||||
location.href =
|
location.href =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user