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

Unified Diff: stats.js

Issue 29532767: Issue 5593 - Use messaging in popup for prefs, whitelisting, and stats (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Check for page ready again after adding listener Created Sept. 19, 2017, 8:54 a.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
« popup.js ('K') | « skin/popup.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: stats.js
===================================================================
--- a/stats.js
+++ b/stats.js
@@ -20,17 +20,16 @@
"use strict";
(function()
{
const {require} = ext.backgroundPage.getWindow();
const {getBlockedPerPage} = require("stats");
const {FilterNotifier} = require("filterNotifier");
- const {Prefs} = require("prefs");
let currentPage;
const shareURL = "https://adblockplus.org/";
let messageMark = {};
let shareLinks = {
facebook: ["https://www.facebook.com/dialog/feed", {
app_id: "475542399197328",
@@ -73,26 +72,29 @@
return url + "?" + querystring.join("&");
}
function onLoad()
{
document.getElementById("share-box").addEventListener("click", share,
false);
let showIconNumber = document.getElementById("show-iconnumber");
- showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon);
+ getPref("show_statsinicon", showStatsInIcon =>
+ {
+ showIconNumber.setAttribute("aria-checked", showStatsInIcon);
+ });
showIconNumber.addEventListener("click", toggleIconNumber, false);
document.querySelector("label[for='show-iconnumber']").addEventListener(
"click", toggleIconNumber, false
);
// Update stats
- ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
+ chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
{
- currentPage = pages[0];
+ currentPage = createPageObject(tabs[0]);
updateStats();
FilterNotifier.on("filter.hitCount", updateStats);
document.getElementById("stats-container").removeAttribute("hidden");
});
}
@@ -103,35 +105,44 @@
function updateStats()
{
let statsPage = document.getElementById("stats-page");
let blockedPage = getBlockedPerPage(currentPage).toLocaleString();
i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
let statsTotal = document.getElementById("stats-total");
- let blockedTotal = Prefs.blocked_total.toLocaleString();
- i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
+ getPref("blocked_total", blockedTotal =>
+ {
+ i18n.setElementText(statsTotal, "stats_label_total",
+ [blockedTotal.toLocaleString()]);
+ });
}
function share(ev)
{
- // Easter Egg
- let blocked = Prefs.blocked_total;
- if (blocked <= 9000 || blocked >= 10000)
- blocked = blocked.toLocaleString();
- else
- blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
+ getPref("blocked_total", blockedTotal =>
+ {
+ // Easter Egg
+ if (blockedTotal <= 9000 || blockedTotal >= 10000)
+ blockedTotal = blockedTotal.toLocaleString();
+ else
+ blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString());
- ext.pages.open(createShareLink(ev.target.dataset.social, blocked));
+ chrome.tabs.create({
+ url: createShareLink(ev.target.dataset.social, blockedTotal)
+ });
+ });
}
function toggleIconNumber()
{
- Prefs.show_statsinicon = !Prefs.show_statsinicon;
- document.getElementById("show-iconnumber").setAttribute(
- "aria-checked", Prefs.show_statsinicon
- );
+ togglePref("show_statsinicon", showStatsInIcon =>
+ {
+ document.getElementById("show-iconnumber").setAttribute(
+ "aria-checked", showStatsInIcon
+ );
+ });
}
document.addEventListener("DOMContentLoaded", onLoad, false);
window.addEventListener("unload", onUnload, false);
}());
« popup.js ('K') | « skin/popup.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld