Get rid of iframes and thus of the "Loading" state of the QR too.
The "Loading" state should be shorter for Firefox users too as we get rid of an iframe workaround required for Chrome.
This commit is contained in:
parent
1b7efd8ec3
commit
61040279f4
111
4chan_x.user.js
111
4chan_x.user.js
@ -1222,26 +1222,34 @@
|
|||||||
$.before(form, link);
|
$.before(form, link);
|
||||||
}
|
}
|
||||||
g.callbacks.push(this.node);
|
g.callbacks.push(this.node);
|
||||||
iframe = $.el('iframe', {
|
if (engine === 'webkit') {
|
||||||
id: 'iframe',
|
qr.status({
|
||||||
hidden: true,
|
ready: true
|
||||||
src: 'http://sys.4chan.org/robots.txt'
|
});
|
||||||
});
|
} else {
|
||||||
$.on(iframe, 'error', function() {
|
iframe = $.el('iframe', {
|
||||||
return this.src = this.src;
|
id: 'iframe',
|
||||||
});
|
hidden: true,
|
||||||
loadChecking = function(iframe) {
|
src: 'http://sys.4chan.org/robots.txt'
|
||||||
if (!qr.status.ready) {
|
});
|
||||||
iframe.src = 'about:blank';
|
$.on(iframe, 'error', function() {
|
||||||
return setTimeout((function() {
|
return this.src = this.src;
|
||||||
return iframe.src = 'http://sys.4chan.org/robots.txt';
|
});
|
||||||
}), 250);
|
loadChecking = function(iframe) {
|
||||||
}
|
if (!qr.status.ready) {
|
||||||
};
|
iframe.src = 'about:blank';
|
||||||
$.on(iframe, 'load', function() {
|
return setTimeout((function() {
|
||||||
if (this.src !== 'about:blank') return setTimeout(loadChecking, 500, this);
|
return iframe.src = 'http://sys.4chan.org/robots.txt';
|
||||||
});
|
}), 100);
|
||||||
$.add(d.body, iframe);
|
}
|
||||||
|
};
|
||||||
|
$.on(iframe, 'load', function() {
|
||||||
|
if (this.src !== 'about:blank') {
|
||||||
|
return setTimeout(loadChecking, 500, this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$.add(d.body, iframe);
|
||||||
|
}
|
||||||
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})';
|
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})';
|
||||||
if (conf['Persistent QR']) {
|
if (conf['Persistent QR']) {
|
||||||
qr.dialog();
|
qr.dialog();
|
||||||
@ -1738,7 +1746,6 @@
|
|||||||
qr.status();
|
qr.status();
|
||||||
qr.cooldown.init();
|
qr.cooldown.init();
|
||||||
qr.captcha.init();
|
qr.captcha.init();
|
||||||
qr.message.init();
|
|
||||||
$.add(d.body, qr.el);
|
$.add(d.body, qr.el);
|
||||||
e = d.createEvent('CustomEvent');
|
e = d.createEvent('CustomEvent');
|
||||||
e.initEvent('QRDialogCreation', true, false);
|
e.initEvent('QRDialogCreation', true, false);
|
||||||
@ -1817,6 +1824,10 @@
|
|||||||
reader.readAsBinaryString(reply.file);
|
reader.readAsBinaryString(reply.file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (engine === 'webkit') {
|
||||||
|
qr.message.post(post);
|
||||||
|
return;
|
||||||
|
}
|
||||||
return qr.message.send(post);
|
return qr.message.send(post);
|
||||||
},
|
},
|
||||||
response: function(html) {
|
response: function(html) {
|
||||||
@ -1870,43 +1881,16 @@
|
|||||||
return qr.resetFileInput();
|
return qr.resetFileInput();
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
init: function() {
|
|
||||||
var code, ready, script;
|
|
||||||
code = function(e) {
|
|
||||||
var data, host;
|
|
||||||
data = e.data;
|
|
||||||
if (!data.changeContext) return;
|
|
||||||
delete data.changeContext;
|
|
||||||
host = location.hostname;
|
|
||||||
if (host === 'boards.4chan.org') {
|
|
||||||
return document.getElementById('iframe').contentWindow.postMessage(data, '*');
|
|
||||||
} else if (host === 'sys.4chan.org') {
|
|
||||||
return parent.postMessage(data, '*');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
script = $.el('script', {
|
|
||||||
textContent: "window.addEventListener('message'," + code + ",false)"
|
|
||||||
});
|
|
||||||
ready = function() {
|
|
||||||
$.add(d.documentElement, script);
|
|
||||||
if (location.hostname === 'sys.4chan.org') {
|
|
||||||
qr.message.send({
|
|
||||||
req: 'status',
|
|
||||||
ready: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return $.rm(script);
|
|
||||||
};
|
|
||||||
if (d.documentElement) {
|
|
||||||
return ready();
|
|
||||||
} else {
|
|
||||||
return $.ready(ready);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
send: function(data) {
|
send: function(data) {
|
||||||
data.changeContext = true;
|
var host, window;
|
||||||
|
if (engine === 'webkit') {
|
||||||
|
qr.message.receive(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
data.qr = true;
|
data.qr = true;
|
||||||
return postMessage(data, '*');
|
host = location.hostname;
|
||||||
|
window = host === 'boards.4chan.org' ? $.id('iframe').contentWindow : host === 'sys.4chan.org' ? parent : void 0;
|
||||||
|
return window.postMessage(data, '*');
|
||||||
},
|
},
|
||||||
receive: function(data) {
|
receive: function(data) {
|
||||||
var _ref;
|
var _ref;
|
||||||
@ -3349,7 +3333,7 @@
|
|||||||
var src, thumb;
|
var src, thumb;
|
||||||
if (root.hidden || !(thumb = $('img[md5]', root))) return;
|
if (root.hidden || !(thumb = $('img[md5]', root))) return;
|
||||||
src = thumb.parentNode.href;
|
src = thumb.parentNode.href;
|
||||||
if (/gif$/.test(src)) return thumb.src = src;
|
if (/gif$/.test(src && !/^Spoiler/.test(thumb.alt))) return thumb.src = src;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3505,7 +3489,10 @@
|
|||||||
$.on(window, 'message', Main.message);
|
$.on(window, 'message', Main.message);
|
||||||
if (location.hostname === 'sys.4chan.org') {
|
if (location.hostname === 'sys.4chan.org') {
|
||||||
if (location.pathname === '/robots.txt') {
|
if (location.pathname === '/robots.txt') {
|
||||||
qr.message.init();
|
qr.message.send({
|
||||||
|
req: 'status',
|
||||||
|
ready: true
|
||||||
|
});
|
||||||
} else if (/report/.test(location.search)) {
|
} else if (/report/.test(location.search)) {
|
||||||
$.ready(function() {
|
$.ready(function() {
|
||||||
return $.on($('#recaptcha_response_field'), 'keydown', function(e) {
|
return $.on($('#recaptcha_response_field'), 'keydown', function(e) {
|
||||||
@ -3624,10 +3611,12 @@
|
|||||||
message: function(e) {
|
message: function(e) {
|
||||||
var data, version;
|
var data, version;
|
||||||
data = e.data;
|
data = e.data;
|
||||||
|
if (data.qr) {
|
||||||
|
qr.message.receive(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
version = data.version;
|
version = data.version;
|
||||||
if (data.qr && !data.changeContext) {
|
if (version && version !== VERSION && confirm('An updated version of 4chan X is available, would you like to install it now?')) {
|
||||||
return qr.message.receive(data);
|
|
||||||
} else if (version && version !== VERSION && confirm('An updated version of 4chan X is available, would you like to install it now?')) {
|
|
||||||
return window.location = "https://raw.github.com/mayhemydg/4chan-x/" + version + "/4chan_x.user.js";
|
return window.location = "https://raw.github.com/mayhemydg/4chan-x/" + version + "/4chan_x.user.js";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -900,18 +900,21 @@ qr =
|
|||||||
$.before form, link
|
$.before form, link
|
||||||
g.callbacks.push @node
|
g.callbacks.push @node
|
||||||
|
|
||||||
iframe = $.el 'iframe',
|
if engine is 'webkit'
|
||||||
id: 'iframe'
|
qr.status ready: true
|
||||||
hidden: true
|
else
|
||||||
src: 'http://sys.4chan.org/robots.txt'
|
iframe = $.el 'iframe',
|
||||||
$.on iframe, 'error', -> @src = @src
|
id: 'iframe'
|
||||||
# Greasemonkey ghetto fix
|
hidden: true
|
||||||
loadChecking = (iframe) ->
|
src: 'http://sys.4chan.org/robots.txt'
|
||||||
unless qr.status.ready
|
$.on iframe, 'error', -> @src = @src
|
||||||
iframe.src = 'about:blank'
|
# Greasemonkey ghetto fix
|
||||||
setTimeout (-> iframe.src = 'http://sys.4chan.org/robots.txt'), 250
|
loadChecking = (iframe) ->
|
||||||
$.on iframe, 'load', -> unless @src is 'about:blank' then setTimeout loadChecking, 500, @
|
unless qr.status.ready
|
||||||
$.add d.body, iframe
|
iframe.src = 'about:blank'
|
||||||
|
setTimeout (-> iframe.src = 'http://sys.4chan.org/robots.txt'), 100
|
||||||
|
$.on iframe, 'load', -> if @src isnt 'about:blank' then setTimeout loadChecking, 500, @
|
||||||
|
$.add d.body, iframe
|
||||||
|
|
||||||
# Prevent original captcha input from being focused on reload.
|
# Prevent original captcha input from being focused on reload.
|
||||||
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'
|
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'
|
||||||
@ -1309,7 +1312,6 @@ qr =
|
|||||||
qr.status()
|
qr.status()
|
||||||
qr.cooldown.init()
|
qr.cooldown.init()
|
||||||
qr.captcha.init()
|
qr.captcha.init()
|
||||||
qr.message.init()
|
|
||||||
$.add d.body, qr.el
|
$.add d.body, qr.el
|
||||||
|
|
||||||
# Create a custom event when the QR dialog is first initialized.
|
# Create a custom event when the QR dialog is first initialized.
|
||||||
@ -1397,6 +1399,9 @@ qr =
|
|||||||
reader.readAsBinaryString reply.file
|
reader.readAsBinaryString reply.file
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if engine is 'webkit'
|
||||||
|
qr.message.post post
|
||||||
|
return
|
||||||
qr.message.send post
|
qr.message.send post
|
||||||
|
|
||||||
response: (html) ->
|
response: (html) ->
|
||||||
@ -1450,35 +1455,18 @@ qr =
|
|||||||
qr.resetFileInput()
|
qr.resetFileInput()
|
||||||
|
|
||||||
message:
|
message:
|
||||||
init: ->
|
|
||||||
# http://code.google.com/p/chromium/issues/detail?id=20773
|
|
||||||
# Let content scripts see other frames (instead of them being undefined)
|
|
||||||
# To access the parent, we have to break out of the sandbox and evaluate
|
|
||||||
# in the global context.
|
|
||||||
code = (e) ->
|
|
||||||
{data} = e
|
|
||||||
return unless data.changeContext
|
|
||||||
delete data.changeContext
|
|
||||||
host = location.hostname
|
|
||||||
if host is 'boards.4chan.org'
|
|
||||||
document.getElementById('iframe').contentWindow.postMessage data, '*'
|
|
||||||
else if host is 'sys.4chan.org'
|
|
||||||
parent.postMessage data, '*'
|
|
||||||
script = $.el 'script', textContent: "window.addEventListener('message',#{code},false)"
|
|
||||||
ready = ->
|
|
||||||
$.add d.documentElement, script
|
|
||||||
if location.hostname is 'sys.4chan.org'
|
|
||||||
qr.message.send req: 'status', ready: true
|
|
||||||
$.rm script
|
|
||||||
# Chrome can access the documentElement on document-start
|
|
||||||
if d.documentElement
|
|
||||||
ready()
|
|
||||||
# other browsers will have to wait
|
|
||||||
else $.ready ready
|
|
||||||
send: (data) ->
|
send: (data) ->
|
||||||
data.changeContext = true
|
if engine is 'webkit'
|
||||||
data.qr = true
|
qr.message.receive data
|
||||||
postMessage data, '*'
|
return
|
||||||
|
data.qr = true
|
||||||
|
host = location.hostname
|
||||||
|
window =
|
||||||
|
if host is 'boards.4chan.org'
|
||||||
|
$.id('iframe').contentWindow
|
||||||
|
else if host is 'sys.4chan.org'
|
||||||
|
parent
|
||||||
|
window.postMessage data, '*'
|
||||||
receive: (data) ->
|
receive: (data) ->
|
||||||
switch data.req
|
switch data.req
|
||||||
when 'abort'
|
when 'abort'
|
||||||
@ -2764,7 +2752,7 @@ Main =
|
|||||||
|
|
||||||
if location.hostname is 'sys.4chan.org'
|
if location.hostname is 'sys.4chan.org'
|
||||||
if location.pathname is '/robots.txt'
|
if location.pathname is '/robots.txt'
|
||||||
qr.message.init()
|
qr.message.send req: 'status', ready: true
|
||||||
else if /report/.test location.search
|
else if /report/.test location.search
|
||||||
$.ready ->
|
$.ready ->
|
||||||
$.on $('#recaptcha_response_field'), 'keydown', (e) ->
|
$.on $('#recaptcha_response_field'), 'keydown', (e) ->
|
||||||
@ -2928,10 +2916,11 @@ Main =
|
|||||||
|
|
||||||
message: (e) ->
|
message: (e) ->
|
||||||
{data} = e
|
{data} = e
|
||||||
{version} = data
|
if data.qr
|
||||||
if data.qr and not data.changeContext
|
|
||||||
qr.message.receive data
|
qr.message.receive data
|
||||||
else if version and version isnt VERSION and confirm 'An updated version of 4chan X is available, would you like to install it now?'
|
return
|
||||||
|
{version} = data
|
||||||
|
if version and version isnt VERSION and confirm 'An updated version of 4chan X is available, would you like to install it now?'
|
||||||
window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js"
|
window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js"
|
||||||
|
|
||||||
node: (nodes, notify) ->
|
node: (nodes, notify) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user