Repository restored

This commit is contained in:
2026-01-04 21:17:51 +01:00
commit e4d67b962a
45 changed files with 21057 additions and 0 deletions

48
options/clearCookies.js Normal file
View File

@@ -0,0 +1,48 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
try {
window.localStorage.clear();
sessionStorage.clear();
} catch (e) {
console.log(e);
}
var cookie_domain = getCookieDomain(document.domain);
// send domain to background.js (to clear cookies)
ext_api.runtime.sendMessage({
request: 'clear_cookies_domain',
data: {
domain: cookie_domain
}
});
function getCookieDomain(hostname) {
let domain = hostname;
let n = 0;
let parts = hostname.split('.');
let str = '_gd' + (new Date()).getTime();
try {
while (n < (parts.length - 1) && document.cookie.indexOf(str + '=' + str) == -1) {
domain = parts.slice(-1 - (++n)).join('.');
document.cookie = str + "=" + str + ";domain=" + domain + ";";
}
document.cookie = str + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";";
} catch (e) {
console.log(e);
}
return domain;
}
var msg = "Cookies (and local storage) removed from " + cookie_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 || document.head || document.documentElement).appendChild(el);
}

7
options/optin/opt-in.css Normal file
View File

@@ -0,0 +1,7 @@
html, body {
padding-left: 0.5em;
padding-right: 0.5em;
}
button {
margin: 0.2em 0.2em 0.5em 0;
}

64
options/optin/opt-in.html Normal file
View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bypass Paywalls Clean (setCookie, custom sites & check update opt-in)</title>
<link rel="stylesheet" href="../options_all.css"/>
<link rel="stylesheet" href="opt-in.css"/>
<script src="opt-in.js"></script>
</head>
<body>
<div>
<p><strong>Bypass Paywalls Clean<br> - setCookie, custom sites & check update opt-in</strong></p>
</div>
</div>
<div id="opt-in-prompt">
<p><strong>setCookie opt-in</strong></p>
<p>For some sites a necessary cookie has to be set (this cookie doesn't contain any personal information about the user or device):<br><br>
None</p>
<p>setCookie opt-in enabled: <span id="opt-in-enabled"></span></p>
<div id="optin-container">
<button id="optin-enable">Enable</button>
<button id="optin-disable">Disable</button>
</div>
<div id="custom-prompt">
<p><strong>custom sites opt-in</strong></p>
<p>If you want to enable custom sites and also have the option to remove cookies/block general paywall-scripts of 'unlisted' sites:</br>
<p>custom sites enabled: <span id="custom-enabled"></span></p>
<div id="custom-container">
<button id="custom-enable">Enable</button>
<button id="custom-disable">Disable</button>
</div>
<p>You can also just request permissions for the <a href="../options_custom.html">custom sites</a> you added yourself.</p>
</div>
<div id="update-prompt">
<p><strong>check update opt-in</strong></p>
<p>Check for update of version (on startup and when opening options):</br>
<p>check update enabled: <span id="update-enabled"></span></p>
<div id="update-container">
<button id="update-enable">Enable</button>
<button id="update-disable">Disable</button>
</div>
</div>
<div id="counter-prompt">
<p><strong>daily users counter opt-in</strong></p>
<p>Very basic daily users counter (by counting the download of an empty json-file (no personal information is shared)):</br>
<p>daily users counter enabled: <span id="counter-enabled"></span></p>
<div id="custom-container">
<button id="counter-enable">Enable</button>
<button id="counter-disable">Disable</button>
</div>
</div>
<p>
<div style='float:left;padding-bottom:50px'>
<small><button><a href="../options.html" style="text-decoration:none;color:inherit">Options</a></button></small>
<small><button><a href="../options_custom.html" style="text-decoration:none;color:inherit">Custom sites</a></button></small>
<small><button id="button-close">Close</button></small>
</div>
</p>
</body>
</html>

125
options/optin/opt-in.js Normal file
View File

@@ -0,0 +1,125 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
var manifestData = ext_api.runtime.getManifest();
var navigator_ua = navigator.userAgent;
var navigator_ua_mobile = navigator_ua.toLowerCase().includes('mobile');
var yandex_browser = navigator_ua_mobile && (url_loc === 'chrome') && navigator_ua.toLowerCase().includes('yabrowser');
var custom_switch = ((manifestData.optional_permissions && manifestData.optional_permissions.length) || (manifestData.optional_host_permissions && manifestData.optional_host_permissions.length)) && !(navigator_ua_mobile && (url_loc === 'chrome') && !yandex_browser);
window.addEventListener("load", function () {
document.getElementById("button-close").addEventListener("click", function () {
ext_api.storage.local.set({
"optInShown": true,
"customShown": true
});
window.close();
});
var opt_in_enabled = document.getElementById('opt-in-enabled');
ext_api.storage.local.get("optIn", function (result) {
opt_in_enabled.innerText = result.optIn ? 'YES' : 'NO';
});
document.getElementById("optin-enable").addEventListener("click", function () {
ext_api.storage.local.set({
"optIn": true,
"optInShown": true
});
opt_in_enabled.innerText = 'YES';
});
document.getElementById("optin-disable").addEventListener("click", function () {
ext_api.storage.local.set({
"optIn": false,
"optInShown": true
});
opt_in_enabled.innerText = 'NO';
});
var custom_enabled = document.getElementById('custom-enabled');
ext_api.permissions.contains({
origins: ["*://*/*"]
}, function (result) {
if (result) {
custom_enabled.innerText = 'YES';
} else {
custom_enabled.innerText = 'NO';
}
});
if (custom_switch) {
document.querySelector('#custom-enable').addEventListener('click', function (event) {
ext_api.permissions.request({
origins: ["*://*/*"]
}, function (granted) {
if (granted) {
custom_enabled.innerText = 'YES';
ext_api.storage.local.set({
"customOptIn": true
});
} else {
custom_enabled.innerText = 'NO';
}
ext_api.storage.local.set({
"customShown": true
});
});
});
document.querySelector('#custom-disable').addEventListener('click', function (event) {
ext_api.permissions.remove({
origins: ["*://*/*", "<all_urls>"]
}, function (removed) {
if (removed) {
custom_enabled.innerText = 'NO';
ext_api.storage.local.set({
"customOptIn": false
});
}
ext_api.storage.local.set({
"customShown": true
});
});
});
}// custom_switch
var update_enabled = document.getElementById('update-enabled');
ext_api.storage.local.get({optInUpdate: true}, function (result) {
update_enabled.innerText = result.optInUpdate ? 'YES' : 'NO';
});
document.getElementById("update-enable").addEventListener("click", function () {
ext_api.storage.local.set({
"optInUpdate": true
});
update_enabled.innerText = 'YES';
});
document.getElementById("update-disable").addEventListener("click", function () {
ext_api.storage.local.set({
"optInUpdate": false
});
update_enabled.innerText = 'NO';
});
var counter_enabled = document.getElementById('counter-enabled');
ext_api.storage.local.get({counter: true}, function (result) {
counter_enabled.innerText = result.counter ? 'YES' : 'NO';
});
document.getElementById("counter-enable").addEventListener("click", function () {
ext_api.storage.local.set({
"counter": true
});
counter_enabled.innerText = 'YES';
});
document.getElementById("counter-disable").addEventListener("click", function () {
ext_api.storage.local.set({
"counter": false
});
counter_enabled.innerText = 'NO';
});
});

50
options/options.html Normal file
View File

@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bypass Paywalls Clean Options</title>
<link rel="stylesheet" href="options_all.css"/>
</head>
<body>
<h1 id="top">Options | <small><span id="version"></span><br><span id="version_new"></span></small></h1>
<br><a href="/changelog.txt" target="_blank">Changelog</a>
<div style="width:90%;">
<br>Some selected sites will have their cookies cleared; uncheck the sites (or add to excluded sites) for which you have an account.<br>
If you also want to block general paywall-scripts for unlisted sites you have to opt-in to custom sites (host permission for access to all sites is needed).
<!-- To view some sites (check list) a necessary cookie has to be set (enable this in opt-in). -->
</div>
<br>
<div style='float:left'>
<small><button id="save_top">Save</button></small>
<small><button><a href="options_custom.html" style="text-decoration:none;color:inherit">Custom sites</a></button></small>
<small><button><a href="optin/opt-in.html" style="text-decoration:none;color:inherit">Opt-in</a></button></small>
<small><button id="check_sites_updated">Check updated sites</button></small>
<small><button id="clear_sites_updated">Clear updated sites</button></small>
<small><button><a href="options_excluded.html" style="text-decoration:none;color:inherit">Excluded sites</a></button></small>
<small><button><a href="#save" style="text-decoration:none;color:inherit">Go to bottom</a></button></small>
<input id="search" type="text" size="30" placeholder="Search (domain)name ...">
</div>
<div style="clear:both;"></div>
<strong style="color:red;"><div id="perm-custom"></div></strong>
<div style="clear:both;"></div>
<br>
<div id="status_top"></div>
<div id='bypass_sites'></div>
<br>
<div id="status"></div>
<div id="error"></div>
<span style='float:left;padding-bottom:50px'>
<button id="save">Save</button>
<button id="select-all">Select all</button>
<button id="select-none">Select none</button>
<button><a href="options_custom.html" style="text-decoration:none;color:inherit">Custom sites</a></button>
<button><a href="options_excluded.html" style="text-decoration:none;color:inherit">Excluded sites</a></button>
<button><a href="#top" style="text-decoration:none;color:inherit">Go to top</a></button>
<button id="button-close">Close</button>
</span>
<script src="../sites.js"></script>
<script src="options.js"></script>
<script src="version.js"></script>
</body>
</html>

222
options/options.js Normal file
View File

@@ -0,0 +1,222 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
// Saves options to ext_api.storage
function save_options(event) {
var inputEls = document.querySelectorAll('#bypass_sites input');
var sites = {};
var sites = Array.from(inputEls).reduce(function (memo, inputEl) {
if (inputEl.checked) {
memo[inputEl.dataset.key] = inputEl.dataset.value;
}
return memo;
}, {});
ext_api.storage.local.set({
sites: sites
}, function () {
// Update status to let user know options were saved.
if (event) {
var status_label = document.querySelectorAll('[id^="status"]');
for (let status of status_label) {
status.textContent = 'Options saved.';
setTimeout(function () {
status.textContent = '';
}, 800);
}
}
});
}
// Restores checkbox input states using the preferences stored in ext_api.storage.
function renderOptions() {
var labelEl;
ext_api.storage.local.get({
sites: {},
sites_updated: {},
sites_custom: {},
sites_excluded: []
}, function (items) {
var sites = items.sites;
var sites_updated = filterObject(items.sites_updated, function (val, key) {
return !val.nofix
});
var sites_updated_domains_new = Object.values(sites_updated).filter(x => (x.domain && !defaultSites_domains.includes(x.domain) || x.group)).map(x => x.group ? x.group.filter(y => !defaultSites_domains.includes(y)) : x.domain).flat();
var sites_updated_perm_domains_new = Object.values(sites_updated).filter(x => x.block_host_perm_add).map(x => x.block_host_perm_add.split(',').filter(x => x).map(x => x.trim())).flat();
var sites_custom = items.sites_custom;
var sites_custom_domains_new = Object.values(sites_custom).filter(x => x.domain && !defaultSites_domains.includes(x.domain)).map(x => x.group ? x.group.split(',').map(x => x.trim()) : x.domain).flat();
var sites_custom_perm_domains_new = Object.values(sites_custom).filter(x => x.block_host_perm_add).map(x => x.block_host_perm_add.split(',').filter(x => x).map(x => x.trim())).flat();
var perm_origins = sites_custom_domains_new.concat(sites_updated_domains_new, sites_custom_perm_domains_new, sites_updated_perm_domains_new).filter(x => !x.includes('###')).map(x => '*://*.' + x + '/*');
var perm_custom = document.getElementById('perm-custom');
ext_api.permissions.contains({
origins: perm_origins
}, function (result) {
if (result) {
perm_custom.innerText = '';
} else {
perm_custom.textContent = ">> check host (domain) permissions for custom/updated sites";
}
});
var sites_excluded = items.sites_excluded;
var sitesEl = document.getElementById('bypass_sites');
var site_types = {
"updated": {
sites: sites_updated,
title: '* Updated (new) sites (opt-in to custom sites)',
default_sites: false
},
"default": {
sites: defaultSites,
default_sites: true
},
"custom": {
sites: sites_custom,
default_sites: false
}
};
for (let site_type in site_types) {
labelEl = document.createElement('label');
labelEl.setAttribute('style', ' font-weight: bold;');
if (site_types[site_type].title)
labelEl.appendChild(document.createTextNode(site_types[site_type].title));
sitesEl.appendChild(labelEl);
let sites_arr = site_types[site_type].sites;
for (let key in sites_arr) {
let domain = sites_arr[key]['domain'];
if (!domain || (key === '###_remove_sites') || (!site_types[site_type].default_sites && (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain))))
continue;
labelEl = document.createElement('label');
let inputEl = document.createElement('input');
inputEl.type = 'checkbox';
inputEl.dataset.key = key;
inputEl.dataset.value = domain;
inputEl.checked = Object.keys(sites).some(title => compareKey(title, key)) && !sites_excluded.includes(domain);
if (domain !== '###') {
labelEl.appendChild(inputEl);
} else {
labelEl.appendChild(document.createElement('hr'));
labelEl.setAttribute('style', ' font-weight: bold;');
}
labelEl.appendChild(document.createTextNode(' ' + key));
sitesEl.appendChild(labelEl);
}
}
// excluded
labelEl.appendChild(document.createElement('hr'));
labelEl = document.createElement('label');
labelEl.setAttribute('style', ' font-weight: bold;');
labelEl.appendChild(document.createTextNode('* Excluded Sites (domain(s) ignored when checked in list)'));
sitesEl.appendChild(labelEl);
labelEl = document.createElement('label');
labelEl.appendChild(document.createTextNode(sites_excluded.join()));
sitesEl.appendChild(labelEl);
save_options();
});
}
function handleSearch() {
let search = document.getElementById('search').value.toLowerCase().replace('www.', '');
let listItems = document.querySelectorAll('#bypass_sites > label');
grouped_sites = filterObject(grouped_sites, function (val, key) {
return val.length
});
ext_api.storage.local.get({
sites_updated: {},
sites_custom: {}
}, function (items) {
let sites_updated_groups = filterObject(items.sites_updated, function (val, key) {
return val.group
}, function (val, key) {
return [val.domain, val.group]
});
for (let site in sites_updated_groups) {
let site_default = Object.keys(defaultSites).find(key => compareKey(key, site)) || site;
grouped_sites[site_default] = sites_updated_groups[site];
}
let sites_custom_groups = filterObject(items.sites_custom, function (val, key) {
return val.group
}, function (val, key) {
return [val.domain, val.group.split(',')]
});
for (let site in sites_custom_groups)
grouped_sites[site] = sites_custom_groups[site];
for (let item of listItems) {
let itemText = item.textContent.toLowerCase();
let itemInput = item.querySelector('input[data-value]');
let itemDomain = itemInput ? itemInput.getAttribute('data-value') : '';
let itemGroup = itemDomain ? grouped_sites[itemDomain] : '';
if (itemText.includes(search) || !itemDomain || (itemDomain && (itemDomain.match(/^(###$|#options_[^d])/) || itemDomain.includes(search) || (itemGroup && itemGroup.includes(search)))))
item.style.display = 'block';
else
item.style.display = 'none';
}
});
let selectButtons = document.querySelectorAll('#select-all, #select-none');
for (let elem of selectButtons) {
if (search == '')
elem.style.display = 'block';
else
elem.style.display = 'none';
}
}
function selectAll() {
var inputEls = Array.from(document.querySelectorAll('input[data-key]'));
inputEls = inputEls.filter(function (input) {
return (!input.dataset.value.match(/^#options_(disable|optin)_/));
});
inputEls.forEach(function (inputEl) {
inputEl.checked = true;
});
// Update status to let user know all sites are selected.
var status = document.getElementById('status');
status.textContent = 'All sites selected.';
setTimeout(function () {
status.textContent = '';
}, 800);
}
function selectNone() {
var inputEls = Array.from(document.querySelectorAll('input'));
inputEls.forEach(function(inputEl) {
inputEl.checked = false;
});
}
function closeButton() {
window.close();
}
function check_sites_updated() {
ext_api.runtime.sendMessage({request: 'check_sites_updated'});
location.reload();
}
function clear_sites_updated() {
ext_api.runtime.sendMessage({request: 'clear_sites_updated'});
location.reload();
}
function compareKey(firstStr, secondStr) {
return firstStr.toLowerCase().replace(/\s\(.*\)/, '') === secondStr.toLowerCase().replace(/\s\(.*\)/, '');
}
function filterObject(obj, filterFn, mapFn = function (val, key) {
return [key, val];
}) {
return Object.fromEntries(Object.entries(obj).
filter(([key, val]) => filterFn(val, key)).map(([key, val]) => mapFn(val, key)));
}
document.addEventListener('DOMContentLoaded', renderOptions);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('save_top').addEventListener('click', save_options);
document.getElementById('select-all').addEventListener('click', selectAll);
document.getElementById('select-none').addEventListener('click', selectNone);
document.getElementById('button-close').addEventListener('click', closeButton);
document.getElementById('check_sites_updated').addEventListener('click', check_sites_updated);
document.getElementById('clear_sites_updated').addEventListener('click', clear_sites_updated);
document.getElementById('search').addEventListener('input', handleSearch);

21
options/options_all.css Normal file
View File

@@ -0,0 +1,21 @@
#bypass_sites label, #add_site label, #excluded_sites label {
display: block;
}
body {
font-size: 100%;
}
* {
box-sizing: border-box;
}
a {
color: black;
}
@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
body, button, a, input, select, textarea {
background-color: #313131;
color: #bfbfbf;
}
}

View File

@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bypass Paywalls Clean Options Custom</title>
<link rel="stylesheet" href="options_all.css"/>
</head>
<body>
<h2>Custom Sites</h2>
<div style="width:90%;">
To add a new site, enter an unique title/domain (without www.).<br>
Select options below (<a href="/README.html#add-custom-site" target="_blank">see help</a>); for examples import from online.<br>
Custom sites (new) are enabled automatically in <small><button><a href="options.html" style="text-decoration:none;color:inherit">Options</a></button></small> (cookies will be blocked by default unless you enable allow_cookies).<br>
If you want to use custom sites (for unlisted sites) enable it in <small><button><a href="optin/opt-in.html" style="text-decoration:none;color:inherit">Opt-in</a></button></small>
<strong>Custom sites enabled: <span id="custom-enabled"></span></strong><br>
You can also just request host permissions for the custom sites & post-release added sites (below).<br>
If host permission is missing the icon badge will contain a 'C' (or '+C' if you can import the custom site from online; when no fix X).
<br><br>
</div>
<div id='add_site'></div>
<br>
<div id="status_add"></div>
<span style='float:left;padding-bottom:5px'>
<button id="add">Add</button>
</span>
<div style="clear:both;"></div>
<div>
<h3>List of custom sites</h3>
* already in default list (double domain)
<br>
</div>
<div id='custom_sites'></div>
<br>
<div id="status_delete"></div>
<span style='float:left;padding-bottom:5px'>
<button id="delete">Delete</button>
<button id="edit">Edit (re-Add)</button>
<button id="delete_default">Delete<br>default (*) sites</button>
<button id="perm_request">Request<br>permissions</button>
<button id="perm_remove">Remove<br>permissions</button>
<input id="search" type="text" size="30" placeholder="Search (domain)name ..."><br><br>
permissions granted (for all in custom list + updated): <strong><span id="perm-custom"></span></strong>
</span>
<div style="clear:both;"></div>
<div style="width:90%;">
<h3>Json file</h3>
You can edit/sort the text area and save (only when json-text is valid).
Clear & save to reset. You can also export/import json-text for new installations.
</div>
<br>
<div id='bypass_sites'></div>
<br>
<div id="status"></div>
<div id="error"></div>
<span style='float:left;padding-bottom:50px'>
<button id="save">Save</button>
<button id="sort">Sort</button>
<button id="export">Export</button>
<button id="import">Import file</button>
<button id="import_online">Import from online</button>
<input type="file" id="importInput" accept=".txt" style="display:none"/>
<button><a href="options.html" style="text-decoration:none;color:inherit">Options</a></button>
</span>
<script src="../sites.js"></script>
<script src="options_custom.js"></script>
</body>
</html>

554
options/options_custom.js Normal file
View File

@@ -0,0 +1,554 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
var manifestData = ext_api.runtime.getManifest();
var navigator_ua = navigator.userAgent;
var navigator_ua_mobile = navigator_ua.toLowerCase().includes('mobile');
var yandex_browser = navigator_ua_mobile && (url_loc === 'chrome') && navigator_ua.toLowerCase().includes('yabrowser');
var custom_switch = ((manifestData.optional_permissions && manifestData.optional_permissions.length) || (manifestData.optional_host_permissions && manifestData.optional_host_permissions.length)) && !(navigator_ua_mobile && (url_loc === 'chrome') && !yandex_browser);
var useragent_options = ['', 'googlebot', 'bingbot', 'facebookbot'];
var referer_options = ['', 'facebook', 'google', 'twitter'];
var random_ip_options = ['', 'all', 'eu'];
var add_ext_link_type_options = ['', 'archive.is', '1ft.io', 'google_webcache', 'google_search_tool'];
function capitalize(str) {
return (typeof str === 'string') ? str.charAt(0).toUpperCase() + str.slice(1) : '';
}
function sortJson(json) {
return Object.keys(json)
.sort().reduce(function (Obj, key) {
Obj[key] = json[key];
return Obj;
}, {});
}
function filterObject(obj, filterFn, mapFn = function (val, key) {
return [key, val];
}) {
return Object.fromEntries(Object.entries(obj).
filter(([key, val]) => filterFn(val, key)).map(([key, val]) => mapFn(val, key)));
}
// Saves options to ext_api.storage
function save_options() {
var textareaEl = document.querySelector('#bypass_sites textarea');
var sites_custom = {};
if (textareaEl.value) {
var sites_custom = JSON.parse(textareaEl.value);
sites_custom = filterObject(sites_custom, function (val, key) {
return !(val.add_ext_link && !val.add_ext_link_type)
});
}
ext_api.storage.local.set({
sites_custom: sites_custom
}, function () {
// Update status to let user know custom sites were saved.
var status = document.getElementById('status');
status.textContent = 'Custom sites saved.';
setTimeout(function () {
status.textContent = '';
location.href = 'options.html';
//window.close();
}, 800);
});
}
// Sort json by key in textarea
function sort_options() {
var textareaEl = document.querySelector('#bypass_sites textarea');
var sites_custom = {};
if (textareaEl.value) {
var sites_custom = JSON.parse(textareaEl.value);
var sites_custom_sorted = sortJson(sites_custom);
textareaEl.value = JSON.stringify(sites_custom_sorted);
}
}
// Export custom sites to file
function export_options() {
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
var result = JSON.stringify(items.sites_custom);
var a = document.createElement("a");
var file = new Blob([result], {type: "text/plain"});
a.href = window.URL.createObjectURL(file);
let date = new Date();
let dateStr = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().split("T")[0];
a.download = 'bypass_paywalls_clean_custom_' + dateStr + '.txt';
a.click();
});
}
function import_json(result) {
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
var sites_custom = items.sites_custom;
var sites_custom_new = JSON.parse(result);
var customSitesExt_remove = [];
if (sites_custom_new['###_remove_sites'] && sites_custom_new['###_remove_sites'].cs_code)
customSitesExt_remove = sites_custom_new['###_remove_sites'].cs_code.split(/,\s?/);
for (let site in sites_custom_new) {
let customSite_diff = Object.keys(sites_custom).find(key => sites_custom[key].domain === sites_custom_new[site].domain && key !== site);
if (customSite_diff)
delete sites_custom[customSite_diff];
if (sites_custom_new[site].group) {
let group = sites_custom_new[site].group;
let customSites_group = Object.keys(sites_custom).filter(key => group.split(',').includes(sites_custom[key].domain));
for (let key of customSites_group)
delete sites_custom[key];
}
sites_custom[site] = sites_custom_new[site];
}
sites_custom = filterObject(sites_custom, function (val, key) {
return !(customSitesExt_remove.includes(val.domain) || (val.add_ext_link && !val.add_ext_link_type))
});
ext_api.storage.local.set({
sites_custom: sortJson(sites_custom)
}, function () {
// Update status to let user know custom sites were imported.
var status = document.getElementById('status');
status.textContent = 'Custom sites imported.';
setTimeout(function () {
//status.textContent = '';
importInput.value = '';
renderOptions();
}, 800);
});
});
}
// Import custom sites from online
function import_online_options(e) {
let url = 'https://bitbucket.org/bpc-updates/bpc_updates/downloads/sites_custom.json';
try {
fetch(url)
.then(response => {
if (response.ok) {
response.text().then(result => {
import_json(result);
})
}
});
} catch (err) {
console.log(err);
}
}
// Import custom sites from file
function import_options(e) {
var files = e.target.files;
var reader = new FileReader();
reader.onload = _imp;
reader.readAsText(files[0]);
}
function _imp() {
var result = this.result;
import_json(result);
}
// Add custom site to ext_api.storage
function add_options() {
var inputEls = document.querySelectorAll('#add_site input, #add_site select, #add_site textarea');
var sites_custom = {};
for (let elem of inputEls) {
if (elem.dataset.key === 'title') {
var title = capitalize(elem.value);
if (!title)
break;
sites_custom[title] = {};
} else {
if (elem.dataset.value) {
if (elem.checked)
sites_custom[title][elem.dataset.key] = parseInt(elem.dataset.value);
} else if (elem.value) {
if (['block_host_perm_add', 'group'].includes(elem.dataset.key))
elem.value = elem.value.replace(/,{2,}/g, ',').replace(/(\s|www\.|,$)/g, '');
sites_custom[title][elem.dataset.key] = elem.value;
}
}
}
if (title && sites_custom[title]['domain']) {
sites_custom[title]['domain'] = sites_custom[title]['domain'].replace(/(http(s)?:\/\/|\/$)/g, '').replace(/^(www|amp(html)?|m|wap)(\d)?\./, '').toLowerCase();
// add new site to local storage
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
var sites_custom_old = items.sites_custom;
for (var key in sites_custom) {
sites_custom_old[key] = sites_custom[key];
}
ext_api.storage.local.set({
sites_custom: sites_custom_old
}, function () {
// Update status to let user know new custom site was added.
var status_add = document.getElementById('status_add');
status_add.textContent = 'Site added.';
setTimeout(function () {
//status.textContent = '';
renderOptions();
}, 800);
});
});
}
}
// Delete custom site from ext_api.storage
function delete_options() {
var selectEl = document.querySelector('#custom_sites select');
var sites_custom = {};
var remove_key = selectEl.value;
if (!remove_key)
return false;
// delete site from local storage
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
var sites_custom_old = items.sites_custom;
delete sites_custom_old[remove_key];
ext_api.storage.local.set({
sites_custom: sites_custom_old
}, function () {
// Update status to let user know custom site was deleted.
var status_delete = document.getElementById('status_delete');
status_delete.textContent = 'Site deleted.';
setTimeout(function () {
//status.textContent = '';
renderOptions();
}, 800);
});
});
}
// Delete custom (& default) sites from ext_api.storage
function delete_default_options() {
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
sites_custom = filterObject(items.sites_custom, function (val, key) {
return !defaultSites_domains.includes(val.domain);
});
ext_api.storage.local.set({
sites_custom: sites_custom
}, function () {
// Update status to let user know custom & default sites were deleted.
var status_delete = document.getElementById('status_delete');
status_delete.textContent = 'Default sites deleted.';
setTimeout(function () {
//status.textContent = '';
renderOptions();
}, 800);
});
});
}
// Edit custom site (copy to add)
function edit_options() {
var selectEl = document.querySelector('#custom_sites select');
var sites_custom = {};
var title = selectEl.value;
if (!title)
return false;
// copy site to add-fields
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
sites_custom = items.sites_custom;
var edit_site = sites_custom[title];
document.querySelector('input[data-key="title"]').value = title;
document.querySelector('input[data-key="domain"]').value = edit_site.domain;
document.querySelector('textarea[data-key="group"]').value = edit_site.group || '';
document.querySelector('input[data-key="allow_cookies"]').checked = (edit_site.allow_cookies > 0);
document.querySelector('input[data-key="remove_cookies"]').checked = (edit_site.remove_cookies > 0);
document.querySelector('select[data-key="useragent"]').selectedIndex = (edit_site.googlebot > 0) ? 1 : useragent_options.indexOf(edit_site.useragent);
document.querySelector('textarea[data-key="useragent_custom"]').value = edit_site.useragent_custom || '';
document.querySelector('select[data-key="referer"]').selectedIndex = referer_options.indexOf(edit_site.referer);
document.querySelector('textarea[data-key="referer_custom"]').value = edit_site.referer_custom || '';
document.querySelector('select[data-key="random_ip"]').selectedIndex = random_ip_options.indexOf(edit_site.random_ip);
document.querySelector('input[data-key="block_js"]').checked = (edit_site.block_js > 0 || edit_site.block_javascript > 0);
document.querySelector('input[data-key="block_js_ext"]').checked = (edit_site.block_js_ext > 0 || edit_site.block_javascript_ext > 0);
document.querySelector('input[data-key="block_js_inline"]').value = edit_site.block_js_inline || '';
document.querySelector('input[data-key="block_regex"]').value = edit_site.block_regex || '';
document.querySelector('input[data-key="block_regex_ignore_default"]').checked = (edit_site.block_regex_ignore_default > 0 || edit_site.block_regex_ignore_default > 0);
document.querySelector('input[data-key="block_host_perm_add"]').value = edit_site.block_host_perm_add || '';
document.querySelector('input[data-key="amp_unhide"]').checked = (edit_site.amp_unhide > 0);
document.querySelector('input[data-key="amp_redirect"]').value = edit_site.amp_redirect || '';
document.querySelector('input[data-key="ld_json"]').value = edit_site.ld_json || '';
document.querySelector('input[data-key="ld_json_next"]').value = edit_site.ld_json_next || '';
document.querySelector('input[data-key="ld_json_url"]').value = edit_site.ld_json_url || '';
document.querySelector('input[data-key="ld_archive_is"]').value = edit_site.ld_archive_is || '';
document.querySelector('input[data-key="ld_google_webcache"]').value = edit_site.ld_google_webcache || '';
document.querySelector('input[data-key="add_ext_link"]').value = edit_site.add_ext_link || '';
document.querySelector('select[data-key="add_ext_link_type"]').selectedIndex = add_ext_link_type_options.indexOf(edit_site.add_ext_link_type);
document.querySelector('textarea[data-key="cs_code"]').value = edit_site.cs_code || '';
});
}
// request permissions for custom sites (in list only)
function request_permissions() {
var perm_custom = document.getElementById('perm-custom');
ext_api.permissions.request({
origins: perm_origins
}, function (granted) {
if (granted) {
perm_custom.innerText = 'YES';
} else {
perm_custom.innerText = 'NO';
}
});
}
// remove permissions for custom sites
function remove_permissions() {
var perm_custom = document.getElementById('perm-custom');
ext_api.permissions.remove({
origins: perm_origins
}, function (removed) {
if (removed) {
perm_custom.innerText = 'NO';
}
});
}
var perm_origins;
// Restores checkbox input states using the preferences stored in ext_api.storage.
function renderOptions() {
ext_api.storage.local.get({
sites_custom: {},
sites_updated: {}
}, function (items) {
var sites_custom = sortJson(items.sites_custom);
var sites_custom_domains_new = Object.values(sites_custom).filter(x => x.domain && !defaultSites_domains.includes(x.domain)).map(x => x.group ? x.group.split(',').filter(x => x).map(x => x.trim()) : x.domain).flat();
var sites_custom_perm_domains_new = Object.values(sites_custom).filter(x => x.block_host_perm_add).map(x => x.block_host_perm_add.split(',').filter(x => x).map(x => x.trim())).flat();
var sites_updated = filterObject(items.sites_updated, function (val, key) {
return !val.nofix
});
var sites_updated_domains_new = Object.values(sites_updated).filter(x => (x.domain && !defaultSites_domains.includes(x.domain) || x.group)).map(x => x.group ? x.group.filter(y => !defaultSites_domains.includes(y)) : x.domain).flat();
var sites_updated_perm_domains_new = Object.values(sites_updated).filter(x => x.block_host_perm_add).map(x => x.block_host_perm_add.split(',').filter(x => x).map(x => x.trim())).flat();
var sitesEl = document.getElementById('bypass_sites');
sitesEl.innerHTML = '';
var labelEl = document.createElement('label');
var textareaEl = document.createElement('textarea');
textareaEl.value = JSON.stringify(sites_custom);
textareaEl.rows = 12;
textareaEl.cols = 40;
labelEl.appendChild(textareaEl);
sitesEl.appendChild(labelEl);
// add site
var add_sitesEl = document.getElementById('add_site');
add_sitesEl.innerHTML = '';
var inputEl;
var add_checkboxes = {
'title': 0,
'domain': 0,
'group': 0,
'allow_cookies': 1,
'remove_cookies': 1,
'useragent': 0,
'useragent_custom': 0,
'referer': 0,
'referer_custom': 0,
'random_ip': 0,
'block_js (domain)': 1,
'block_js_ext': 1,
'block_js_inline': 0,
'block_regex (add to default)': 0,
'block_regex_ignore_default': 1,
'block_host_perm_add': 0,
'amp_unhide': 1,
'amp_redirect': 0,
'ld_json': 0,
'ld_json_next': 0,
'ld_json_url': 0,
'ld_archive_is': 0,
'ld_google_webcache': 0,
'add_ext_link': 0,
'add_ext_link_type': 0,
'cs_code': 0,
};
var add_options = {
useragent: useragent_options,
referer: referer_options,
random_ip: random_ip_options,
add_ext_link_type: add_ext_link_type_options
};
for (var key in add_checkboxes) {
if (add_checkboxes[key]) {
inputEl = document.createElement('input');
inputEl.type = 'checkbox';
inputEl.dataset.value = 1;
} else {
if (add_options[key]) {
inputEl = document.createElement('select');
for (let elem of add_options[key]) {
let option = document.createElement("option");
option.value = elem;
option.text = elem;
inputEl.appendChild(option);
}
} else {
if (!['cs_code', 'group', 'referer_custom', 'useragent_custom'].includes(key)) {
inputEl = document.createElement('input');
inputEl.size = 25;
} else {
inputEl = document.createElement('textarea');
inputEl.rows = 5;
inputEl.cols = 25;
}
let placeholders = {
title: 'Example',
domain: 'example.com',
group: 'example1.com,example2.com',
block_js_inline: '\\.example\\.com\\/article\\/',
block_regex: '\\.example\\.com\\/js\\/',
block_host_perm_add: 'example1.com,example2.com',
amp_redirect: 'div.paywall',
ld_json: 'div.paywall|div.article',
ld_json_next: 'div.paywall|div.article',
ld_json_url: 'div.paywall|div.article',
ld_archive_is: 'div.paywall|div.art|div.art_src|div.art_link',
ld_google_webcache: 'div.paywall|div.article',
add_ext_link: 'div.paywall|div.article',
cs_code: 'for dev: check imported examples',
};
if (placeholders[key])
inputEl.placeholder = placeholders[key];
}
}
labelEl = document.createElement('label');
labelEl.style = 'margin: 2px 0px;';
inputEl.dataset.key = key.split(' (')[0];
labelEl.appendChild(inputEl);
labelEl.appendChild(document.createTextNode(' ' + key));
add_sitesEl.appendChild(labelEl);
}
// list of custom sites
var custom_sitesEl = document.getElementById('custom_sites');
custom_sitesEl.innerHTML = '';
labelEl = document.createElement('label');
var selectEl = document.createElement('select');
selectEl.id = 'sites';
selectEl.size = 6;
var optionEl;
for (let key in sites_custom) {
optionEl = document.createElement('option');
let domain = sites_custom[key]['domain'];
let group = sites_custom[key]['group'];
let isDefaultSite = defaultSites_domains.includes(domain);
optionEl.text = isDefaultSite ? '*' : '';
optionEl.text += key + ': ' + domain +
(sites_custom[key]['allow_cookies'] > 0 ? ' | allow_cookies' : '') +
(sites_custom[key]['remove_cookies'] > 0 ? ' | remove_cookies' : '') +
(sites_custom[key]['useragent'] ? ' | useragent: ' + sites_custom[key]['useragent'] : '') +
(sites_custom[key]['useragent_custom'] ? ' | useragent_custom' : '') +
(sites_custom[key]['googlebot'] > 0 ? ' | googlebot' : '') +
(sites_custom[key]['referer'] ? ' | referer: ' + sites_custom[key]['referer'] : '') +
(sites_custom[key]['referer_custom'] ? ' | referer_custom' : '') +
(sites_custom[key]['random_ip'] ? ' | random_ip: ' + sites_custom[key]['random_ip'] : '') +
((sites_custom[key]['block_js'] > 0 || sites_custom[key]['block_javascript'] > 0) ? ' | block_js' : '') +
((sites_custom[key]['block_js_ext'] > 0 || sites_custom[key]['block_javascript_ext'] > 0) ? ' | block_js_ext' : '') +
(sites_custom[key]['block_js_inline'] ? ' | block_js_inline' : '') +
(sites_custom[key]['block_regex'] ? ' | block_regex' : '') +
(sites_custom[key]['amp_unhide'] > 0 ? ' | amp_unhide' : '') +
(sites_custom[key]['amp_redirect'] ? ' | amp_redirect' : '') +
(sites_custom[key]['ld_json'] ? ' | ld_json' : '') +
(sites_custom[key]['ld_json_next'] ? ' | ld_json_next' : '') +
(sites_custom[key]['ld_json_url'] ? ' | ld_json_url' : '') +
(sites_custom[key]['ld_archive_is'] ? ' | ld_archive_is' : '') +
(sites_custom[key]['ld_google_webcache'] ? ' | ld_google_webcache' : '') +
(sites_custom[key]['add_ext_link'] && sites_custom[key]['add_ext_link_type'] ? ' | add_ext_link' : '') +
(sites_custom[key]['cs_code'] ? ' | cs_code' : '');
optionEl.value = key;
selectEl.add(optionEl);
}
labelEl.appendChild(selectEl);
custom_sitesEl.appendChild(labelEl);
if (sites_updated_domains_new.length > 0) {
labelEl = document.createElement('p');
labelEl.appendChild(document.createElement('label'));
labelEl.appendChild(document.createTextNode('Updated sites: ' + sites_updated_domains_new.concat(sites_updated_perm_domains_new).join(', ')));
custom_sitesEl.appendChild(labelEl);
}
perm_origins = sites_custom_domains_new.concat(sites_updated_domains_new, sites_custom_perm_domains_new, sites_updated_perm_domains_new).filter(x => !x.includes('###')).map(x => '*://*.' + x + '/*');
var perm_custom = document.getElementById('perm-custom');
ext_api.permissions.contains({
origins: perm_origins
}, function (result) {
if (result) {
perm_custom.innerText = 'YES';
} else {
perm_custom.innerText = 'NO';
}
});
});
var custom_enabled = document.getElementById('custom-enabled');
ext_api.permissions.contains({
origins: ["*://*/*"]
}, function (result) {
if (result) {
custom_enabled.innerText = 'YES';
} else {
custom_enabled.innerText = 'NO';
}
});
}
function handleSearch() {
let search = document.getElementById('search').value.toLowerCase().replace('www.', '');
let listItems = document.querySelectorAll('select#sites > option');
ext_api.storage.local.get({
sites_custom: {}
}, function (items) {
let sites_custom = items.sites_custom;
let grouped_sites = filterObject(sites_custom, function (val, key) {
return val.group
}, function (val, key) {
return [val.domain, val.group.split(',')]
});
for (let item of listItems) {
let itemDomain = sites_custom[item.value].domain;
let itemText = item.value.toLowerCase();
let itemGroup = itemDomain ? grouped_sites[itemDomain] : '';
if (itemText.includes(search) || (itemDomain.includes(search) || (itemGroup && itemGroup.includes(search))))
item.style.display = 'block';
else
item.style.display = 'none';
}
});
}
document.addEventListener('DOMContentLoaded', renderOptions);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('sort').addEventListener('click', sort_options);
document.getElementById('export').addEventListener('click', export_options);
document.getElementById('import').onclick = function () {importInput.click()}
document.getElementById('importInput').addEventListener("change", import_options, false);
document.getElementById('import_online').addEventListener('click', import_online_options);
document.getElementById('add').addEventListener('click', add_options);
document.getElementById('delete').addEventListener('click', delete_options);
document.getElementById('delete_default').addEventListener('click', delete_default_options);
document.getElementById('edit').addEventListener('click', edit_options);
document.getElementById('search').addEventListener('input', handleSearch);
if (custom_switch) {
document.getElementById('perm_request').addEventListener('click', request_permissions);
document.getElementById('perm_remove').addEventListener('click', remove_permissions);
}

View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bypass Paywalls Clean Options Excluded</title>
<link rel="stylesheet" href="options_all.css"/>
</head>
<body>
<h2>Excluded Sites</h2>
<div style="width:90%;">
Add excluded sites/domains (for your subscriptions) as a comma-separated list (www.-prefix and spaces are removed).<br>
You can also exclude a specific domain which is grouped in options.<br>
Checked sites in options are ignored (to still enable select all).<br>
</div>
<div style="clear:both;"></div>
<div style="width:90%;">
<h3>Sites</h3>
</div>
<br>
<div id='excluded_sites'></div>
<br>
<div id="status"></div>
<div id="error"></div>
<span style='float:left;padding-bottom:50px'>
<button id="save">Save</button>
<button id="sort">Sort</button>
<button><a href="options.html" style="text-decoration:none;color:inherit">Options</a></button>
</span>
<script src="options_excluded.js"></script>
</body>
</html>

View File

@@ -0,0 +1,52 @@
var ext_api = chrome || browser;
// Saves options to ext_api.storage
function save_options() {
var textareaEl = document.querySelector('#excluded_sites textarea');
var sites_excluded = [];
if (textareaEl.value !== '')
var sites_excluded = textareaEl.value.split(',').filter(x => x).map(x => x.trim().replace('www.', ''));
ext_api.storage.local.set({
sites_excluded: sites_excluded
}, function () {
// Update status to let user know excluded sites were saved.
var status = document.getElementById('status');
status.textContent = 'Excluded sites saved.';
});
}
// Sort json by key in textarea
function sort_options() {
var textareaEl = document.querySelector('#excluded_sites textarea');
var sites_excluded = [];
if (textareaEl.value !== '') {
var sites_excluded = textareaEl.value.split(',').map(x => x.trim().replace('www.', ''));
var sites_excluded_sorted = sites_excluded.sort();
textareaEl.value = sites_excluded_sorted.join();
}
// Update status to let user know excluded sites were sorted.
var status = document.getElementById('status');
status.textContent = 'Excluded sites sorted (not saved yet)';
}
function renderOptions() {
ext_api.storage.local.get({
sites_excluded: []
}, function (items) {
var sites_excluded = items.sites_excluded;
var sitesEl = document.getElementById('excluded_sites');
sitesEl.innerHTML = '';
var labelEl = document.createElement('label');
var textareaEl = document.createElement('textarea');
textareaEl.placeholder = 'example1.com,example2.com';
textareaEl.value = sites_excluded.join();
textareaEl.rows = 12;
textareaEl.cols = 40;
labelEl.appendChild(textareaEl);
sitesEl.appendChild(labelEl);
});
}
document.addEventListener('DOMContentLoaded', renderOptions);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('sort').addEventListener('click', sort_options);

32
options/popup.html Normal file
View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="options_all.css"/>
<link rel="stylesheet" href="popup_switch.css"/>
<style>
body {
text-align: center;
}
div {
margin: 10px;
}
</style>
</head>
<body style="width:290px">
<div><strong>Bypass Paywalls Clean <span id="version"></span></strong><span id="site_switch_span">&nbsp;&nbsp;</span></div>
<div><a href="options.html" target="_blank">Options</a> |
<a href="options_custom.html" target="_blank">Custom</a> |
<a href="/README.html" target="_blank">Help</a> |
<a href="https://twitter.com/Magnolia1234B" target="_blank">X (Twitter)</a></div>
<div><a href="/changelog.txt" target="_blank">Changelog</a> |
<button id="clear_cookies" title="clear cookies (and local storage) for current site">clear cookies<br>(& permission)</button> |
<button id="button-close" title="close popup">close</button></div>
<div><span id="version_new"></span></div>
<div><span>* for unlisted sites: first clear cookies (X = no fix) & block general paywall-scripts (in options) or use custom sites/reader view</span></div>
<div><span id="archive"></span></div>
<script id="popup" src="version.js"></script>
<script src="popup.js"></script>
</body>
</html>

150
options/popup.js Normal file
View File

@@ -0,0 +1,150 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
var manifestData = ext_api.runtime.getManifest();
var navigator_ua = navigator.userAgent;
var navigator_ua_mobile = navigator_ua.toLowerCase().includes('mobile');
var yandex_browser = navigator_ua_mobile && (url_loc === 'chrome') && navigator_ua.toLowerCase().includes('yabrowser');
var custom_switch = ((manifestData.optional_permissions && manifestData.optional_permissions.length) || (manifestData.optional_host_permissions && manifestData.optional_host_permissions.length)) && !(navigator_ua_mobile && (url_loc === 'chrome') && !yandex_browser);
function popup_show_toggle(domain, enabled) {
if (domain && !matchDomain(['webcache.googleusercontent.com'], 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/group 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.onMessage.addListener(function (message, sender) {
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] && /^http/.test(tabs[0].url)) {
let hostname = new URL(tabs[0].url).hostname;
cookie_domain = getCookiePermDomain(hostname);
}
});
document.getElementById("clear_cookies").addEventListener('click', function () {
if (custom_switch)
ext_api.permissions.request({
origins: ["*://*." + cookie_domain + "/*"]
}, function (granted) {
if (granted) {
ext_api.runtime.sendMessage({
request: 'clear_cookies'
});
}
});
else
ext_api.permissions.contains({
origins: ["*://*." + cookie_domain + "/*"]
}, function (result) {
if (result) {
ext_api.runtime.sendMessage({
request: 'clear_cookies'
});
}
});
});
function showArchiveLinks() {
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
let url = tabs[0].url;
let hostname = urlHost(url);
if (!matchDomain(['hbrchina.org'], hostname))
url = url.split(/[#\?]/)[0];
let url_enc = encodeURIComponent(url);
let archive_array = {
'Archive.today': 'https://archive.today?run=1&url=' + url_enc,
'Google webcache': 'https://webcache.googleusercontent.com/search?q=cache:' + url_enc,
'Clearthis.page': 'https://clearthis.page?u=' + url,
'1ft.io': 'https://1ft.io/' + url,
'Google Search Tool\n(use online html-viewer - no fix)': 'https://search.google.com/test/rich-results?url=' + url_enc
};
//'Archive.today (renew)': 'https://archive.today?renew=1&url=' + url_enc,
let archive_id = document.querySelector('span#archive');
if (archive_id) {
archive_id.appendChild(document.createTextNode('Open tab in:'));
for (let key in archive_array) {
let elem_div = document.createElement('div');
let elem = document.createElement('a');
elem.innerText = key;
if (!(matchDomain(['1ft.io', 'clearthis.page', 'google.com', 'googleusercontent.com'], hostname) || hostname.match(/^archive\.\w{2}$/))) {
elem.href = archive_array[key];
elem.title = elem.href;
elem.target = '_blank';
elem_div.appendChild(elem);
archive_id.appendChild(elem_div);
}
}
}
}
});
}
showArchiveLinks();
function matchDomain(domains, hostname = window.location.hostname) {
let matched_domain = false;
if (typeof domains === 'string')
domains = [domains];
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
return matched_domain;
}
function urlHost(url) {
if (/^http/.test(url)) {
try {
return new URL(url).hostname;
} catch (e) {
console.log(`url not valid: ${url} error: ${e}`);
}
}
return url;
}
function closeButton() {
window.close();
}
function getCookiePermDomain(hostname) {
let domain = hostname.replace(/^(www|amp(html)?|m|wap)(\d)?\./, '');
let domain_split = domain.split('.');
let num = 2;
if (domain_split.length > 2 && domain.match(/(\w){2,4}\.(\w){2}$/))
num = 3;
domain = domain_split.slice(-num).join('.');
return domain;
}
document.getElementById("button-close").addEventListener('click', closeButton);

58
options/popup_switch.css Normal file
View File

@@ -0,0 +1,58 @@
.switch {
position: relative;
display: inline-block;
width: 30px;
height: 17px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: blue;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 13px;
width: 13px;
left: 2px;
bottom: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: red;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(13px);
-ms-transform: translateX(13px);
transform: translateX(13px);
}
.slider.round {
border-radius: 9px;
}
.slider.round:before {
border-radius: 50%;
}

5
options/toggleIcon.js Normal file
View File

@@ -0,0 +1,5 @@
// message for dark or incognito mode (chrome)
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || chrome.extension.inIncognitoContext)
chrome.runtime.sendMessage({scheme: 'dark'});
else
chrome.runtime.sendMessage({scheme: 'light'});

88
options/version.js Normal file
View File

@@ -0,0 +1,88 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
var manifestData = ext_api.runtime.getManifest();
var url_loc = manifestData.key ? 'chrome' : 'firefox';
var ext_url = 'https://github.com/bpc-clone/bpc_updates/releases/latest';
var ext_name = manifestData.name;
var version_str = 'v' + manifestData.version;
var version_span = document.querySelector('span#version');
if (version_span)
version_span.innerText = version_str;
var version_span_new = document.querySelector('span#version_new');
version_span_new.setAttribute('style', 'font-weight: bold;');
var anchorEl;
function show_warning() {
let warning;
if (!ext_name.includes('Clean')) {
warning = 'fake';
}
if (warning) {
let par = document.createElement('p');
let ext_link = document.createElement('a');
ext_link.href = ext_url;
ext_link.innerText = "You've installed a " + warning + " version of Bypass Paywalls Clean";
ext_link.target = '_blank';
par.style = 'font-weight: bold;';
par.appendChild(ext_link);
version_span_new.appendChild(par);
}
}
function show_update(ext_version_new, check = true) {
if (ext_version_new) {
ext_api.management.getSelf(function (result) {
var installType = result.installType;
var version_len = (installType === 'development') ? 7 : 5;
if (ext_version_new.substring(0, version_len) > manifestData.version.substring(0, version_len)) {
ext_api.storage.local.set({
ext_version_new: ext_version_new
});
anchorEl = document.createElement('a');
anchorEl.target = '_blank';
if (installType === 'development')
anchorEl.href = ext_url;
else {
anchorEl.href = ext_url + '/-/releases';
ext_version_new = ext_version_new.replace(/\d$/, '0');
}
anchorEl.innerText = 'New release v' + ext_version_new;
version_span_new.appendChild(anchorEl);
}
});
show_warning();
} else if (check) {
anchorEl = document.createElement('a');
anchorEl.text = 'Check Twitter for latest update';
anchorEl.href = 'https://twitter.com/Magnolia1234B';
anchorEl.target = '_blank';
version_span_new.appendChild(anchorEl);
}
}
function check_version_update(ext_version_new, popup) {
if (!popup) {
let manifest_new = 'https://bitbucket.org/bpc-updates/bpc_updates/downloads/manifest.json';
fetch(manifest_new)
.then(response => {
if (response.ok) {
response.json().then(json => {
var version_new = json['version'];
show_update(version_new);
})
} else {
show_update(ext_version_new);
}
}).catch(function (err) {
false;
});
} else
show_update(ext_version_new, false);
}
ext_api.storage.local.get({optInUpdate: true, ext_version_new: false}, function (result) {
if (result.optInUpdate) {
let popup = document.querySelector('script[id="popup"]');
check_version_update(result.ext_version_new, popup);
} else
show_warning();
});