Merge branch 'master' of https://github.com/MayhemYDG/4chan-x into pull-request

This commit is contained in:
noface 2012-12-10 15:22:56 +01:00
commit f3149a314b
3 changed files with 112 additions and 32 deletions

View File

@ -319,8 +319,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));
}
});
@ -1043,7 +1044,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];
@ -1059,6 +1063,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));
},
@ -4199,7 +4222,10 @@
FileInfo.node(post);
}
if (Conf['Resurrect Quotes']) {
return Quotify.node(post);
Quotify.node(post);
}
if (Conf['Anonymize']) {
return Anonymize.node(post);
}
});
$.on(this, 'mousemove', UI.hover);
@ -5218,16 +5244,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];
} else if (temp === 'catalog') {
g.CATALOG = true;
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];
@ -5275,6 +5303,22 @@
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['Catalog Links']) {
CatalogLinks.init();
}
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; }';
@ -5377,9 +5421,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)) {
@ -5404,15 +5448,15 @@
}
}
Favicon.init();
if (Conf['Catalog Links']) {
CatalogLinks.init();
}
if (Conf['Quick Reply']) {
QR.init();
}
if (Conf['Image Expansion']) {
ImageExpand.init();
}
if (Conf['Catalog Links']) {
CatalogLinks.init();
}
if (Conf['Thread Watcher']) {
setTimeout(function() {
return Watcher.init();

View File

@ -1,6 +1,10 @@
master
- noface
Add Catalog Links toggle.
Fix Anonymize not working on hovered posts.
- Mayhem
Added catalog support:
Sync thread hiding between index and catalog.
2.36.3
- Mayhem

View File

@ -270,8 +270,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) ->
@ -833,7 +834,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'
@ -846,6 +848,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"]]', @
@ -3449,6 +3465,8 @@ QuotePreview =
FileInfo.node post
if Conf['Resurrect Quotes']
Quotify.node post
if Conf['Anonymize']
Anonymize.node post
$.on @, 'mousemove', UI.hover
$.on @, 'mouseout click', QuotePreview.mouseout
@ -4197,20 +4215,20 @@ CatalogLinks =
while a.href and split = a.href.split '/'
unless /^rs|status/.test split[2]
if (isDead = split[3] is 'f') and g.CATALOG or split[4] is 'catalog'
a.href = a.href.replace /catalog$/, ''
a.title = a.title.replace /\ -\ Catalog$/, ''
a.href = a.href.replace /catalog$/, ''
a.title = a.title.replace /\ -\ Catalog$/, ''
else if not isDead
a.href += 'catalog'
a.title += ' - Catalog'
a = a.nextElementSibling
if /On$/.test (el = a.parentNode.lastChild.firstElementChild).textContent
el.textContent = 'Catalog Off'
el.title = 'Turn Catalog Links off.'
el.textContent = 'Catalog Off'
el.title = 'Turn Catalog Links off.'
$.set 'CatalogIsToggled', true
else
el.textContent = 'Catalog On'
el.title = 'Turn Catalog Links on.'
el.textContent = 'Catalog On'
el.title = 'Turn Catalog Links on.'
$.delete 'CatalogIsToggled'
return
@ -4221,11 +4239,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]
else if temp is 'catalog'
g.CATALOG = true
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
@ -4258,6 +4277,19 @@ Main =
settings.disableAll = true
localStorage.setItem '4chan-settings', JSON.stringify settings
if g.CATALOG
$.ready Main.catalog
else
Main.features()
catalog: ->
if Conf['Catalog Links']
CatalogLinks.init()
if Conf['Thread Hiding']
ThreadHiding.init()
features: ->
Options.init()
if Conf['Quick Reply'] and Conf['Hide Original Post Form']
@ -4359,9 +4391,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 =
@ -4380,9 +4412,6 @@ Main =
$.addClass a, 'current'
Favicon.init()
if Conf['Catalog Links']
CatalogLinks.init()
# Major features.
if Conf['Quick Reply']
QR.init()
@ -4390,6 +4419,9 @@ Main =
if Conf['Image Expansion']
ImageExpand.init()
if Conf['Catalog Links']
CatalogLinks.init()
if Conf['Thread Watcher']
setTimeout -> Watcher.init()