LEFT | RIGHT |
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 * @see https://adblockplus.org/en/preferences#subscriptions_autoupdate | 83 * @see https://adblockplus.org/en/preferences#subscriptions_autoupdate |
84 * @type {boolean} | 84 * @type {boolean} |
85 */ | 85 */ |
86 defaults.subscriptions_autoupdate = true; | 86 defaults.subscriptions_autoupdate = true; |
87 /** | 87 /** |
88 * @see https://adblockplus.org/en/preferences#subscriptions_exceptionsurl | 88 * @see https://adblockplus.org/en/preferences#subscriptions_exceptionsurl |
89 * @type {string} | 89 * @type {string} |
90 */ | 90 */ |
91 defaults.subscriptions_exceptionsurl = "https://easylist-downloads.adblockplus.o
rg/exceptionrules.txt"; | 91 defaults.subscriptions_exceptionsurl = "https://easylist-downloads.adblockplus.o
rg/exceptionrules.txt"; |
92 /** | 92 /** |
93 * @see https://adblockplus.org/en/preferences#subscriptions_exceptionsurl_priva
cy | 93 * @see https://adblockplus.org/en/preferences#subscriptions_exceptionsurl_priva
cy |
94 * @type {string} | 94 * @type {string} |
95 */ | 95 */ |
96 defaults.subscriptions_exceptionsurl_privacy = "https://easylist-downloads.adblo
ckplus.org/exceptionrules.txt"; | 96 defaults.subscriptions_exceptionsurl_privacy = "https://easylist-downloads.adblo
ckplus.org/exceptionrules-privacy-friendly.txt"; |
97 /** | 97 /** |
98 * @see https://adblockplus.org/en/preferences#subscriptions_antiadblockurl | 98 * @see https://adblockplus.org/en/preferences#subscriptions_antiadblockurl |
99 * @type {string} | 99 * @type {string} |
100 */ | 100 */ |
101 defaults.subscriptions_antiadblockurl = "https://easylist-downloads.adblockplus.
org/antiadblockfilters.txt"; | 101 defaults.subscriptions_antiadblockurl = "https://easylist-downloads.adblockplus.
org/antiadblockfilters.txt"; |
102 /** | 102 /** |
103 * @see https://adblockplus.org/en/preferences#documentation_link | 103 * @see https://adblockplus.org/en/preferences#documentation_link |
104 * @type {string} | 104 * @type {string} |
105 */ | 105 */ |
106 defaults.documentation_link = "https://adblockplus.org/redirect?link=%LINK%&lang
=%LANG%"; | 106 defaults.documentation_link = "https://adblockplus.org/redirect?link=%LINK%&lang
=%LANG%"; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 * | 144 * |
145 * @type {boolean} | 145 * @type {boolean} |
146 */ | 146 */ |
147 defaults.hidePlaceholders = true; | 147 defaults.hidePlaceholders = true; |
148 | 148 |
149 /** | 149 /** |
150 * Whether notification opt-out UI should be shown. | 150 * Whether notification opt-out UI should be shown. |
151 * @type {boolean} | 151 * @type {boolean} |
152 */ | 152 */ |
153 defaults.notifications_showui = false; | 153 defaults.notifications_showui = false; |
154 /** | 154 |
155 * Whether notification about privacy conflict should be shown. | |
156 * @type {boolean} | |
157 */ | |
158 defaults.ui_warn_tracking = true; | |
159 /** | 155 /** |
160 * Determines whether data has been cleaned up after upgrading from the legacy | 156 * Determines whether data has been cleaned up after upgrading from the legacy |
161 * extension on Firefox. | 157 * extension on Firefox. |
162 * | 158 * |
163 * @type {boolean} | 159 * @type {boolean} |
164 */ | 160 */ |
165 defaults.data_cleanup_done = false; | 161 defaults.data_cleanup_done = false; |
166 | 162 |
167 /** | 163 /** |
168 * Notification categories to be ignored. | 164 * Notification categories to be ignored. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return null; | 236 return null; |
241 | 237 |
242 return key.substr(keyPrefix.length); | 238 return key.substr(keyPrefix.length); |
243 } | 239 } |
244 | 240 |
245 function prefToKey(pref) | 241 function prefToKey(pref) |
246 { | 242 { |
247 return keyPrefix + pref; | 243 return keyPrefix + pref; |
248 } | 244 } |
249 | 245 |
| 246 function savePref(pref) |
| 247 { |
| 248 ext.storage.set(prefToKey(pref), overrides[pref]); |
| 249 } |
| 250 |
| 251 let customSave = new Map(); |
| 252 if (require("info").platform == "gecko") |
| 253 { |
| 254 // Saving one storage value causes all others to be saved as well on Gecko. |
| 255 // Make sure that updating ad counter doesn't cause the filters data to be |
| 256 // saved frequently as a side-effect. |
| 257 const MIN_UPDATE_INTERVAL = 60 * 1000; |
| 258 let lastUpdate = -MIN_UPDATE_INTERVAL; |
| 259 let updateScheduled = false; |
| 260 customSave.set("blocked_total", pref => |
| 261 { |
| 262 if (updateScheduled) |
| 263 return; |
| 264 |
| 265 let callback = () => |
| 266 { |
| 267 lastUpdate = performance.now(); |
| 268 updateScheduled = false; |
| 269 savePref(pref); |
| 270 }; |
| 271 |
| 272 let timeElapsed = performance.now() - lastUpdate; |
| 273 if (timeElapsed < MIN_UPDATE_INTERVAL) |
| 274 { |
| 275 setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed); |
| 276 updateScheduled = true; |
| 277 } |
| 278 else |
| 279 callback(); |
| 280 }); |
| 281 } |
| 282 |
250 function addPreference(pref) | 283 function addPreference(pref) |
251 { | 284 { |
252 Object.defineProperty(Prefs, pref, { | 285 Object.defineProperty(Prefs, pref, { |
253 get() { return (pref in overrides ? overrides : defaults)[pref]; }, | 286 get() { return (pref in overrides ? overrides : defaults)[pref]; }, |
254 set(value) | 287 set(value) |
255 { | 288 { |
256 let defaultValue = defaults[pref]; | 289 let defaultValue = defaults[pref]; |
257 | 290 |
258 if (typeof value != typeof defaultValue) | 291 if (typeof value != typeof defaultValue) |
259 throw new Error("Attempt to change preference type"); | 292 throw new Error("Attempt to change preference type"); |
260 | 293 |
261 if (value == defaultValue) | 294 if (value == defaultValue) |
262 { | 295 { |
263 delete overrides[pref]; | 296 delete overrides[pref]; |
264 ext.storage.remove(prefToKey(pref)); | 297 ext.storage.remove(prefToKey(pref)); |
265 } | 298 } |
266 else | 299 else |
267 { | 300 { |
268 overrides[pref] = value; | 301 overrides[pref] = value; |
269 ext.storage.set(prefToKey(pref), value); | 302 (customSave.get(pref) || savePref)(pref); |
270 } | 303 } |
271 }, | 304 }, |
272 enumerable: true | 305 enumerable: true |
273 }); | 306 }); |
274 } | 307 } |
275 | 308 |
276 function init() | 309 function init() |
277 { | 310 { |
278 let prefs = Object.keys(defaults); | 311 let prefs = Object.keys(defaults); |
279 prefs.forEach(addPreference); | 312 prefs.forEach(addPreference); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 eventEmitter.emit(pref); | 364 eventEmitter.emit(pref); |
332 } | 365 } |
333 } | 366 } |
334 }); | 367 }); |
335 } | 368 } |
336 | 369 |
337 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); | 370 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); |
338 } | 371 } |
339 | 372 |
340 init(); | 373 init(); |
LEFT | RIGHT |