From 64a3e4284a89362ec031212d84696e13471d75cd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 24 Jan 2012 12:15:35 +0100 Subject: [PATCH] Fix error/success checking for Firefox. WHY do you people still use this garbage. Apparently, I cannot message the object once again, unless I recreate it for who the hell knows what reason. Fuck that shit. --- 4chan_x.user.js | 17 +++++++++++++---- script.coffee | 13 +++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4cc224270..266ba4415 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1624,18 +1624,27 @@ init: function() { var code; code = function(e) { - var data, host; + var data, host, i, o, u; data = e.data; if (!data.changeContext) return; delete data.changeContext; host = location.hostname; + o = {}; + for (i in data) { + u = data[i]; + o[i] = u; + } if (host === 'boards.4chan.org') { - return document.getElementById('iframe').contentWindow.postMessage(data, '*'); + return document.getElementById('iframe').contentWindow.postMessage(o, '*'); } else if (host === 'sys.4chan.org') { - return parent.postMessage(data, '*'); + return parent.postMessage(o, '*'); } }; - return window.location = "javascript:window.addEventListener('message'," + code + ",false)"; + if (engine === 'gecko') { + return $.on(window, 'message', code); + } else { + return window.location = "javascript:window.addEventListener('message'," + code + ",false)"; + } }, send: function(data) { data.changeContext = true; diff --git a/script.coffee b/script.coffee index d2d9e2053..a7adeeae5 100644 --- a/script.coffee +++ b/script.coffee @@ -100,7 +100,6 @@ config = 'Auto Update': [true, 'Automatically fetch new posts'] 'Interval': 30 - # XXX Chrome can't into {log} = console # XXX GreaseMonkey can't into console.log.bind log = console.log.bind? console @@ -1248,12 +1247,18 @@ qr = return unless data.changeContext delete data.changeContext host = location.hostname + o = {} + for i, u of data + o[i] = u if host is 'boards.4chan.org' - document.getElementById('iframe').contentWindow.postMessage data, '*' + document.getElementById('iframe').contentWindow.postMessage o, '*' else if host is 'sys.4chan.org' - parent.postMessage data, '*' + parent.postMessage o, '*' # do not wait for 4chan to load - window.location = "javascript:window.addEventListener('message',#{code},false)" + if engine is 'gecko' + $.on window, 'message', code + else + window.location = "javascript:window.addEventListener('message',#{code},false)" send: (data) -> data.changeContext = true data.qr = true