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: Fix lint error and simplify code Created Sept. 24, 2017, 10:34 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
« 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
@@ -10,29 +10,27 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-/* global i18n */
+/* global i18n, getPref, togglePref */
"use strict";
(function()
{
const {require} = ext.backgroundPage.getWindow();
- const {getBlockedPerPage} = require("stats");
const {FilterNotifier} = require("filterNotifier");
- const {Prefs} = require("prefs");
- let currentPage;
+ let currentTab;
const shareURL = "https://adblockplus.org/";
let messageMark = {};
let shareLinks = {
facebook: ["https://www.facebook.com/dialog/feed", {
app_id: "475542399197328",
link: shareURL,
redirect_uri: "https://www.facebook.com/",
@@ -73,65 +71,84 @@
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];
+ currentTab = tabs[0];
updateStats();
FilterNotifier.on("filter.hitCount", updateStats);
document.getElementById("stats-container").removeAttribute("hidden");
});
}
function onUnload()
{
FilterNotifier.off("filter.hitCount", updateStats);
}
function updateStats()
{
let statsPage = document.getElementById("stats-page");
- let blockedPage = getBlockedPerPage(currentPage).toLocaleString();
- i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
+ chrome.runtime.sendMessage({
+ type: "stats.getBlockedPerPage",
+ tab: currentTab
+ },
+ blockedPage =>
+ {
+ i18n.setElementText(statsPage, "stats_label_page",
+ [blockedPage.toLocaleString()]);
+ });
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