OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 16 matching lines...) Expand all Loading... |
27 let messageMark = {}; | 27 let messageMark = {}; |
28 let shareLinks = { | 28 let shareLinks = { |
29 facebook: ["https://www.facebook.com/dialog/feed", { | 29 facebook: ["https://www.facebook.com/dialog/feed", { |
30 app_id: "475542399197328", | 30 app_id: "475542399197328", |
31 link: shareURL, | 31 link: shareURL, |
32 redirect_uri: "https://www.facebook.com/", | 32 redirect_uri: "https://www.facebook.com/", |
33 ref: "adcounter", | 33 ref: "adcounter", |
34 name: messageMark, | 34 name: messageMark, |
35 actions: JSON.stringify([ | 35 actions: JSON.stringify([ |
36 { | 36 { |
37 name: chrome.i18n.getMessage("stats_share_download"), | 37 name: browser.i18n.getMessage("stats_share_download"), |
38 link: shareURL | 38 link: shareURL |
39 } | 39 } |
40 ]) | 40 ]) |
41 }], | 41 }], |
42 gplus: ["https://plus.google.com/share", { | 42 gplus: ["https://plus.google.com/share", { |
43 url: shareURL | 43 url: shareURL |
44 }], | 44 }], |
45 twitter: ["https://twitter.com/intent/tweet", { | 45 twitter: ["https://twitter.com/intent/tweet", { |
46 text: messageMark, | 46 text: messageMark, |
47 url: shareURL, | 47 url: shareURL, |
48 via: "AdblockPlus" | 48 via: "AdblockPlus" |
49 }] | 49 }] |
50 }; | 50 }; |
51 | 51 |
52 function createShareLink(network, blockedCount) | 52 function createShareLink(network, blockedCount) |
53 { | 53 { |
54 let url = shareLinks[network][0]; | 54 let url = shareLinks[network][0]; |
55 let params = shareLinks[network][1]; | 55 let params = shareLinks[network][1]; |
56 | 56 |
57 let querystring = []; | 57 let querystring = []; |
58 for (let key in params) | 58 for (let key in params) |
59 { | 59 { |
60 let value = params[key]; | 60 let value = params[key]; |
61 if (value == messageMark) | 61 if (value == messageMark) |
62 value = chrome.i18n.getMessage("stats_share_message", blockedCount); | 62 value = browser.i18n.getMessage("stats_share_message", blockedCount); |
63 querystring.push( | 63 querystring.push( |
64 encodeURIComponent(key) + "=" + encodeURIComponent(value) | 64 encodeURIComponent(key) + "=" + encodeURIComponent(value) |
65 ); | 65 ); |
66 } | 66 } |
67 return url + "?" + querystring.join("&"); | 67 return url + "?" + querystring.join("&"); |
68 } | 68 } |
69 | 69 |
70 function onLoad() | 70 function onLoad() |
71 { | 71 { |
72 document.getElementById("share-box").addEventListener("click", share, | 72 document.getElementById("share-box").addEventListener("click", share, |
73 false); | 73 false); |
74 let showIconNumber = document.getElementById("show-iconnumber"); | 74 let showIconNumber = document.getElementById("show-iconnumber"); |
75 getPref("show_statsinicon", showStatsInIcon => | 75 getPref("show_statsinicon", showStatsInIcon => |
76 { | 76 { |
77 showIconNumber.setAttribute("aria-checked", showStatsInIcon); | 77 showIconNumber.setAttribute("aria-checked", showStatsInIcon); |
78 }); | 78 }); |
79 showIconNumber.addEventListener("click", toggleIconNumber, false); | 79 showIconNumber.addEventListener("click", toggleIconNumber, false); |
80 document.querySelector("label[for='show-iconnumber']").addEventListener( | 80 document.querySelector("label[for='show-iconnumber']").addEventListener( |
81 "click", toggleIconNumber, false | 81 "click", toggleIconNumber, false |
82 ); | 82 ); |
83 | 83 |
84 // Update stats | 84 // Update stats |
85 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => | 85 browser.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
86 { | 86 { |
87 currentTab = tabs[0]; | 87 currentTab = tabs[0]; |
88 updateStats(); | 88 updateStats(); |
89 | 89 |
90 document.getElementById("stats-container").removeAttribute("hidden"); | 90 document.getElementById("stats-container").removeAttribute("hidden"); |
91 }); | 91 }); |
92 } | 92 } |
93 | 93 |
94 function updateStats() | 94 function updateStats() |
95 { | 95 { |
96 let statsPage = document.getElementById("stats-page"); | 96 let statsPage = document.getElementById("stats-page"); |
97 chrome.runtime.sendMessage({ | 97 browser.runtime.sendMessage({ |
98 type: "stats.getBlockedPerPage", | 98 type: "stats.getBlockedPerPage", |
99 tab: currentTab | 99 tab: currentTab |
100 }, | 100 }, |
101 blockedPage => | 101 blockedPage => |
102 { | 102 { |
103 ext.i18n.setElementText(statsPage, "stats_label_page", | 103 ext.i18n.setElementText(statsPage, "stats_label_page", |
104 [blockedPage.toLocaleString()]); | 104 [blockedPage.toLocaleString()]); |
105 }); | 105 }); |
106 | 106 |
107 let statsTotal = document.getElementById("stats-total"); | 107 let statsTotal = document.getElementById("stats-total"); |
108 getPref("blocked_total", blockedTotal => | 108 getPref("blocked_total", blockedTotal => |
109 { | 109 { |
110 ext.i18n.setElementText(statsTotal, "stats_label_total", | 110 ext.i18n.setElementText(statsTotal, "stats_label_total", |
111 [blockedTotal.toLocaleString()]); | 111 [blockedTotal.toLocaleString()]); |
112 }); | 112 }); |
113 } | 113 } |
114 | 114 |
115 function share(ev) | 115 function share(ev) |
116 { | 116 { |
117 getPref("blocked_total", blockedTotal => | 117 getPref("blocked_total", blockedTotal => |
118 { | 118 { |
119 // Easter Egg | 119 // Easter Egg |
120 if (blockedTotal <= 9000 || blockedTotal >= 10000) | 120 if (blockedTotal <= 9000 || blockedTotal >= 10000) |
121 { | 121 { |
122 blockedTotal = blockedTotal.toLocaleString(); | 122 blockedTotal = blockedTotal.toLocaleString(); |
123 } | 123 } |
124 else | 124 else |
125 { | 125 { |
126 blockedTotal = chrome.i18n.getMessage("stats_over", | 126 blockedTotal = browser.i18n.getMessage("stats_over", |
127 (9000).toLocaleString()); | 127 (9000).toLocaleString()); |
128 } | 128 } |
129 | 129 |
130 chrome.tabs.create({ | 130 browser.tabs.create({ |
131 url: createShareLink(ev.target.dataset.social, blockedTotal) | 131 url: createShareLink(ev.target.dataset.social, blockedTotal) |
132 }); | 132 }); |
133 }); | 133 }); |
134 } | 134 } |
135 | 135 |
136 function toggleIconNumber() | 136 function toggleIconNumber() |
137 { | 137 { |
138 togglePref("show_statsinicon", showStatsInIcon => | 138 togglePref("show_statsinicon", showStatsInIcon => |
139 { | 139 { |
140 document.getElementById("show-iconnumber").setAttribute( | 140 document.getElementById("show-iconnumber").setAttribute( |
141 "aria-checked", showStatsInIcon | 141 "aria-checked", showStatsInIcon |
142 ); | 142 ); |
143 }); | 143 }); |
144 } | 144 } |
145 | 145 |
146 document.addEventListener("DOMContentLoaded", onLoad, false); | 146 document.addEventListener("DOMContentLoaded", onLoad, false); |
147 }()); | 147 }()); |
OLD | NEW |