From f1a8335955e3e6890701fb88d6cfeda4249728ea Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sat, 3 Apr 2021 19:03:46 +0200 Subject: [PATCH] Update options: restore opt-in for custom sites Synching with Chrome --- background.js | 21 +++++++++++++++++++++ bpc_count_daily_users.js | 3 +++ changelog.txt | 1 + contentScript.js | 4 ++-- manifest.json | 2 +- options/optin/opt-in.js | 20 ++++++++++---------- sites.js | 1 + 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/background.js b/background.js index 1704ab0c..e7139fd6 100644 --- a/background.js +++ b/background.js @@ -1340,6 +1340,27 @@ ext_api.storage.local.get(["optInShown", "customShown"], function (result) { } }); +// restore custom sites opt-in on reload (chrome-only, load upacked) +if (typeof browser !== 'object') { + ext_api.storage.local.get({ + sites: {}, + customOptIn: false + }, function (result) { + let options_restore_custom = Object.values(result.sites).includes('#options_restore_custom'); + if (result.customOptIn && options_restore_custom) { + ext_api.permissions.contains({ + origins: [""] + }, function (result_perm) { + if (!result_perm) { + ext_api.tabs.create({ + url: "options/optin/opt-in.html" + }); + } + }); + } + }); +} + function filterObject(obj, callback) { return Object.fromEntries(Object.entries(obj). filter(([key, val]) => callback(val, key))); diff --git a/bpc_count_daily_users.js b/bpc_count_daily_users.js index 1252c974..1b982955 100644 --- a/bpc_count_daily_users.js +++ b/bpc_count_daily_users.js @@ -16,8 +16,11 @@ function bpc_count_daily_users(dateStr) { let count_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-daily-users/downloads/bpc-daily-users-' + dateStr + '.json'; fetch(count_json, {mode: 'no-cors'}); let count_mobile_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-mobile-daily-users/downloads/bpc-daily-users-' + dateStr + '.json'; + let count_desktop_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-desktop-daily-users/downloads/bpc-daily-users-' + dateStr + '.json'; if (window.navigator && window.navigator.userAgent.match(/(mobile|android)/i)) fetch(count_mobile_json, {mode: 'no-cors'}); + else + fetch(count_desktop_json, {mode: 'no-cors'}); } }); } diff --git a/changelog.txt b/changelog.txt index dfa83fe9..abe6eeb5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ Add Billboard Add La Tribune (France) Add Le Telegramme (France) Fix-update Mexico News Daily +Update options: restore opt-in for custom sites (on reload; Chrome-only) * v2.1.4.0 (2021-03-28) Add Aachener Zeitung (Germany) diff --git a/contentScript.js b/contentScript.js index 5a48ea27..01226e74 100644 --- a/contentScript.js +++ b/contentScript.js @@ -701,8 +701,8 @@ else if (matchDomain("theglobeandmail.com")) { } else if (matchDomain("sofrep.com")) { - const banner = document.getElementById('scrollerCTA'); - removeDOMElement(banner); + let banners = document.querySelectorAll('#scrollerCTA, #botCta'); + removeDOMElement(...banners); } else if (matchDomain("newstatesman.com")) { diff --git a/manifest.json b/manifest.json index 2f0b949a..66fa4ace 100644 --- a/manifest.json +++ b/manifest.json @@ -499,5 +499,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.1.4.4" + "version": "2.1.4.5" } \ No newline at end of file diff --git a/options/optin/opt-in.js b/options/optin/opt-in.js index f393be60..caebdbbe 100644 --- a/options/optin/opt-in.js +++ b/options/optin/opt-in.js @@ -7,9 +7,7 @@ window.addEventListener("load", function () { opt_in_enabled.innerText = result.optIn ? 'YES' : 'NO'; }); - document.getElementById("optin-enable").addEventListener( - "click", - function () { + document.getElementById("optin-enable").addEventListener("click", function () { ext_api.storage.local.set({ "optIn": true, "optInShown": true @@ -17,9 +15,7 @@ window.addEventListener("load", function () { opt_in_enabled.innerText = 'YES'; }); - document.getElementById("optin-disable").addEventListener( - "click", - function () { + document.getElementById("optin-disable").addEventListener("click", function () { ext_api.storage.local.set({ "optIn": false, "optInShown": true @@ -27,9 +23,7 @@ window.addEventListener("load", function () { opt_in_enabled.innerText = 'NO'; }); - document.getElementById("button-close").addEventListener( - "click", - function () { + document.getElementById("button-close").addEventListener("click", function () { ext_api.storage.local.set({ "optInShown": true, "customShown": true @@ -54,6 +48,9 @@ window.addEventListener("load", function () { }, function (granted) { if (granted) { custom_enabled.innerText = 'YES'; + ext_api.storage.local.set({ + "customOptIn": true + }); } else { custom_enabled.innerText = 'NO'; } @@ -69,7 +66,10 @@ window.addEventListener("load", function () { }, function (removed) { if (removed) { custom_enabled.innerText = 'NO'; - } else {} + ext_api.storage.local.set({ + "customOptIn": false + }); + } ext_api.storage.local.set({ "customShown": true }); diff --git a/sites.js b/sites.js index 5dac87ad..d56055b1 100644 --- a/sites.js +++ b/sites.js @@ -296,6 +296,7 @@ var defaultSites = "TribDss": "tribdss.com", "* BPC settings": "###", "Show options on update": "#options_on_update", + "Restore opt-in for custom sites (on reload; Chrome-only)": "#options_restore_custom", "The Wall Street Journal - no Googlebot (http error 500)": "#options_disable_gb_wsj" }