Start catalog support. Close #834.

This commit is contained in:
Nicolas Stepien 2012-12-10 14:41:58 +01:00
parent fdaee4641e
commit 65b1e168b3
3 changed files with 87 additions and 15 deletions

View File

@ -318,8 +318,9 @@
return $.on(d, 'DOMContentLoaded', cb);
},
sync: function(key, cb) {
key = Main.namespace + key;
return $.on(window, 'storage', function(e) {
if (e.key === ("" + Main.namespace + key)) {
if (e.key === key) {
return cb(JSON.parse(e.newValue));
}
});
@ -1042,7 +1043,10 @@
ThreadHiding = {
init: function() {
var a, hiddenThreads, thread, _i, _len, _ref;
hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {});
hiddenThreads = ThreadHiding.sync();
if (g.CATALOG) {
return;
}
_ref = $$('.thread');
for (_i = 0, _len = _ref.length; _i < _len; _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() {
return ThreadHiding.toggle($.x('ancestor::div[parent::div[@class="board"]]', this));
},
@ -5157,14 +5180,18 @@
Main = {
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);
path = location.pathname;
pathname = path.slice(1).split('/');
g.BOARD = pathname[0], temp = pathname[1];
if (temp === 'res') {
g.REPLY = true;
g.THREAD_ID = pathname[2];
switch (temp) {
case 'res':
g.REPLY = true;
g.THREAD_ID = pathname[2];
break;
case 'catalog':
g.CATALOG = true;
}
for (key in Conf) {
val = Conf[key];
@ -5212,6 +5239,19 @@
settings.disableAll = true;
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();
if (Conf['Quick Reply'] && Conf['Hide Original Post Form']) {
Main.css += '#postForm { display: none; }';
@ -5314,9 +5354,9 @@
if (Conf['Indicate Cross-thread Quotes']) {
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;
if (/^4chan - 404/.test(d.title)) {
if (Conf['404 Redirect'] && /^\d+$/.test(g.THREAD_ID)) {

View File

@ -1,4 +1,7 @@
master
- Mayhem
Added catalog support:
Sync thread hiding between index and catalog.
2.36.3
- Mayhem

View File

@ -269,8 +269,9 @@ $.extend $,
fc()
$.on d, 'DOMContentLoaded', cb
sync: (key, cb) ->
key = Main.namespace + key
$.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) ->
d.getElementById id
formData: (arg) ->
@ -832,7 +833,8 @@ ExpandThread =
ThreadHiding =
init: ->
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
hiddenThreads = ThreadHiding.sync()
return if g.CATALOG
for thread in $$ '.thread'
a = $.el 'a',
className: 'hide_thread_button'
@ -845,6 +847,20 @@ ThreadHiding =
ThreadHiding.hide thread
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: ->
ThreadHiding.toggle $.x 'ancestor::div[parent::div[@class="board"]]', @
@ -4178,9 +4194,12 @@ Main =
path = location.pathname
pathname = path[1..].split '/'
[g.BOARD, temp] = pathname
if temp is 'res'
g.REPLY = true
g.THREAD_ID = pathname[2]
switch temp
when 'res'
g.REPLY = true
g.THREAD_ID = pathname[2]
when 'catalog'
g.CATALOG = true
# Load values from localStorage.
for key, val of Conf
@ -4213,6 +4232,16 @@ Main =
settings.disableAll = true
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()
if Conf['Quick Reply'] and Conf['Hide Original Post Form']
@ -4314,9 +4343,9 @@ Main =
if Conf['Indicate Cross-thread Quotes']
QuoteCT.init()
$.ready Main.ready
$.ready Main.featuresReady
ready: ->
featuresReady: ->
if /^4chan - 404/.test d.title
if Conf['404 Redirect'] and /^\d+$/.test g.THREAD_ID
location.href =