Index: ext/content.js |
diff --git a/ext/content.js b/ext/content.js |
index 3b5200b4e8d5b073269f382834d3a26714a96946..697c198ba0d7d37982d2561740959bc081d2ab2e 100644 |
--- a/ext/content.js |
+++ b/ext/content.js |
@@ -15,58 +15,63 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
-(function(global) |
+"use strict"; |
+ |
{ |
Wladimir Palant
2017/03/09 15:05:07
Here we have no functions declared so strictly spe
kzar
2017/03/10 07:28:59
Done.
|
- if (!global.ext) |
- global.ext = {}; |
+ if (typeof ext == "undefined") |
+ window.ext = {}; |
- var backgroundFrame = document.createElement("iframe"); |
- backgroundFrame.setAttribute("src", "background.html" + window.location.search); |
+ let backgroundFrame = document.createElement("iframe"); |
+ backgroundFrame.setAttribute("src", |
+ "background.html" + window.location.search); |
backgroundFrame.style.display = "none"; |
- window.addEventListener("DOMContentLoaded", function() |
+ window.addEventListener("DOMContentLoaded", () => |
{ |
document.body.appendChild(backgroundFrame); |
}, false); |
- var messageQueue = []; |
- var maxMessageId = -1; |
- var loadHandler = function(event) |
+ let messageQueue = []; |
+ let maxMessageId = -1; |
+ let loadHandler = (event) => |
{ |
if (event.data.type == "backgroundPageLoaded") |
{ |
- var queue = messageQueue; |
+ let queue = messageQueue; |
messageQueue = null; |
if (queue) |
- for (var i = 0; i < queue.length; i++) |
- backgroundFrame.contentWindow.postMessage(queue[i], "*"); |
+ { |
+ for (let message of queue) |
+ backgroundFrame.contentWindow.postMessage(message, "*"); |
+ } |
window.removeEventListener("message", loadHandler, false); |
} |
- } |
+ }; |
window.addEventListener("message", loadHandler, false); |
- global.ext.backgroundPage = { |
- _sendRawMessage: function(message) |
+ ext.backgroundPage = { |
+ _sendRawMessage(message) |
{ |
if (messageQueue) |
messageQueue.push(message); |
else |
backgroundFrame.contentWindow.postMessage(message, "*"); |
}, |
- sendMessage: function(message, responseCallback) |
+ sendMessage(message, responseCallback) |
{ |
- var messageId = ++maxMessageId; |
+ let messageId = ++maxMessageId; |
this._sendRawMessage({ |
type: "message", |
- messageId: messageId, |
+ messageId, |
payload: message |
}); |
if (responseCallback) |
{ |
- var callbackWrapper = function(event) |
+ let callbackWrapper = function(event) |
{ |
- if (event.data.type == "response" && event.data.messageId == messageId) |
+ if (event.data.type == "response" && |
+ event.data.messageId == messageId) |
{ |
window.removeEventListener("message", callbackWrapper, false); |
responseCallback(event.data.payload); |
@@ -76,4 +81,4 @@ |
} |
} |
}; |
-})(this); |
+} |