From 827d1f0987e11c77896eb81c3497646230b226fb Mon Sep 17 00:00:00 2001 From: James Campos Date: Mon, 15 Aug 2011 22:13:35 -0700 Subject: [PATCH] Revert "cleanup, should work in chrome" This reverts commit 3faa0b314001d71da308958f954df2555ccf53e2. --- 4chan_x.user.js | 72 +++++++++++++++++++++++++++++-------------------- script.coffee | 57 ++++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 53 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 0fc0c121b..37c75147f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1416,7 +1416,20 @@ 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(); @@ -1434,22 +1447,17 @@ } } } + if (this.id !== 'qr_form') { + return; + } + if (!e) { + this.submit(); + } $('#error', qr.el).textContent = ''; if (conf['Auto Hide QR']) { $('#autohide', qr.el).checked = true; } - 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), '*'); + return qr.sage = /sage/i.test($('input[name=email]', this).value); }, foo: function() { var body, data, href, node, textContent, _ref; @@ -1465,18 +1473,7 @@ } else { 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. - */ + return parent.postMessage(data, '*'); }, sysMessage: function(e) { var board, data, formData, key, val, x; @@ -1491,16 +1488,33 @@ return x = $.xhr("http://sys.4chan.org/" + board + "/post", qr.foo, formData); }, sys: function() { - var c, duration, error, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref, _ref2; + var c, duration, id, noko, recaptcha, sage, search, thread, url, watch, _, _ref, _ref2; + $.bind(window, 'message', qr.sysMessage); + return; if (recaptcha = $('#recaptcha_response_field')) { $.bind(recaptcha, 'keydown', Recaptcha.listener); return; } - $.bind(window, 'message', qr.sysMessage); - error = $.el('span', { - id: 'error' + /* + 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, '*'); }); - $.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 4d106f1e6..00e7807b7 100644 --- a/script.coffee +++ b/script.coffee @@ -1163,7 +1163,18 @@ 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() @@ -1178,18 +1189,13 @@ 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 @@ -1199,19 +1205,7 @@ qr = data = JSON.stringify {textContent, href} else 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. - ### + parent.postMessage data, '*' sysMessage: (e) -> data = JSON.parse e.data @@ -1225,13 +1219,28 @@ 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 - $.bind window, 'message', qr.sysMessage - error = $.el 'span', id: 'error' - $.append d.body, error + ### + 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, '*' c = $('b')?.lastChild