From 9c721e4ef496415a4120de29db870f949c2695d1 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Mon, 12 Oct 2020 17:31:51 +0200 Subject: [PATCH] Option to clear cookies & local storage (of site) Plus fix-update MIT Sloan Management Review (modal) --- README.md | 6 +++--- background.js | 50 ++++++++++++++++++++++++++++++++++++++++++------ changelog.txt | 2 ++ clearCookies.js | 22 +++++++++++++++++++++ contentScript.js | 2 +- lp/manifest.json | 3 +-- manifest.json | 2 +- popup.html | 3 ++- popup.js | 5 +++++ 9 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 clearCookies.js diff --git a/README.md b/README.md index 33f4f1b..2536308 100644 --- a/README.md +++ b/README.md @@ -321,14 +321,14 @@ For example: _*free articles only._ ### Sites with limited number of free articles -The free article limit can normally be bypassed by removing cookies for the site.* +The free article limit can normally be bypassed by removing cookies for the site. +Click on the BPC-icon and then 'clear cookies' button in the popup. +For user with the limited permissions BPC-version this will only work for supported sites; for other sites use: 1. Install the add-on [Cookie Remover](https://addons.mozilla.org/en-US/firefox/addon/cookie-remover/). 2. When coming across a paywall click the cookie icon to remove the cookies then refresh the page. If removing the cookies works you can also add the site as a custom site. -_*May not always succeed_ - ### New site requests You can submit a request for a new website [here](https://bitbucket.org/magnolia1234/bypass-paywalls-firefox-clean/issues?status=new&status=open). Please read the following instructions and share your results for a quicker process. diff --git a/background.js b/background.js index 76852c3..6d15ad0 100644 --- a/background.js +++ b/background.js @@ -747,15 +747,53 @@ ext_api.webRequest.onCompleted.addListener(function (details) { urls: [""] }); +function clear_cookies() { + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { + ext_api.tabs.executeScript({ + file: 'clearCookies.js', + runAt: 'document_start' + }, function (res) { + if (ext_api.runtime.lastError || res[0]) { + return; + } + }); + ext_api.tabs.update(tabs[0].id, { + url: tabs[0].url + }); + } + }); +} + ext_api.runtime.onMessage.addListener(function (message, sender) { // check storage for opt in - ext_api.storage.sync.get("optIn", function (result) { - // send message back to content script with value of opt in - ext_api.tabs.sendMessage( - sender.tab.id, { - "optIn": (true == result.optIn) + if (message.request === 'optin') { + ext_api.storage.sync.get("optIn", function (result) { + // send message back to content script with value of opt in + ext_api.tabs.sendMessage( + sender.tab.id, { + "optIn": (true == result.optIn) + }); }); - }); + } + // clear cookies for domain + if (message.domain) { + var domainVar = message.domain.replace('www.', ''); + ext_api.cookies.getAll({ + domain: domainVar + }, function (cookies) { + for (let cookie of cookies) { + var cookie_domain = cookie.domain; + ext_api.cookies.remove({ + url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path, + name: cookie.name + }); + } + }); + } }); // show the tab if we haven't registered the user reacting to the prompt. diff --git a/changelog.txt b/changelog.txt index 7792105..d14fbfd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,8 @@ Changelog Bypass Paywalls Clean - Firefox Post-release +Fix-update MIT Sloan Management Review (modal) +Option to clear cookies & local storage (of site) * v1.9.0.0 (2020-10-11) Add Slate diff --git a/clearCookies.js b/clearCookies.js new file mode 100644 index 0000000..6cf6fe1 --- /dev/null +++ b/clearCookies.js @@ -0,0 +1,22 @@ +var ext_api = (typeof browser === 'object') ? browser : chrome; + +window.localStorage.clear(); +sessionStorage.clear(); + +// send domain to background.js (to clear cookies) +ext_api.runtime.sendMessage({ + domain: document.domain +}); + +let msg = "Cookies (and local storage) removed from " + document.domain; +showMessage(msg, 2000); + +function showMessage(msg, duration) { + var el = document.createElement("div"); + el.setAttribute("style", "position:fixed;top:40%;left:40%;z-index:99;padding:4px;font-family: Arial, sans-serif;font-size:18px;color:white;background-color:blue;"); + el.innerText = msg; + setTimeout(function () { + el.parentNode.removeChild(el); + }, duration); + document.body.appendChild(el); +} \ No newline at end of file diff --git a/contentScript.js b/contentScript.js index ed11bc3..0eb11e3 100644 --- a/contentScript.js +++ b/contentScript.js @@ -39,7 +39,7 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { }); // ask for opt-in confirmation -ext_api.runtime.sendMessage({}); +ext_api.runtime.sendMessage({request: 'optin'}); // Content workarounds/domain diff --git a/lp/manifest.json b/lp/manifest.json index adcb1f3..3fdefcf 100644 --- a/lp/manifest.json +++ b/lp/manifest.json @@ -299,7 +299,6 @@ "*://*.jsdelivr.net/*", "*://*.lightboxcdn.com/*", "*://*.lp4.io/*", - "*://*.netdna-ssl.com/*", "*://*.nyt.com/*", "*://*.pasedigital.cl/*", "*://*.pelcro.com/*", @@ -319,5 +318,5 @@ "webRequest", "webRequestBlocking" ], - "version": "1.9.0.0" + "version": "1.9.0.1" } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 3dabc39..9f25347 100644 --- a/manifest.json +++ b/manifest.json @@ -40,5 +40,5 @@ "webRequest", "webRequestBlocking" ], - "version": "1.9.0.0" + "version": "1.9.0.1" } \ No newline at end of file diff --git a/popup.html b/popup.html index b6a724f..971c5c9 100644 --- a/popup.html +++ b/popup.html @@ -8,7 +8,8 @@
Options | Custom | BitBucket | - + | +
Changelog diff --git a/popup.js b/popup.js index 56f9dee..cf282a1 100644 --- a/popup.js +++ b/popup.js @@ -1,4 +1,9 @@ var ext_api = chrome || browser; document.getElementById("site_switch").addEventListener('click', function() { ext_api.extension.getBackgroundPage().site_switch(); + window.close(); +}); +document.getElementById("clear_cookies").addEventListener('click', function() { + ext_api.extension.getBackgroundPage().clear_cookies(); + window.close(); });