Index: popup.js |
=================================================================== |
--- a/popup.js |
+++ b/popup.js |
@@ -24,17 +24,17 @@ |
facebook: ["https://www.facebook.com/dialog/feed", { |
app_id: "475542399197328", |
link: shareURL, |
redirect_uri: "https://www.facebook.com/", |
ref: "adcounter", |
name: messageMark, |
actions: JSON.stringify([ |
{ |
- name: chrome.i18n.getMessage("stats_share_download"), |
+ name: browser.i18n.getMessage("stats_share_download"), |
link: shareURL |
} |
]) |
}], |
gplus: ["https://plus.google.com/share", { |
url: shareURL |
}], |
twitter: ["https://twitter.com/intent/tweet", { |
@@ -43,94 +43,94 @@ |
via: "AdblockPlus" |
}] |
}; |
let tab = null; |
function getPref(key, callback) |
{ |
- chrome.runtime.sendMessage({type: "prefs.get", key}, callback); |
+ browser.runtime.sendMessage({type: "prefs.get", key}, callback); |
} |
function setPref(key, value, callback) |
{ |
- chrome.runtime.sendMessage({type: "prefs.set", key, value}, callback); |
+ browser.runtime.sendMessage({type: "prefs.set", key, value}, 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 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); |
@@ -141,17 +141,17 @@ |
if (!notification.links) |
return Promise.resolve([]); |
return Promise.all( |
notification.links.map(link => |
{ |
return new Promise((resolve, reject) => |
{ |
- chrome.runtime.sendMessage({ |
+ browser.runtime.sendMessage({ |
type: "app.get", |
what: "doclink", |
link |
}, resolve); |
}); |
}) |
); |
} |
@@ -186,28 +186,28 @@ |
let url = shareLinks[network][0]; |
let params = shareLinks[network][1]; |
let querystring = []; |
for (let key in params) |
{ |
let value = params[key]; |
if (value == messageMark) |
- value = chrome.i18n.getMessage("stats_share_message", blockedCount); |
+ value = browser.i18n.getMessage("stats_share_message", blockedCount); |
querystring.push( |
encodeURIComponent(key) + "=" + encodeURIComponent(value) |
); |
} |
return url + "?" + querystring.join("&"); |
} |
function updateStats() |
{ |
let statsPage = document.getElementById("stats-page"); |
- chrome.runtime.sendMessage({ |
+ browser.runtime.sendMessage({ |
type: "stats.getBlockedPerPage", |
tab |
}, |
blockedPage => |
{ |
ext.i18n.setElementText(statsPage, "stats_label_page", |
[blockedPage.toLocaleString()]); |
}); |
@@ -226,21 +226,21 @@ |
{ |
// Easter Egg |
if (blockedTotal <= 9000 || blockedTotal >= 10000) |
{ |
blockedTotal = blockedTotal.toLocaleString(); |
} |
else |
{ |
- blockedTotal = chrome.i18n.getMessage("stats_over", |
+ blockedTotal = browser.i18n.getMessage("stats_over", |
(9000).toLocaleString()); |
} |
- chrome.tabs.create({ |
+ browser.tabs.create({ |
url: createShareLink(event.target.dataset.social, blockedTotal) |
}); |
}); |
} |
function toggleIconNumber() |
{ |
togglePref("show_statsinicon", showStatsInIcon => |
@@ -248,17 +248,17 @@ |
document.getElementById("show-iconnumber").setAttribute( |
"aria-checked", showStatsInIcon |
); |
}); |
} |
document.addEventListener("DOMContentLoaded", () => |
{ |
- 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:") |
@@ -281,17 +281,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"); |
}); |
} |
@@ -306,17 +306,17 @@ |
document.getElementById("clickhide").addEventListener( |
"click", activateClickHide |
); |
document.getElementById("clickhide-cancel").addEventListener( |
"click", cancelClickHide |
); |
document.getElementById("options").addEventListener("click", () => |
{ |
- chrome.runtime.sendMessage({type: "app.open", what: "options"}); |
+ browser.runtime.sendMessage({type: "app.open", what: "options"}); |
window.close(); |
}); |
// Set up collapsing of menu items |
for (let collapser of document.getElementsByClassName("collapse")) |
{ |
collapser.addEventListener("click", toggleCollapse); |
getPref(collapser.dataset.option, value => |
@@ -339,17 +339,17 @@ |
showIconNumber.addEventListener("click", toggleIconNumber); |
document.querySelector("label[for='show-iconnumber']").addEventListener( |
"click", toggleIconNumber |
); |
}); |
window.addEventListener("load", () => |
{ |
- chrome.runtime.sendMessage({ |
+ browser.runtime.sendMessage({ |
type: "notifications.get", |
displayMethod: "popup" |
}, notification => |
{ |
if (!notification) |
return; |
let titleElement = document.getElementById("notification-title"); |
@@ -365,17 +365,17 @@ |
{ |
let link = event.target; |
while (link && link != messageElement && link.localName != "a") |
link = link.parentNode; |
if (!link) |
return; |
event.preventDefault(); |
event.stopPropagation(); |
- chrome.tabs.create({url: link.href}); |
+ browser.tabs.create({url: link.href}); |
}); |
}); |
let notificationElement = document.getElementById("notification"); |
notificationElement.className = notification.type; |
notificationElement.hidden = false; |
notificationElement.addEventListener("click", event => |
{ |