From f5cbd129df892cdeae0bbefe573e1425e369fbd7 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sun, 16 Aug 2020 09:27:33 +0200 Subject: [PATCH] Update custom sites (auto-enable in options) --- README.md | 13 ++++++++----- background.js | 34 ++++++++++++++++++++++++++++++++++ options_custom.html | 7 +++---- options_custom.js | 5 ++--- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0b90453..db34a0e 100644 --- a/README.md +++ b/README.md @@ -311,22 +311,25 @@ You can submit a request for a new website [here](https://bitbucket.org/magnolia Please read the following instructions and share your results for a quicker process. Remember to check the [previous requests](https://bitbucket.org/magnolia1234/bypass-paywalls-firefox-clean/issues) before asking for a new website. 1. Visit an article on the site you want to bypass the paywall for and copy the article title. -2. Open up a new incognito window (Ctrl+Shift+N) and paste the article title into Google. +2. Open up a new incognito window (Ctrl+Shift+P) and paste the article title into Google. 3. Click on the same article from the Google search results page. Or you can: -4. Disable javascript on the website by clicking the button right icon on the uBlock panel. +4. Disable javascript on the website by clicking the button right icon on the uBlock Origin panel. 5. Refresh the page. ### Add custom site Add your own custom site (also for testing). Check 'Options'-link in popup-menu and go to custom sites. -By default sites' cookies are removed after page loads (to bypass article limit). +Make sure the (new) site is checked under Options. +By default sites' cookies/local storage are removed after page loads (to bypass article limit). Also you can enable Googlebot user-agent or disable Javascript for (sub)domain(s)/external sources. ### Troubleshooting -* This add-on works best alongside [uBlock Origin](https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/). +* This add-on works best alongside the adblocker [uBlock Origin](https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/). * If a site doesn't work try turning off uBlock and refreshing. -* If you live in the EU, also consider installing the extension [I don't care about cookies](https://addons.mozilla.org/en-US/firefox/addon/i-dont-care-about-cookies) in order to remove cookie warnings. * Make sure the (new) site is checked under Options. +* You will be logged out for most of the sites you have checked. +* If you live in the EU, also consider installing the extension [I don't care about cookies](https://addons.mozilla.org/en-US/firefox/addon/i-dont-care-about-cookies) in order to remove cookie warnings. + ### Changelog-releases * Visit the [changelog page](https://bitbucket.org/magnolia1234/bypass-paywalls-firefox-clean/src/master/changelog.txt). diff --git a/background.js b/background.js index 4bc8d64..cb4d1cd 100644 --- a/background.js +++ b/background.js @@ -304,6 +304,28 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) { } if (key === 'sites_custom') { var sites_custom = storageChange.newValue; + var sites_custom_old = storageChange.oldValue; + + // add/remove custom sites in options + var sites_custom_added = Object.keys(sites_custom).filter(x => !Object.keys(sites_custom_old).includes(x) && !defaultSites.hasOwnProperty(x)); + var sites_custom_removed = Object.keys(sites_custom_old).filter(x => !Object.keys(sites_custom).includes(x) && !defaultSites.hasOwnProperty(x)); + + chrome.storage.sync.get({ + sites: {} + }, function (items) { + var sites = items.sites; + for (var key of sites_custom_added) + sites[key] = sites_custom[key].domain; + for (var key of sites_custom_removed) + delete sites[key]; + + chrome.storage.sync.set({ + sites: sites + }, function () { + true; + }); + }); + use_google_bot = use_google_bot_default.slice(); block_js_custom = []; block_js_custom_ext = []; @@ -323,6 +345,18 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) { // reset disableJavascriptOnListedSites eventListener ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites); ext_api.webRequest.handlerBehaviorChanged(); + + // Refresh the current tab + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs[0].url && tabs[0].url.indexOf("http") !== -1) { + ext_api.tabs.update(tabs[0].id, { + url: tabs[0].url + }); + } + }); } } }); diff --git a/options_custom.html b/options_custom.html index 1643fe6..2cbd44a 100644 --- a/options_custom.html +++ b/options_custom.html @@ -16,8 +16,8 @@

Custom Sites

- To add new site, enter a unique title/domain (without www.) and select options for googlebot/block javascript (block on (sub)domain of site and/or external domains). - Then enable your new site in options (cookies will be removed by default). + To add new site, enter a unique title/domain (without www.) and select options for Googlebot/block Javascript (block on (sub)domain(s) of site and/or external domains).
+ Custom sites are enabled automatically in options (cookies will be removed by default).

@@ -29,8 +29,7 @@

List of custom sites

- Disable deleted sites in options. -

+

diff --git a/options_custom.js b/options_custom.js index 2cb0c5f..7e33575 100644 --- a/options_custom.js +++ b/options_custom.js @@ -124,7 +124,7 @@ function add_options() { }, function () { // Update status to let user know new custom site was added. var status_add = document.getElementById('status_add'); - status_add.textContent = 'Site added. Also enable site in options (save).'; + status_add.textContent = 'Site added.'; setTimeout(function () { //status.textContent = ''; renderOptions(); @@ -151,7 +151,7 @@ function delete_options() { }, function () { // Update status to let user know custom site was deleted. var status_delete = document.getElementById('status_delete'); - status_delete.textContent = 'Site deleted. Also disable site in options (save).'; + status_delete.textContent = 'Site deleted.'; setTimeout(function () { //status.textContent = ''; renderOptions(); @@ -221,7 +221,6 @@ function renderOptions() { selectEl.add(optionEl); } labelEl.appendChild(selectEl); - //labelEl.appendChild(document.createTextNode('')); custom_sitesEl.appendChild(labelEl); });