Break up some stuff, address a few small issues

This commit is contained in:
Zixaphir 2014-01-09 11:00:08 -07:00
parent 9478dabdad
commit d2311ab805
3 changed files with 134 additions and 122 deletions

View File

@ -12477,7 +12477,7 @@
}); });
}, },
initReady: function() { initReady: function() {
var GMver, err, errors, href, i, passLink, post, postRoot, posts, styleSelector, thread, threadRoot, v, _i, _j, _len, _len1, _ref, _ref1, _ref2; var GMver, err, href, i, passLink, styleSelector, v, _i, _len, _ref, _ref1;
if ((_ref = d.title) === '4chan - Temporarily Offline' || _ref === '4chan - 404 Not Found') { if ((_ref = d.title) === '4chan - Temporarily Offline' || _ref === '4chan - 404 Not Found') {
if (Conf['404 Redirect'] && g.VIEW === 'thread') { if (Conf['404 Redirect'] && g.VIEW === 'thread') {
href = Redirect.to('thread', { href = Redirect.to('thread', {
@ -12490,66 +12490,70 @@
return; return;
} }
Main.initStyle(); Main.initStyle();
if (g.VIEW === 'thread' && (threadRoot = $('.thread'))) { if (g.VIEW === 'thread') {
thread = new Thread(+threadRoot.id.slice(1), g.BOARD); Main.initThread();
posts = []; } else {
_ref1 = $$('.thread > .postContainer', threadRoot); $.event('4chanXInitFinished');
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { }
postRoot = _ref1[_i]; if (styleSelector = $.id('styleSelector')) {
try { passLink = $.el('a', {
posts.push(post = new Post(postRoot, thread, g.BOARD, { textContent: '4chan Pass',
isOriginalMarkup: true href: 'javascript:;'
}));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.",
error: err
});
}
}
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]);
Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
}); });
if (styleSelector = $.id('styleSelector')) { $.on(passLink, 'click', function() {
passLink = $.el('a', { return window.open('//sys.4chan.org/auth', 'This will steal your data.', 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0');
textContent: '4chan Pass', });
href: 'javascript:;' $.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
});
$.on(passLink, 'click', function() {
return window.open('//sys.4chan.org/auth', 'This will steal your data.', 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0');
});
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
}
return;
} }
GMver = GM_info.version.split('.'); GMver = GM_info.version.split('.');
_ref2 = "1.13".split('.'); _ref1 = "1.13".split('.');
for (i = _j = 0, _len1 = _ref2.length; _j < _len1; i = ++_j) { for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) {
v = _ref2[i]; v = _ref1[i];
if (v < GMver[i]) {
break;
}
if (v === GMver[i]) { if (v === GMver[i]) {
continue; continue;
} }
new Notice('warning', "Your version of Greasemonkey is outdated (v" + GM_info.version + " instead of v1.13 minimum) and 4chan X may not operate correctly.", 30); (v < GMver[i]) || new Notice('warning', "Your version of Greasemonkey is outdated (v" + GM_info.version + " instead of v1.13 minimum) and 4chan X may not operate correctly.", 30);
break; break;
} }
try { try {
localStorage.getItem('4chan-settings'); return localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30); return new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30);
} }
return $.event('4chanXInitFinished'); },
initThread: function() {
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref;
if (!(threadRoot = $('.thread'))) {
return;
}
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
posts = [];
_ref = $$('.thread > .postContainer', threadRoot);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
postRoot = _ref[_i];
try {
posts.push(new Post(postRoot, thread, g.BOARD, {
isOriginalMarkup: true
}));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.",
error: err
});
}
}
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]);
return Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
});
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var cb, i, node; var cb, i, node;

View File

@ -12464,7 +12464,7 @@
}); });
}, },
initReady: function() { initReady: function() {
var err, errors, href, passLink, post, postRoot, posts, styleSelector, thread, threadRoot, _i, _len, _ref, _ref1; var err, href, passLink, styleSelector, _ref;
if ((_ref = d.title) === '4chan - Temporarily Offline' || _ref === '4chan - 404 Not Found') { if ((_ref = d.title) === '4chan - Temporarily Offline' || _ref === '4chan - 404 Not Found') {
if (Conf['404 Redirect'] && g.VIEW === 'thread') { if (Conf['404 Redirect'] && g.VIEW === 'thread') {
href = Redirect.to('thread', { href = Redirect.to('thread', {
@ -12477,53 +12477,60 @@
return; return;
} }
Main.initStyle(); Main.initStyle();
if (g.VIEW === 'thread' && (threadRoot = $('.thread'))) { if (g.VIEW === 'thread') {
thread = new Thread(+threadRoot.id.slice(1), g.BOARD); Main.initThread();
posts = []; } else {
_ref1 = $$('.thread > .postContainer', threadRoot); $.event('4chanXInitFinished');
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { }
postRoot = _ref1[_i]; if (styleSelector = $.id('styleSelector')) {
try { passLink = $.el('a', {
posts.push(post = new Post(postRoot, thread, g.BOARD, { textContent: '4chan Pass',
isOriginalMarkup: true href: 'javascript:;'
}));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.",
error: err
});
}
}
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]);
Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
}); });
if (styleSelector = $.id('styleSelector')) { $.on(passLink, 'click', function() {
passLink = $.el('a', { return window.open('//sys.4chan.org/auth', 'This will steal your data.', 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0');
textContent: '4chan Pass', });
href: 'javascript:;' $.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
});
$.on(passLink, 'click', function() {
return window.open('//sys.4chan.org/auth', 'This will steal your data.', 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0');
});
$.before(styleSelector.previousSibling, [$.tn('['), passLink, $.tn(']\u00A0\u00A0')]);
}
return;
} }
try { try {
localStorage.getItem('4chan-settings'); return localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30); return new Notice('warning', 'Cookies need to be enabled on 4chan for 4chan X to operate properly.', 30);
} }
return $.event('4chanXInitFinished'); },
initThread: function() {
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref;
if (!(threadRoot = $('.thread'))) {
return;
}
thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
posts = [];
_ref = $$('.thread > .postContainer', threadRoot);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
postRoot = _ref[_i];
try {
posts.push(new Post(postRoot, thread, g.BOARD, {
isOriginalMarkup: true
}));
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.",
error: err
});
}
}
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]);
return Main.callbackNodesDB(Post, posts, function() {
return $.event('4chanXInitFinished');
});
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var cb, i, node; var cb, i, node;

View File

@ -182,42 +182,26 @@ Main =
# Something might have gone wrong! # Something might have gone wrong!
Main.initStyle() Main.initStyle()
if g.VIEW is 'thread' and threadRoot = $ '.thread' if g.VIEW is 'thread'
thread = new Thread +threadRoot.id[1..], g.BOARD Main.initThread()
posts = [] else
for postRoot in $$ '.thread > .postContainer', threadRoot $.event '4chanXInitFinished'
try
posts.push post = new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true}
catch err
# Skip posts that we failed to parse.
errors = [] unless errors
errors.push
message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped."
error: err
Main.handleErrors errors if errors
Main.callbackNodes Thread, [thread] if styleSelector = $.id 'styleSelector'
Main.callbackNodesDB Post, posts, -> passLink = $.el 'a',
$.event '4chanXInitFinished' textContent: '4chan Pass'
href: 'javascript:;'
if styleSelector = $.id 'styleSelector' $.on passLink, 'click', ->
passLink = $.el 'a', window.open '//sys.4chan.org/auth',
textContent: '4chan Pass' 'This will steal your data.'
href: 'javascript:;' 'left=0,top=0,width=500,height=255,toolbar=0,resizable=0'
$.on passLink, 'click', -> $.before styleSelector.previousSibling, [$.tn '['; passLink, $.tn ']\u00A0\u00A0']
window.open '//sys.4chan.org/auth',
'This will steal your data.'
'left=0,top=0,width=500,height=255,toolbar=0,resizable=0'
$.before styleSelector.previousSibling, [$.tn '['; passLink, $.tn ']\u00A0\u00A0']
return
<% if (type === 'userscript') { %> <% if (type === 'userscript') { %>
GMver = GM_info.version.split '.' GMver = GM_info.version.split '.'
for v, i in "<%= meta.min.greasemonkey %>".split '.' for v, i in "<%= meta.min.greasemonkey %>".split '.'
break if v < GMver[i]
continue if v is GMver[i] continue if v is GMver[i]
new Notice 'warning', "Your version of Greasemonkey is outdated (v#{GM_info.version} instead of v<%= meta.min.greasemonkey %> minimum) and <%= meta.name %> may not operate correctly.", 30 (v < GMver[i]) or new Notice 'warning', "Your version of Greasemonkey is outdated (v#{GM_info.version} instead of v<%= meta.min.greasemonkey %> minimum) and <%= meta.name %> may not operate correctly.", 30
break break
<% } %> <% } %>
@ -226,7 +210,24 @@ Main =
catch err catch err
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
$.event '4chanXInitFinished' initThread: ->
return unless threadRoot = $ '.thread'
thread = new Thread +threadRoot.id[1..], g.BOARD
posts = []
for postRoot in $$ '.thread > .postContainer', threadRoot
try
posts.push new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true}
catch err
# Skip posts that we failed to parse.
errors = [] unless errors
errors.push
message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped."
error: err
Main.handleErrors errors if errors
Main.callbackNodes Thread, [thread]
Main.callbackNodesDB Post, posts, ->
$.event '4chanXInitFinished'
callbackNodes: (klass, nodes) -> callbackNodes: (klass, nodes) ->
i = 0 i = 0