Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: popup.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Oct. 9, 2017, 3:12 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« options.js ('K') | « options.js ('k') | qunit/tests/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popup.js
===================================================================
--- a/popup.js
+++ b/popup.js
@@ -16,63 +16,63 @@
*/
"use strict";
let tab = null;
function getPref(key, callback)
{
- chrome.runtime.sendMessage({type: "prefs.get", key}, callback);
+ browser.runtime.sendMessage({type: "prefs.get", key}, callback);
}
function togglePref(key, callback)
{
- chrome.runtime.sendMessage({type: "prefs.toggle", key}, callback);
+ browser.runtime.sendMessage({type: "prefs.toggle", key}, callback);
}
function isPageWhitelisted(callback)
{
- chrome.runtime.sendMessage({type: "filters.isWhitelisted", tab}, callback);
+ browser.runtime.sendMessage({type: "filters.isWhitelisted", tab}, callback);
}
function whenPageReady()
{
return new Promise(resolve =>
{
function onMessage(message, sender)
{
if (message.type == "composer.ready" && sender.page &&
sender.page.id == tab.id)
{
- chrome.runtime.onMessage.removeListener(onMessage);
+ browser.runtime.onMessage.removeListener(onMessage);
resolve();
}
}
- chrome.runtime.onMessage.addListener(onMessage);
+ browser.runtime.onMessage.addListener(onMessage);
- chrome.runtime.sendMessage({
+ browser.runtime.sendMessage({
type: "composer.isPageReady",
pageId: tab.id
},
ready =>
{
if (ready)
{
- chrome.runtime.onMessage.removeListener(onMessage);
+ browser.runtime.onMessage.removeListener(onMessage);
resolve();
}
});
});
}
function onLoad()
{
- chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
+ browser.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
{
if (tabs.length > 0)
tab = {id: tabs[0].id, url: tabs[0].url};
let urlProtocol = tab && tab.url && new URL(tab.url).protocol;
// Mark page as 'local' to hide non-relevant elements
if (urlProtocol != "http:" && urlProtocol != "https:")
@@ -95,17 +95,17 @@
if (tab)
{
isPageWhitelisted(whitelisted =>
{
if (whitelisted)
document.body.classList.add("disabled");
});
- chrome.tabs.sendMessage(tab.id, {
+ browser.tabs.sendMessage(tab.id, {
type: "composer.content.getState"
},
response =>
{
if (response && response.active)
document.body.classList.add("clickhide-active");
});
}
@@ -117,17 +117,17 @@
document.getElementById("clickhide").addEventListener(
"click", activateClickHide, false
);
document.getElementById("clickhide-cancel").addEventListener(
"click", cancelClickHide, false
);
document.getElementById("options").addEventListener("click", () =>
{
- chrome.runtime.sendMessage({type: "app.open", what: "options"});
+ browser.runtime.sendMessage({type: "app.open", what: "options"});
window.close();
}, false);
// Set up collapsing of menu items
for (let collapser of document.getElementsByClassName("collapse"))
{
collapser.addEventListener("click", toggleCollapse, false);
getPref(collapser.dataset.option, value =>
@@ -140,42 +140,42 @@
}
});
}
}
function toggleEnabled()
{
let disabled = document.body.classList.toggle("disabled");
- chrome.runtime.sendMessage({
+ browser.runtime.sendMessage({
type: disabled ? "filters.whitelist" : "filters.unwhitelist",
tab
});
}
function activateClickHide()
{
document.body.classList.add("clickhide-active");
- chrome.tabs.sendMessage(tab.id, {
+ browser.tabs.sendMessage(tab.id, {
type: "composer.content.startPickingElement"
});
// Close the popup after a few seconds, so user doesn't have to
activateClickHide.timeout = window.setTimeout(window.close, 5000);
}
function cancelClickHide()
{
if (activateClickHide.timeout)
{
window.clearTimeout(activateClickHide.timeout);
activateClickHide.timeout = null;
}
document.body.classList.remove("clickhide-active");
- chrome.tabs.sendMessage(tab.id, {type: "composer.content.finished"});
+ browser.tabs.sendMessage(tab.id, {type: "composer.content.finished"});
}
function toggleCollapse(event)
{
let collapser = event.currentTarget;
let collapsible = document.getElementById(collapser.dataset.collapsible);
collapsible.classList.toggle("collapsed");
togglePref(collapser.dataset.option);
« options.js ('K') | « options.js ('k') | qunit/tests/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld