Update popup (permission to clear cookies)

This commit is contained in:
magnolia1234 2021-12-30 20:36:01 +01:00
parent 902be2ffa6
commit ea260f62fc
5 changed files with 54 additions and 34 deletions

View file

@ -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

View file

@ -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)

View file

@ -600,5 +600,5 @@
"*://*.wsj.net/*",
"*://*.zephr.com/*"
],
"version": "2.4.9.2"
"version": "2.4.9.3"
}

View file

@ -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) {

View file

@ -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() {