Merge Mayhem X

This commit is contained in:
Jordan Bates 2013-05-14 13:32:43 -07:00
commit f4db0a60ff
8 changed files with 138 additions and 34 deletions

View File

@ -1308,12 +1308,18 @@
}; };
DataBoard.prototype.clean = function() { DataBoard.prototype.clean = function() {
var boardID, now; var boardID, now, val, _ref;
for (boardID in this.data.boards) { _ref = this.data.boards;
this.deleteIfEmpty({ for (boardID in _ref) {
boardID: boardID val = _ref[boardID];
}); if (!val) {
delete this.data.boards[boardID];
} else {
this.deleteIfEmpty({
boardID: boardID
});
}
} }
now = Date.now(); now = Date.now();
if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) { if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) {
@ -2681,6 +2687,10 @@
} }
for (key in Config.filter) { for (key in Config.filter) {
this.filters[key] = []; this.filters[key] = [];
if (Conf[key] === void 0) {
$["delete"](key);
continue;
}
_ref = Conf[key].split('\n'); _ref = Conf[key].split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
filter = _ref[_i]; filter = _ref[_i];
@ -9186,7 +9196,7 @@
Sauce = { Sauce = {
init: function() { init: function() {
var link, links, _i, _len, _ref; var err, link, links, _i, _len, _ref;
if (g.VIEW === 'catalog' || !Conf['Sauce']) { if (g.VIEW === 'catalog' || !Conf['Sauce']) {
return; return;
@ -9198,7 +9208,12 @@
if (link[0] === '#') { if (link[0] === '#') {
continue; continue;
} }
links.push(this.createSauceLink(link.trim())); try {
links.push(this.createSauceLink(link.trim()));
} catch (_error) {
err = _error;
continue;
}
} }
if (!links.length) { if (!links.length) {
return; return;
@ -9578,6 +9593,7 @@
}; };
} }
$.get(Conf, function(Conf) { $.get(Conf, function(Conf) {
delete Conf['archives'];
data.Conf = Conf; data.Conf = Conf;
return Settings["export"](now, data); return Settings["export"](now, data);
}); });
@ -10035,10 +10051,11 @@
} }
Conf['selectedArchives'] = {}; Conf['selectedArchives'] = {};
$.get(Conf, Main.initFeatures); $.get(Conf, Main.initFeatures);
$.on(d, '4chanMainInit', Main.initStyle);
return $.asap((function() { return $.asap((function() {
var _ref; var _ref;
return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); return d.head && $('title', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete');
}), Main.initStyle); }), Main.initStyle);
}, },
initFeatures: function(items) { initFeatures: function(items) {
@ -10047,6 +10064,9 @@
Conf = items; Conf = items;
pathname = location.pathname.split('/'); pathname = location.pathname.split('/');
g.BOARD = new Board(pathname[1]); g.BOARD = new Board(pathname[1]);
if (g.BOARD.ID === 'z') {
return;
}
g.VIEW = (function() { g.VIEW = (function() {
switch (pathname[2]) { switch (pathname[2]) {
case 'res': case 'res':
@ -10162,7 +10182,8 @@
initStyle: function() { initStyle: function() {
var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref; var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref;
if (!Main.isThisPageLegit()) { $.off(d, '4chanMainInit', Main.initStyle);
if (!Main.isThisPageLegit() || $.hasClass(doc, 'fourchan-x')) {
return; return;
} }
if ((_ref = $('link[href*=mobile]', d.head)) != null) { if ((_ref = $('link[href*=mobile]', d.head)) != null) {
@ -10274,6 +10295,12 @@
} }
return; return;
} }
try {
localStorage.getItem('4chan-settings');
} catch (_error) {
err = _error;
new Notification('warning', 'Cookies need to be enabled on 4chan for 4chan X to properly function.', 30);
}
$.event('4chanXInitFinished'); $.event('4chanXInitFinished');
return Main.checkUpdate(); return Main.checkUpdate();
}, },

View File

@ -1304,12 +1304,18 @@
}; };
DataBoard.prototype.clean = function() { DataBoard.prototype.clean = function() {
var boardID, now; var boardID, now, val, _ref;
for (boardID in this.data.boards) { _ref = this.data.boards;
this.deleteIfEmpty({ for (boardID in _ref) {
boardID: boardID val = _ref[boardID];
}); if (!val) {
delete this.data.boards[boardID];
} else {
this.deleteIfEmpty({
boardID: boardID
});
}
} }
now = Date.now(); now = Date.now();
if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) { if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) {
@ -2677,6 +2683,10 @@
} }
for (key in Config.filter) { for (key in Config.filter) {
this.filters[key] = []; this.filters[key] = [];
if (Conf[key] === void 0) {
$["delete"](key);
continue;
}
_ref = Conf[key].split('\n'); _ref = Conf[key].split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
filter = _ref[_i]; filter = _ref[_i];
@ -9195,7 +9205,7 @@
Sauce = { Sauce = {
init: function() { init: function() {
var link, links, _i, _len, _ref; var err, link, links, _i, _len, _ref;
if (g.VIEW === 'catalog' || !Conf['Sauce']) { if (g.VIEW === 'catalog' || !Conf['Sauce']) {
return; return;
@ -9207,7 +9217,12 @@
if (link[0] === '#') { if (link[0] === '#') {
continue; continue;
} }
links.push(this.createSauceLink(link.trim())); try {
links.push(this.createSauceLink(link.trim()));
} catch (_error) {
err = _error;
continue;
}
} }
if (!links.length) { if (!links.length) {
return; return;
@ -9587,6 +9602,7 @@
}; };
} }
$.get(Conf, function(Conf) { $.get(Conf, function(Conf) {
delete Conf['archives'];
data.Conf = Conf; data.Conf = Conf;
return Settings["export"](now, data); return Settings["export"](now, data);
}); });
@ -10046,10 +10062,11 @@
} }
Conf['selectedArchives'] = {}; Conf['selectedArchives'] = {};
$.get(Conf, Main.initFeatures); $.get(Conf, Main.initFeatures);
$.on(d, '4chanMainInit', Main.initStyle);
return $.asap((function() { return $.asap((function() {
var _ref; var _ref;
return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); return d.head && $('title', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete');
}), Main.initStyle); }), Main.initStyle);
}, },
initFeatures: function(items) { initFeatures: function(items) {
@ -10058,6 +10075,9 @@
Conf = items; Conf = items;
pathname = location.pathname.split('/'); pathname = location.pathname.split('/');
g.BOARD = new Board(pathname[1]); g.BOARD = new Board(pathname[1]);
if (g.BOARD.ID === 'z') {
return;
}
g.VIEW = (function() { g.VIEW = (function() {
switch (pathname[2]) { switch (pathname[2]) {
case 'res': case 'res':
@ -10173,7 +10193,8 @@
initStyle: function() { initStyle: function() {
var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref; var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref;
if (!Main.isThisPageLegit()) { $.off(d, '4chanMainInit', Main.initStyle);
if (!Main.isThisPageLegit() || $.hasClass(doc, 'fourchan-x')) {
return; return;
} }
if ((_ref = $('link[href*=mobile]', d.head)) != null) { if ((_ref = $('link[href*=mobile]', d.head)) != null) {
@ -10285,6 +10306,12 @@
} }
return; return;
} }
try {
localStorage.getItem('4chan-settings');
} catch (_error) {
err = _error;
new Notification('warning', 'Cookies need to be enabled on 4chan for 4chan X to properly function.', 30);
}
$.event('4chanXInitFinished'); $.event('4chanXInitFinished');
return Main.checkUpdate(); return Main.checkUpdate();
}, },

View File

@ -1306,12 +1306,18 @@
}; };
DataBoard.prototype.clean = function() { DataBoard.prototype.clean = function() {
var boardID, now; var boardID, now, val, _ref;
for (boardID in this.data.boards) { _ref = this.data.boards;
this.deleteIfEmpty({ for (boardID in _ref) {
boardID: boardID val = _ref[boardID];
}); if (!val) {
delete this.data.boards[boardID];
} else {
this.deleteIfEmpty({
boardID: boardID
});
}
} }
now = Date.now(); now = Date.now();
if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) { if ((this.data.lastChecked || 0) < now - 2 * $.HOUR) {
@ -2679,6 +2685,10 @@
} }
for (key in Config.filter) { for (key in Config.filter) {
this.filters[key] = []; this.filters[key] = [];
if (Conf[key] === void 0) {
$["delete"](key);
continue;
}
_ref = Conf[key].split('\n'); _ref = Conf[key].split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
filter = _ref[_i]; filter = _ref[_i];
@ -9178,7 +9188,7 @@
Sauce = { Sauce = {
init: function() { init: function() {
var link, links, _i, _len, _ref; var err, link, links, _i, _len, _ref;
if (g.VIEW === 'catalog' || !Conf['Sauce']) { if (g.VIEW === 'catalog' || !Conf['Sauce']) {
return; return;
@ -9190,7 +9200,12 @@
if (link[0] === '#') { if (link[0] === '#') {
continue; continue;
} }
links.push(this.createSauceLink(link.trim())); try {
links.push(this.createSauceLink(link.trim()));
} catch (_error) {
err = _error;
continue;
}
} }
if (!links.length) { if (!links.length) {
return; return;
@ -9570,6 +9585,7 @@
}; };
} }
$.get(Conf, function(Conf) { $.get(Conf, function(Conf) {
delete Conf['archives'];
data.Conf = Conf; data.Conf = Conf;
return Settings["export"](now, data); return Settings["export"](now, data);
}); });
@ -10027,10 +10043,11 @@
} }
Conf['selectedArchives'] = {}; Conf['selectedArchives'] = {};
$.get(Conf, Main.initFeatures); $.get(Conf, Main.initFeatures);
$.on(d, '4chanMainInit', Main.initStyle);
return $.asap((function() { return $.asap((function() {
var _ref; var _ref;
return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); return d.head && $('title', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete');
}), Main.initStyle); }), Main.initStyle);
}, },
initFeatures: function(items) { initFeatures: function(items) {
@ -10039,6 +10056,9 @@
Conf = items; Conf = items;
pathname = location.pathname.split('/'); pathname = location.pathname.split('/');
g.BOARD = new Board(pathname[1]); g.BOARD = new Board(pathname[1]);
if (g.BOARD.ID === 'z') {
return;
}
g.VIEW = (function() { g.VIEW = (function() {
switch (pathname[2]) { switch (pathname[2]) {
case 'res': case 'res':
@ -10154,7 +10174,8 @@
initStyle: function() { initStyle: function() {
var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref; var MutationObserver, mainStyleSheet, observer, setStyle, style, styleSheets, _ref;
if (!Main.isThisPageLegit()) { $.off(d, '4chanMainInit', Main.initStyle);
if (!Main.isThisPageLegit() || $.hasClass(doc, 'fourchan-x')) {
return; return;
} }
if ((_ref = $('link[href*=mobile]', d.head)) != null) { if ((_ref = $('link[href*=mobile]', d.head)) != null) {
@ -10267,6 +10288,12 @@
} }
return; return;
} }
try {
localStorage.getItem('4chan-settings');
} catch (_error) {
err = _error;
new Notification('warning', 'Cookies need to be enabled on 4chan for 4chan X to properly function.', 30);
}
$.event('4chanXInitFinished'); $.event('4chanXInitFinished');
return Main.checkUpdate(); return Main.checkUpdate();
}, },

View File

@ -8,6 +8,11 @@ Filter =
for key of Config.filter for key of Config.filter
@filters[key] = [] @filters[key] = []
if Conf[key] is undefined
# XXX hopefully tmp fix for the rare people getting this mysterious error:
# "Filter" initialization crashed. TypeError: Cannot call method 'split' of undefined
$.delete key
continue
for filter in Conf[key].split '\n' for filter in Conf[key].split '\n'
continue if filter[0] is '#' continue if filter[0] is '#'
@ -272,4 +277,4 @@ Filter =
ta = $ 'textarea', section ta = $ 'textarea', section
tl = ta.textLength tl = ta.textLength
ta.setSelectionRange tl, tl ta.setSelectionRange tl, tl
ta.focus() ta.focus()

View File

@ -18,7 +18,8 @@ Main =
$.get Conf, Main.initFeatures $.get Conf, Main.initFeatures
$.asap (-> d.head and $('link[rel="shortcut icon"]', d.head) or d.readyState in ['interactive', 'complete']),\ $.on d, '4chanMainInit', Main.initStyle
$.asap (-> d.head and $('title', d.head) or d.readyState in ['interactive', 'complete']),
Main.initStyle Main.initStyle
initFeatures: (items) -> initFeatures: (items) ->
@ -26,6 +27,7 @@ Main =
pathname = location.pathname.split '/' pathname = location.pathname.split '/'
g.BOARD = new Board pathname[1] g.BOARD = new Board pathname[1]
return if g.BOARD.ID is 'z'
g.VIEW = g.VIEW =
switch pathname[2] switch pathname[2]
when 'res' when 'res'
@ -131,7 +133,8 @@ Main =
$.ready Main.initReady $.ready Main.initReady
initStyle: -> initStyle: ->
return unless Main.isThisPageLegit() $.off d, '4chanMainInit', Main.initStyle
return if !Main.isThisPageLegit() or $.hasClass doc, 'fourchan-x'
# disable the mobile layout # disable the mobile layout
$('link[href*=mobile]', d.head)?.disabled = true $('link[href*=mobile]', d.head)?.disabled = true
<% if (type === 'crx') { %> <% if (type === 'crx') { %>
@ -223,6 +226,10 @@ Main =
return return
try
localStorage.getItem '4chan-settings'
catch err
new Notification 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to properly function.', 30
$.event '4chanXInitFinished' $.event '4chanXInitFinished'
Main.checkUpdate() Main.checkUpdate()

View File

@ -154,6 +154,8 @@ Settings =
Conf[db] = boards: {} Conf[db] = boards: {}
# Make sure to export the most recent data. # Make sure to export the most recent data.
$.get Conf, (Conf) -> $.get Conf, (Conf) ->
# XXX don't export archives.
delete Conf['archives']
data.Conf = Conf data.Conf = Conf
Settings.export now, data Settings.export now, data
return return

View File

@ -59,8 +59,13 @@ class DataBoard
val or defaultValue val or defaultValue
clean: -> clean: ->
for boardID of @data.boards for boardID, val of @data.boards
@deleteIfEmpty {boardID} # XXX tmp fix for users that had the `null`
# value for a board with the Unread features:
unless val
delete @data.boards[boardID]
else
@deleteIfEmpty {boardID}
now = Date.now() now = Date.now()
if (@data.lastChecked or 0) < now - 2 * $.HOUR if (@data.lastChecked or 0) < now - 2 * $.HOUR

View File

@ -5,7 +5,11 @@ Sauce =
links = [] links = []
for link in Conf['sauces'].split '\n' for link in Conf['sauces'].split '\n'
continue if link[0] is '#' continue if link[0] is '#'
links.push @createSauceLink link.trim() try
links.push @createSauceLink link.trim()
catch err
# Don't add random text plz.
continue
return unless links.length return unless links.length
@links = links @links = links
@link = $.el 'a', target: '_blank' @link = $.el 'a', target: '_blank'
@ -39,4 +43,4 @@ Sauce =
for link in Sauce.links for link in Sauce.links
# \u00A0 is nbsp # \u00A0 is nbsp
nodes.push $.tn('\u00A0'), link @, Sauce.link.cloneNode true nodes.push $.tn('\u00A0'), link @, Sauce.link.cloneNode true
$.add @file.info, nodes $.add @file.info, nodes