diff --git a/README.md b/README.md index 622f587e..2de60f9b 100644 --- a/README.md +++ b/README.md @@ -659,11 +659,7 @@ _* free articles only._ ### Sites with limited number of free articles 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. - +Click on the BPC-icon and then 'clear cookies'-button in the popup (for unsupported sites grant permission for domain). If removing the cookies works you can also add the site as a custom site. ### New site requests diff --git a/changelog.txt b/changelog.txt index 4f8d0c2d..f712866a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ Post-release Add Capital Gazette (local USA) Add Il Foglio (Italy) Fix group Tribune Publishing Company (js) +Update popup (permission to clear cookies) * v2.4.9.0 (2021-12-26) Add El Espectador (Colombia) diff --git a/manifest.json b/manifest.json index 82735319..8ed32810 100644 --- a/manifest.json +++ b/manifest.json @@ -600,5 +600,5 @@ "*://*.wsj.net/*", "*://*.zephr.com/*" ], - "version": "2.4.9.2" + "version": "2.4.9.3" } diff --git a/options/clearCookies.js b/options/clearCookies.js index d1f4282e..7b2bd009 100644 --- a/options/clearCookies.js +++ b/options/clearCookies.js @@ -3,12 +3,13 @@ var ext_api = (typeof browser === 'object') ? browser : chrome; window.localStorage.clear(); sessionStorage.clear(); +var cookie_domain = document.domain.replace(/^(www|amp(\d|html)?|m|wap)\./, ''); // send domain to background.js (to clear cookies) ext_api.runtime.sendMessage({ - domain: document.domain + domain: cookie_domain }); -let msg = "Cookies (and local storage) removed from " + document.domain; +var msg = "Cookies (and local storage) removed from " + cookie_domain; showMessage(msg, 2000); function showMessage(msg, duration) { diff --git a/options/popup.js b/options/popup.js index c53565db..235e7f59 100644 --- a/options/popup.js +++ b/options/popup.js @@ -1,38 +1,60 @@ var ext_api = (typeof browser === 'object') ? browser : chrome; function popup_show_toggle(domain, enabled) { - if (domain) { - var site_switch_span = document.getElementById('site_switch_span'); - let labelEl = document.createElement('label'); - labelEl.setAttribute('class', 'switch'); - let inputEl = document.createElement('input'); - inputEl.setAttribute('id', 'site_switch'); - inputEl.setAttribute('type', 'checkbox'); - if (enabled) - inputEl.setAttribute('checked', true); - labelEl.appendChild(inputEl); - let spanEl = document.createElement('span'); - spanEl.setAttribute('class', 'slider round'); - spanEl.setAttribute('title', 'en/disable current site in BPC'); - labelEl.appendChild(spanEl); - site_switch_span.appendChild(labelEl); - document.getElementById("site_switch").addEventListener('click', function () { - ext_api.runtime.sendMessage({request: 'site_switch'}); - //open(location).close(); - }); - } + if (domain) { + var site_switch_span = document.getElementById('site_switch_span'); + let labelEl = document.createElement('label'); + labelEl.setAttribute('class', 'switch'); + let inputEl = document.createElement('input'); + inputEl.setAttribute('id', 'site_switch'); + inputEl.setAttribute('type', 'checkbox'); + if (enabled) + inputEl.setAttribute('checked', true); + labelEl.appendChild(inputEl); + let spanEl = document.createElement('span'); + spanEl.setAttribute('class', 'slider round'); + spanEl.setAttribute('title', 'en/disable current site in BPC'); + labelEl.appendChild(spanEl); + site_switch_span.appendChild(labelEl); + document.getElementById("site_switch").addEventListener('click', function () { + ext_api.runtime.sendMessage({ + request: 'site_switch' + }); + //open(location).close(); + }); + } }; -ext_api.runtime.sendMessage({request: 'popup_show_toggle'}); +ext_api.runtime.sendMessage({ + request: 'popup_show_toggle' +}); ext_api.runtime.onMessage.addListener(function (message, sender) { - if (message.msg === 'popup_show_toggle' && message.data) { - popup_show_toggle(message.data.domain, message.data.enabled) - } + if (message.msg === 'popup_show_toggle' && message.data) { + popup_show_toggle(message.data.domain, message.data.enabled) + } +}); + +var cookie_domain; +ext_api.tabs.query({ + active: true, + currentWindow: true +}, function (tabs) { + if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + let hostname = new URL(tabs[0].url).hostname; + cookie_domain = hostname.replace(/^(www|amp(\d|html)?|m|wap)\./, ''); + } }); document.getElementById("clear_cookies").addEventListener('click', function () { - ext_api.runtime.sendMessage({request: 'clear_cookies'}); - //open(location).close(); + ext_api.permissions.request({ + origins: ["*://*." + cookie_domain + "/*"] + }, function (granted) { + if (granted) { + ext_api.runtime.sendMessage({ + request: 'clear_cookies' + }); + } + }); }); function closeButton() {