From 3faa0b314001d71da308958f954df2555ccf53e2 Mon Sep 17 00:00:00 2001 From: James Campos Date: Mon, 15 Aug 2011 21:33:16 -0700 Subject: [PATCH] cleanup, should work in chrome --- 4chan_x.user.js | 72 ++++++++++++++++++++----------------------------- script.coffee | 57 +++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 76 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 36866c054..f0d90166f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1417,20 +1417,7 @@ submit: function(e) { var data, el, id, msg, op, _i, _len, _ref; e.preventDefault(); - data = { - board: g.BOARD - }; - _ref = $$('[name]', qr.el); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - el = _ref[_i]; - if (el.value) { - data[el.name] = el.value; - } - } - $('iframe').contentWindow.postMessage(JSON.stringify(data), '*'); - return; if (msg = qr.postInvalid()) { - e.preventDefault(); alert(msg); if (msg === 'You forgot to type in the verification.') { $('#recaptcha_response_field', qr.el).focus(); @@ -1448,17 +1435,22 @@ } } } - if (this.id !== 'qr_form') { - return; - } - if (!e) { - this.submit(); - } $('#error', qr.el).textContent = ''; if (conf['Auto Hide QR']) { $('#autohide', qr.el).checked = true; } - return qr.sage = /sage/i.test($('input[name=email]', this).value); + qr.sage = /sage/i.test($('input[name=email]', this).value); + data = { + board: g.BOARD + }; + _ref = $$('[name]', qr.el); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + el = _ref[_i]; + if (el.value) { + data[el.name] = el.value; + } + } + return $('iframe').contentWindow.postMessage(JSON.stringify(data), '*'); }, foo: function() { var body, data, href, node, textContent, _ref; @@ -1474,7 +1466,18 @@ } else { data = ''; } - return parent.postMessage(data, '*'); + $('#error').textContent = data; + return $.globalEval(function() { + data = document.getElementById('error').textContent; + return parent.postMessage(data, '*'); + }); + /* + 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. + */ }, sysMessage: function(e) { var board, data, formData, key, val, x; @@ -1489,33 +1492,16 @@ return x = $.xhr("http://sys.4chan.org/" + board + "/post", qr.foo, formData); }, sys: function() { - var c, duration, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref, _ref2; - $.bind(window, 'message', qr.sysMessage); - return; + var c, duration, error, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref, _ref2; if (recaptcha = $('#recaptcha_response_field')) { $.bind(recaptcha, 'keydown', Recaptcha.listener); return; } - /* - 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. - */ - $.globalEval(function() { - var data, href, node, textContent, _ref; - if (node = (_ref = document.querySelector('table font b')) != null ? _ref.firstChild : void 0) { - textContent = node.textContent, href = node.href; - data = JSON.stringify({ - textContent: textContent, - href: href - }); - } else { - data = ''; - } - return parent.postMessage(data, '*'); + $.bind(window, 'message', qr.sysMessage); + error = $.el('span', { + id: 'error' }); + $.append(d.body, error); c = (_ref = $('b')) != null ? _ref.lastChild : void 0; if (!(c && c.nodeType === 8)) { return; diff --git a/script.coffee b/script.coffee index 00e7807b7..4d106f1e6 100644 --- a/script.coffee +++ b/script.coffee @@ -1163,18 +1163,7 @@ qr = submit: (e) -> e.preventDefault() - data = - board: g.BOARD - - for el in $$ '[name]', qr.el when el.value - data[el.name] = el.value - - $('iframe').contentWindow.postMessage JSON.stringify(data), '*' - - return - if msg = qr.postInvalid() - e.preventDefault() alert msg if msg is 'You forgot to type in the verification.' $('#recaptcha_response_field', qr.el).focus() @@ -1189,13 +1178,18 @@ qr = if $('img.favicon', op).src is Favicon.empty watcher.watch op, id - return unless @id is 'qr_form' - - if !e then @submit() $('#error', qr.el).textContent = '' $('#autohide', qr.el).checked = true if conf['Auto Hide QR'] qr.sage = /sage/i.test $('input[name=email]', @).value + data = + board: g.BOARD + + for el in $$ '[name]', qr.el when el.value + data[el.name] = el.value + + $('iframe').contentWindow.postMessage JSON.stringify(data), '*' + foo: -> body = $.el 'body', innerHTML: @responseText @@ -1205,7 +1199,19 @@ qr = data = JSON.stringify {textContent, href} else data = '' - parent.postMessage data, '*' + $('#error').textContent = data + + $.globalEval -> + data = document.getElementById('error').textContent + parent.postMessage data, '*' + + ### + 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. + ### sysMessage: (e) -> data = JSON.parse e.data @@ -1219,28 +1225,13 @@ qr = x = $.xhr "http://sys.4chan.org/#{board}/post", qr.foo, formData sys: -> - $.bind window, 'message', qr.sysMessage - - return - if recaptcha = $ '#recaptcha_response_field' #post reporting $.bind recaptcha, 'keydown', Recaptcha.listener return - ### - 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. - ### - $.globalEval -> - if node = document.querySelector('table font b')?.firstChild - {textContent, href} = node - data = JSON.stringify {textContent, href} - else - data = '' - parent.postMessage data, '*' + $.bind window, 'message', qr.sysMessage + error = $.el 'span', id: 'error' + $.append d.body, error c = $('b')?.lastChild