Set up transcontext messaging between the global window and the iframe window. Fuck you moot.
This commit is contained in:
parent
8e64f1e877
commit
59131e484c
@ -1494,7 +1494,7 @@
|
||||
}
|
||||
});
|
||||
qr.mimeTypes = mimeTypes.split(', ');
|
||||
qr.el = ui.dialog('qr', 'top:0;right:0;', "<div class=move> Quick Reply <input type=checkbox name=autohide id=autohide title=Auto-hide> <span>" + (g.REPLY ? '' : threads) + " <a class=close>x</a></span></div><form> <div><input id=dump class=field type=button title='Dump mode' value=+><input name=name title=Name placeholder=Name class=field size=1><input name=email title=E-mail placeholder=E-mail class=field size=1><input name=sub title=Subject placeholder=Subject class=field size=1></div> <output id=replies><div><a id=addReply href=javascript:;>+</a></div></output> <div><textarea name=com title=Comment placeholder=Comment class=field></textarea></div> <div class=captcha title=Reload><img></div> <div><input name=captcha title=Verification class=field size=1></div> <div><input type=file name=upfile max=" + ($('[name=MAX_FILE_SIZE]').value) + " accept='" + mimeTypes + "' multiple><input type=submit value=" + (g.dead ? '404 disabled' : 'Submit') + "></div> <label" + (qr.spoiler ? '' : ' hidden') + "><input type=checkbox id=spoiler> Spoiler Image?</label> <div class=error></div></form>");
|
||||
qr.el = ui.dialog('qr', 'top:0;right:0;', "<div class=move> Quick Reply <input type=checkbox name=autohide id=autohide title=Auto-hide> <span>" + (g.REPLY ? '' : threads) + " <a class=close>x</a></span></div><form> <div><input id=dump class=field type=button title='Dump mode' value=+><input name=name title=Name placeholder=Name class=field size=1><input name=email title=E-mail placeholder=E-mail class=field size=1><input name=sub title=Subject placeholder=Subject class=field size=1></div> <output id=replies><div><a id=addReply href=javascript:;>+</a></div></output> <div><textarea name=com title=Comment placeholder=Comment class=field></textarea></div> <div class=captcha title=Reload><img></div> <div><input name=captcha title=Verification class=field size=1></div> <div><input type=file name=upfile max=" + ($('[name=MAX_FILE_SIZE]').value) + " accept='" + mimeTypes + "' multiple><input type=submit value=" + (g.dead ? '404 disabled' : 'Submit') + "></div> <label" + (qr.spoiler ? '' : ' hidden') + "><input type=checkbox id=spoiler> Spoiler Image?</label> <div class=error></div></form><iframe id=iframe src=http://sys.4chan.org/post hidden></iframe>");
|
||||
if (!g.REPLY) {
|
||||
$.on($('select', qr.el), 'mousedown', function(e) {
|
||||
return e.stopPropagation();
|
||||
@ -1525,6 +1525,7 @@
|
||||
});
|
||||
}
|
||||
qr.captcha.init();
|
||||
qr.message.init();
|
||||
return $.add(d.body, qr.el);
|
||||
},
|
||||
submit: function(e) {
|
||||
@ -1547,6 +1548,36 @@
|
||||
if (conf['Remember Subject']) $.set("qr_sub", reply.sub);
|
||||
if (qr.replies.length === 1) new qr.reply().select();
|
||||
return reply.rm();
|
||||
},
|
||||
message: {
|
||||
init: function() {
|
||||
var code, 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)"
|
||||
});
|
||||
$.add(d.documentElement, script);
|
||||
return $.rm(script);
|
||||
},
|
||||
send: function(data) {
|
||||
data.changeContext = true;
|
||||
data.qr = true;
|
||||
return postMessage(data, '*');
|
||||
},
|
||||
receive: function(data) {
|
||||
return log('receive', location.hostname, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3051,18 +3082,19 @@
|
||||
} else {
|
||||
g.PAGENUM = parseInt(temp) || 0;
|
||||
}
|
||||
$.on(window, 'message', Main.message);
|
||||
if (location.hostname === 'sys.4chan.org') {
|
||||
$.ready(function() {
|
||||
if (/report/.test(location.search)) {
|
||||
if (location.pathname === '/post') {
|
||||
qr.message.init();
|
||||
} else if (/report/.test(location.search)) {
|
||||
$.ready(function() {
|
||||
return $.on($('#recaptcha_response_field'), 'keydown', function(e) {
|
||||
if (e.keyCode === 8 && !e.target.value) {
|
||||
return window.location = 'javascript:Recaptcha.reload()';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (location.hostname === 'images.4chan.org') {
|
||||
@ -3072,7 +3104,6 @@
|
||||
return;
|
||||
}
|
||||
$.ready(options.init);
|
||||
$.on(window, 'message', Main.message);
|
||||
now = Date.now();
|
||||
if (conf['Check for Updates'] && $.get('lastUpdate', 0) < now - 6 * HOUR) {
|
||||
$.ready(function() {
|
||||
@ -3159,9 +3190,12 @@
|
||||
return $.on($('form[name=delform]'), 'DOMNodeInserted', Main.node);
|
||||
},
|
||||
message: function(e) {
|
||||
var version;
|
||||
version = e.data.version;
|
||||
if (version && version !== VERSION && confirm('An updated version of 4chan X is available, would you like to install it now?')) {
|
||||
var data, version;
|
||||
data = e.data;
|
||||
version = data.version;
|
||||
if (data.qr && !data.changeContext) {
|
||||
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";
|
||||
}
|
||||
},
|
||||
|
||||
@ -1125,7 +1125,8 @@ qr =
|
||||
<div><input type=file name=upfile max=#{$('[name=MAX_FILE_SIZE]').value} accept='#{mimeTypes}' multiple><input type=submit value=#{if g.dead then '404 disabled' else 'Submit'}></div>
|
||||
<label#{if qr.spoiler then '' else ' hidden'}><input type=checkbox id=spoiler> Spoiler Image?</label>
|
||||
<div class=error></div>
|
||||
</form>"
|
||||
</form>
|
||||
<iframe id=iframe src=http://sys.4chan.org/post hidden></iframe>"
|
||||
unless g.REPLY
|
||||
$.on $('select', qr.el), 'mousedown', (e) -> e.stopPropagation()
|
||||
$.on $('#autohide', qr.el), 'click', qr.hide
|
||||
@ -1147,6 +1148,7 @@ qr =
|
||||
# qr.inputs[match[1]].value = JSON.parse e.newValue
|
||||
|
||||
qr.captcha.init()
|
||||
qr.message.init()
|
||||
$.add d.body, qr.el
|
||||
|
||||
submit: (e) ->
|
||||
@ -1176,6 +1178,32 @@ qr =
|
||||
new qr.reply().select() if qr.replies.length is 1
|
||||
reply.rm()
|
||||
|
||||
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)"
|
||||
$.add d.documentElement, script
|
||||
$.rm script
|
||||
send: (data) ->
|
||||
data.changeContext = true
|
||||
data.qr = true
|
||||
postMessage data, '*'
|
||||
receive: (data) ->
|
||||
log 'receive', location.hostname, data
|
||||
|
||||
options =
|
||||
init: ->
|
||||
home = $ '#navtopr a'
|
||||
@ -2333,13 +2361,15 @@ Main =
|
||||
else
|
||||
g.PAGENUM = parseInt(temp) or 0
|
||||
|
||||
$.on window, 'message', Main.message
|
||||
|
||||
if location.hostname is 'sys.4chan.org'
|
||||
$.ready ->
|
||||
if /report/.test location.search
|
||||
if location.pathname is '/post'
|
||||
qr.message.init()
|
||||
else if /report/.test location.search
|
||||
$.ready ->
|
||||
$.on $('#recaptcha_response_field'), 'keydown', (e) ->
|
||||
window.location = 'javascript:Recaptcha.reload()' if e.keyCode is 8 and not e.target.value
|
||||
else
|
||||
# posting
|
||||
return
|
||||
if location.hostname is 'images.4chan.org'
|
||||
$.ready -> redirect.init() if d.title is '4chan - 404'
|
||||
@ -2347,8 +2377,6 @@ Main =
|
||||
|
||||
$.ready options.init
|
||||
|
||||
$.on window, 'message', Main.message
|
||||
|
||||
now = Date.now()
|
||||
if conf['Check for Updates'] and $.get('lastUpdate', 0) < now - 6*HOUR
|
||||
$.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js'
|
||||
@ -2486,8 +2514,11 @@ Main =
|
||||
$.on $('form[name=delform]'), 'DOMNodeInserted', Main.node
|
||||
|
||||
message: (e) ->
|
||||
{version} = e.data
|
||||
if version and version isnt VERSION and confirm 'An updated version of 4chan X is available, would you like to install it now?'
|
||||
{data} = e
|
||||
{version} = data
|
||||
if data.qr and not data.changeContext
|
||||
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?'
|
||||
window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js"
|
||||
|
||||
node: (e) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user