Init more features asynchronously.

This commit is contained in:
Nicolas Stepien 2012-03-08 01:47:30 +01:00
parent 6bc5f5d9be
commit 29617d64ef
2 changed files with 70 additions and 40 deletions

View File

@ -1258,8 +1258,12 @@
qr = { qr = {
init: function() { init: function() {
var form, iframe, link, loadChecking;
if (!$.id('recaptcha_challenge_field_holder')) return; if (!$.id('recaptcha_challenge_field_holder')) return;
g.callbacks.push(this.node);
return setTimeout(this.asyncInit);
},
asyncInit: function() {
var form, iframe, link, loadChecking, script;
if (conf['Hide Original Post Form']) { if (conf['Hide Original Post Form']) {
link = $.el('h1', { link = $.el('h1', {
innerHTML: "<a href=javascript:;>" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "</a>" innerHTML: "<a href=javascript:;>" + (g.REPLY ? 'Quick Reply' : 'New Thread') + "</a>"
@ -1271,7 +1275,6 @@
form = d.forms[0]; form = d.forms[0];
$.before(form, link); $.before(form, link);
} }
g.callbacks.push(this.node);
if (/chrome/i.test(navigator.userAgent)) { if (/chrome/i.test(navigator.userAgent)) {
qr.status({ qr.status({
ready: true ready: true
@ -1299,19 +1302,14 @@
}); });
$.add(d.head, iframe); $.add(d.head, iframe);
} }
setTimeout(function() { script = $.el('script', {
var script; textContent: 'Recaptcha.focus_response_field=function(){}'
script = $.el('script', {
textContent: 'Recaptcha.focus_response_field=function(){}'
});
$.add(d.head, script);
return $.rm(script);
}); });
$.add(d.head, script);
$.rm(script);
if (conf['Persistent QR']) { if (conf['Persistent QR']) {
setTimeout(function() { qr.dialog();
qr.dialog(); if (conf['Auto Hide QR']) qr.hide();
if (conf['Auto Hide QR']) return qr.hide();
});
} }
$.on(d, 'dragover', qr.dragOver); $.on(d, 'dragover', qr.dragOver);
$.on(d, 'drop', qr.dropFile); $.on(d, 'drop', qr.dropFile);
@ -3948,19 +3946,51 @@
Favicon.init(); Favicon.init();
if (conf['Quick Reply']) qr.init(); if (conf['Quick Reply']) qr.init();
if (conf['Image Expansion']) ImageExpand.init(); if (conf['Image Expansion']) ImageExpand.init();
if (conf['Thread Watcher']) Watcher.init(); if (conf['Thread Watcher']) {
if (conf['Keybinds']) Keybinds.init(); setTimeout(function() {
return Watcher.init();
});
}
if (conf['Keybinds']) {
setTimeout(function() {
return Keybinds.init();
});
}
if (g.REPLY) { if (g.REPLY) {
if (conf['Thread Updater']) Updater.init(); if (conf['Thread Updater']) {
setTimeout(function() {
return Updater.init();
});
}
if (conf['Thread Stats']) ThreadStats.init(); if (conf['Thread Stats']) ThreadStats.init();
if (conf['Reply Navigation']) Nav.init(); if (conf['Reply Navigation']) {
setTimeout(function() {
return Nav.init();
});
}
if (conf['Post in Title']) TitlePost.init(); if (conf['Post in Title']) TitlePost.init();
if (conf['Unread Count'] || conf['Unread Favicon']) Unread.init(); if (conf['Unread Count'] || conf['Unread Favicon']) Unread.init();
} else { } else {
if (conf['Thread Hiding']) ThreadHiding.init(); if (conf['Thread Hiding']) {
if (conf['Thread Expansion']) ExpandThread.init(); setTimeout(function() {
if (conf['Comment Expansion']) ExpandComment.init(); return ThreadHiding.init();
if (conf['Index Navigation']) Nav.init(); });
}
if (conf['Thread Expansion']) {
setTimeout(function() {
return ExpandThread.init();
});
}
if (conf['Comment Expansion']) {
setTimeout(function() {
return ExpandComment.init();
});
}
if (conf['Index Navigation']) {
setTimeout(function() {
return Nav.init();
});
}
} }
nodes = []; nodes = [];
_ref2 = $$('.op, a + table', form); _ref2 = $$('.op, a + table', form);

View File

@ -1031,6 +1031,10 @@ Nav =
qr = qr =
init: -> init: ->
return unless $.id 'recaptcha_challenge_field_holder' return unless $.id 'recaptcha_challenge_field_holder'
g.callbacks.push @node
setTimeout @asyncInit
asyncInit: ->
if conf['Hide Original Post Form'] if conf['Hide Original Post Form']
link = $.el 'h1', innerHTML: "<a href=javascript:;>#{if g.REPLY then 'Quick Reply' else 'New Thread'}</a>" link = $.el 'h1', innerHTML: "<a href=javascript:;>#{if g.REPLY then 'Quick Reply' else 'New Thread'}</a>"
$.on $('a', link), 'click', -> $.on $('a', link), 'click', ->
@ -1038,7 +1042,6 @@ qr =
$('textarea', qr.el).focus() $('textarea', qr.el).focus()
form = d.forms[0] form = d.forms[0]
$.before form, link $.before form, link
g.callbacks.push @node
# CORS is ignored for content script on Chrome, but not Safari/Oprah/Firefox. # CORS is ignored for content script on Chrome, but not Safari/Oprah/Firefox.
if /chrome/i.test navigator.userAgent if /chrome/i.test navigator.userAgent
@ -1056,17 +1059,14 @@ qr =
$.on iframe, 'load', -> if @src isnt 'about:blank' then setTimeout loadChecking, 500, @ $.on iframe, 'load', -> if @src isnt 'about:blank' then setTimeout loadChecking, 500, @
$.add d.head, iframe $.add d.head, iframe
# This is extemely slow, execute is asynchronously. # Prevent original captcha input from being focused on reload.
setTimeout -> script = $.el 'script', textContent: 'Recaptcha.focus_response_field=function(){}'
# Prevent original captcha input from being focused on reload. $.add d.head, script
script = $.el 'script', textContent: 'Recaptcha.focus_response_field=function(){}' $.rm script
$.add d.head, script
$.rm script
if conf['Persistent QR'] if conf['Persistent QR']
setTimeout -> qr.dialog()
qr.dialog() qr.hide() if conf['Auto Hide QR']
qr.hide() if conf['Auto Hide QR']
$.on d, 'dragover', qr.dragOver $.on d, 'dragover', qr.dragOver
$.on d, 'drop', qr.dropFile $.on d, 'drop', qr.dropFile
$.on d, 'dragstart', qr.drag $.on d, 'dragstart', qr.drag
@ -2054,7 +2054,7 @@ ThreadHiding =
hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {}
for thread in $$ '.thread' for thread in $$ '.thread'
op = thread.firstChild op = thread.firstChild
a = $.el 'a', a = $.el 'a',
textContent: '[ - ]' textContent: '[ - ]'
href: 'javascript:;' href: 'javascript:;'
$.on a, 'click', ThreadHiding.cb.hide $.on a, 'click', ThreadHiding.cb.hide
@ -3266,20 +3266,20 @@ Main =
ImageExpand.init() ImageExpand.init()
if conf['Thread Watcher'] if conf['Thread Watcher']
Watcher.init() setTimeout -> Watcher.init()
if conf['Keybinds'] if conf['Keybinds']
Keybinds.init() setTimeout -> Keybinds.init()
if g.REPLY if g.REPLY
if conf['Thread Updater'] if conf['Thread Updater']
Updater.init() setTimeout -> Updater.init()
if conf['Thread Stats'] if conf['Thread Stats']
ThreadStats.init() ThreadStats.init()
if conf['Reply Navigation'] if conf['Reply Navigation']
Nav.init() setTimeout -> Nav.init()
if conf['Post in Title'] if conf['Post in Title']
TitlePost.init() TitlePost.init()
@ -3289,16 +3289,16 @@ Main =
else #not reply else #not reply
if conf['Thread Hiding'] if conf['Thread Hiding']
ThreadHiding.init() setTimeout -> ThreadHiding.init()
if conf['Thread Expansion'] if conf['Thread Expansion']
ExpandThread.init() setTimeout -> ExpandThread.init()
if conf['Comment Expansion'] if conf['Comment Expansion']
ExpandComment.init() setTimeout -> ExpandComment.init()
if conf['Index Navigation'] if conf['Index Navigation']
Nav.init() setTimeout -> Nav.init()
nodes = [] nodes = []
for node in $$ '.op, a + table', form for node in $$ '.op, a + table', form