2020-03-25 18:31:28 +00:00
|
|
|
var ext_api = chrome || browser;
|
2022-07-24 16:25:42 +00:00
|
|
|
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
|
2023-07-17 14:40:53 +00:00
|
|
|
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 && !yandex_browser);
|
2020-02-28 15:23:17 +00:00
|
|
|
|
2022-12-09 16:08:18 +00:00
|
|
|
var useragent_options = ['', 'googlebot', 'bingbot', 'facebookbot'];
|
2021-02-06 20:37:52 +00:00
|
|
|
var referer_options = ['', 'facebook', 'google', 'twitter'];
|
2021-12-21 16:36:48 +00:00
|
|
|
var random_ip_options = ['', 'all', 'eu'];
|
2023-10-30 06:48:49 +00:00
|
|
|
var add_ext_link_type_options = ['', 'archive.is', '1ft.io', 'google_webcache', 'google_search_tool'];
|
2021-02-06 20:37:52 +00:00
|
|
|
|
2020-04-11 17:40:12 +00:00
|
|
|
function capitalize(str) {
|
2021-10-17 08:01:21 +00:00
|
|
|
return (typeof str === 'string') ? str.charAt(0).toUpperCase() + str.slice(1) : '';
|
2020-04-11 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function sortJson(json) {
|
2021-10-17 08:01:21 +00:00
|
|
|
return Object.keys(json)
|
|
|
|
.sort().reduce(function (Obj, key) {
|
|
|
|
Obj[key] = json[key];
|
|
|
|
return Obj;
|
|
|
|
}, {});
|
2020-04-11 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 16:14:27 +00:00
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
// Saves options to ext_api.storage
|
2020-02-28 15:23:17 +00:00
|
|
|
function save_options() {
|
2021-10-17 08:01:21 +00:00
|
|
|
var textareaEl = document.querySelector('#bypass_sites textarea');
|
|
|
|
var sites_custom = {};
|
2023-05-17 16:14:27 +00:00
|
|
|
if (textareaEl.value) {
|
2021-10-17 08:01:21 +00:00
|
|
|
var sites_custom = JSON.parse(textareaEl.value);
|
2023-05-17 16:14:27 +00:00
|
|
|
sites_custom = filterObject(sites_custom, function (val, key) {
|
2023-08-19 05:42:37 +00:00
|
|
|
return !(val.add_ext_link && !val.add_ext_link_type)
|
2023-05-17 16:14:27 +00:00
|
|
|
});
|
|
|
|
}
|
2021-10-17 08:01:21 +00:00
|
|
|
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);
|
|
|
|
});
|
2020-02-28 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 17:40:12 +00:00
|
|
|
// Sort json by key in textarea
|
|
|
|
function sort_options() {
|
2021-10-17 08:01:21 +00:00
|
|
|
var textareaEl = document.querySelector('#bypass_sites textarea');
|
|
|
|
var sites_custom = {};
|
2022-12-21 17:04:11 +00:00
|
|
|
if (textareaEl.value) {
|
2021-10-17 08:01:21 +00:00
|
|
|
var sites_custom = JSON.parse(textareaEl.value);
|
|
|
|
var sites_custom_sorted = sortJson(sites_custom);
|
|
|
|
textareaEl.value = JSON.stringify(sites_custom_sorted);
|
|
|
|
}
|
2020-04-11 17:40:12 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 18:45:19 +00:00
|
|
|
// Export custom sites to file
|
|
|
|
function export_options() {
|
2021-10-17 08:01:21 +00:00
|
|
|
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();
|
|
|
|
});
|
2020-03-08 18:45:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 16:25:42 +00:00
|
|
|
function import_json(result) {
|
2021-10-17 08:01:21 +00:00
|
|
|
ext_api.storage.local.get({
|
|
|
|
sites_custom: {}
|
|
|
|
}, function (items) {
|
|
|
|
var sites_custom = items.sites_custom;
|
|
|
|
var sites_custom_new = JSON.parse(result);
|
2023-09-18 06:20:00 +00:00
|
|
|
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?/);
|
2023-08-04 17:14:55 +00:00
|
|
|
for (let site in sites_custom_new) {
|
2023-09-28 05:21:09 +00:00
|
|
|
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];
|
|
|
|
sites_custom[site] = sites_custom_new[site];
|
2023-08-04 17:14:55 +00:00
|
|
|
}
|
2023-05-17 16:14:27 +00:00
|
|
|
sites_custom = filterObject(sites_custom, function (val, key) {
|
2023-09-28 05:21:09 +00:00
|
|
|
return !(customSitesExt_remove.includes(val.domain) || (val.add_ext_link && !val.add_ext_link_type))
|
2023-05-17 16:14:27 +00:00
|
|
|
});
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.set({
|
2023-09-28 05:21:09 +00:00
|
|
|
sites_custom: sortJson(sites_custom)
|
2020-03-08 18:45:19 +00:00
|
|
|
}, function () {
|
2021-10-17 08:01:21 +00:00
|
|
|
// 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);
|
2020-03-08 18:45:19 +00:00
|
|
|
});
|
2021-10-17 08:01:21 +00:00
|
|
|
});
|
2020-03-08 18:45:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 16:25:42 +00:00
|
|
|
// Import custom sites from GitLab
|
|
|
|
function import_gitlab_options(e) {
|
|
|
|
let url = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/-/raw/master/custom/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;
|
2023-05-17 16:14:27 +00:00
|
|
|
import_json(result);
|
2022-07-24 16:25:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
// Add custom site to ext_api.storage
|
2020-02-28 15:23:17 +00:00
|
|
|
function add_options() {
|
2022-12-21 17:04:11 +00:00
|
|
|
var inputEls = document.querySelectorAll('#add_site input, #add_site select, #add_site textarea');
|
2021-10-17 08:01:21 +00:00
|
|
|
var sites_custom = {};
|
|
|
|
|
|
|
|
for (let elem of inputEls) {
|
|
|
|
if (elem.dataset.key === 'title') {
|
|
|
|
var title = capitalize(elem.value);
|
2022-12-21 17:04:11 +00:00
|
|
|
if (!title)
|
2021-10-17 08:01:21 +00:00
|
|
|
break;
|
|
|
|
sites_custom[title] = {};
|
|
|
|
} else {
|
|
|
|
if (elem.dataset.value) {
|
|
|
|
if (elem.checked)
|
2021-10-30 08:29:59 +00:00
|
|
|
sites_custom[title][elem.dataset.key] = parseInt(elem.dataset.value);
|
2023-11-05 17:48:46 +00:00
|
|
|
} else if (elem.value) {
|
|
|
|
if (elem.dataset.key === 'group')
|
|
|
|
elem.value = elem.value.replace(/(\s|www\.)/g, '');
|
2021-10-17 08:01:21 +00:00
|
|
|
sites_custom[title][elem.dataset.key] = elem.value;
|
2023-11-05 17:48:46 +00:00
|
|
|
}
|
2020-08-22 11:52:43 +00:00
|
|
|
}
|
2021-10-17 08:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (title && sites_custom[title]['domain']) {
|
2022-01-13 16:22:38 +00:00
|
|
|
sites_custom[title]['domain'] = sites_custom[title]['domain'].replace(/(http(s)?:\/\/|\/$)/g, '').replace(/^(www|amp(html)?|m|wap)(\d)?\./, '').toLowerCase();
|
2021-10-17 08:01:21 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-02-28 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
// Delete custom site from ext_api.storage
|
2020-03-02 17:36:11 +00:00
|
|
|
function delete_options() {
|
2021-10-17 08:01:21 +00:00
|
|
|
var selectEl = document.querySelector('#custom_sites select');
|
|
|
|
var sites_custom = {};
|
|
|
|
var remove_key = selectEl.value;
|
2023-01-12 18:18:09 +00:00
|
|
|
if (!remove_key)
|
|
|
|
return false;
|
2021-10-17 08:01:21 +00:00
|
|
|
|
|
|
|
// 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);
|
2020-03-02 17:36:11 +00:00
|
|
|
});
|
2021-10-17 08:01:21 +00:00
|
|
|
});
|
2020-03-02 17:36:11 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 18:48:00 +00:00
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-18 18:19:15 +00:00
|
|
|
// Edit custom site (copy to add)
|
|
|
|
function edit_options() {
|
2021-10-17 08:01:21 +00:00
|
|
|
var selectEl = document.querySelector('#custom_sites select');
|
|
|
|
var sites_custom = {};
|
|
|
|
var title = selectEl.value;
|
2023-01-12 18:18:09 +00:00
|
|
|
if (!title)
|
|
|
|
return false;
|
2021-10-17 08:01:21 +00:00
|
|
|
|
|
|
|
// 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;
|
2023-11-05 17:48:46 +00:00
|
|
|
document.querySelector('textarea[data-key="group"]').value = edit_site.group ? edit_site.group : '';
|
2021-10-17 08:01:21 +00:00
|
|
|
document.querySelector('input[data-key="allow_cookies"]').checked = (edit_site.allow_cookies > 0);
|
2023-01-12 18:18:09 +00:00
|
|
|
document.querySelector('input[data-key="remove_cookies"]').checked = (edit_site.remove_cookies > 0);
|
2023-02-19 11:36:09 +00:00
|
|
|
document.querySelector('select[data-key="useragent"]').selectedIndex = (edit_site.googlebot > 0) ? 1 : useragent_options.indexOf(edit_site.useragent);
|
|
|
|
document.querySelector('select[data-key="referer"]').selectedIndex = referer_options.indexOf(edit_site.referer);
|
|
|
|
document.querySelector('select[data-key="random_ip"]').selectedIndex = random_ip_options.indexOf(edit_site.random_ip);
|
2022-12-24 16:05:55 +00:00
|
|
|
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 ? edit_site.block_js_inline : '';
|
2021-10-17 08:01:21 +00:00
|
|
|
document.querySelector('input[data-key="block_regex"]').value = edit_site.block_regex ? edit_site.block_regex : '';
|
2021-10-17 19:15:00 +00:00
|
|
|
document.querySelector('input[data-key="amp_unhide"]').checked = (edit_site.amp_unhide > 0);
|
2021-12-22 19:28:59 +00:00
|
|
|
document.querySelector('input[data-key="amp_redirect"]').value = edit_site.amp_redirect ? edit_site.amp_redirect : '';
|
2022-02-22 18:23:36 +00:00
|
|
|
document.querySelector('input[data-key="ld_json"]').value = edit_site.ld_json ? edit_site.ld_json : '';
|
2023-05-07 11:13:41 +00:00
|
|
|
document.querySelector('input[data-key="ld_json_next"]').value = edit_site.ld_json_next ? edit_site.ld_json_next : '';
|
2023-08-12 07:04:57 +00:00
|
|
|
document.querySelector('input[data-key="ld_json_url"]').value = edit_site.ld_json_url ? edit_site.ld_json_url : '';
|
2022-08-01 18:49:58 +00:00
|
|
|
document.querySelector('input[data-key="ld_google_webcache"]').value = edit_site.ld_google_webcache ? edit_site.ld_google_webcache : '';
|
2023-02-19 11:36:09 +00:00
|
|
|
document.querySelector('input[data-key="add_ext_link"]').value = edit_site.add_ext_link ? 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 ? edit_site.cs_code : '';
|
2021-10-17 08:01:21 +00:00
|
|
|
});
|
2020-08-18 18:19:15 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 17:35:59 +00:00
|
|
|
// request permissions for custom sites (in list only)
|
|
|
|
function request_permissions() {
|
2021-10-17 08:01:21 +00:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
});
|
2021-04-29 17:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove permissions for custom sites
|
|
|
|
function remove_permissions() {
|
2021-10-17 08:01:21 +00:00
|
|
|
var perm_custom = document.getElementById('perm-custom');
|
|
|
|
ext_api.permissions.remove({
|
|
|
|
origins: perm_origins
|
|
|
|
}, function (removed) {
|
|
|
|
if (removed) {
|
|
|
|
perm_custom.innerText = 'NO';
|
|
|
|
}
|
|
|
|
});
|
2021-04-29 17:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var perm_origins;
|
2020-03-25 18:31:28 +00:00
|
|
|
// Restores checkbox input states using the preferences stored in ext_api.storage.
|
2020-02-28 15:23:17 +00:00
|
|
|
function renderOptions() {
|
2021-10-17 08:01:21 +00:00
|
|
|
ext_api.storage.local.get({
|
2021-11-13 10:43:09 +00:00
|
|
|
sites_custom: {},
|
|
|
|
sites_updated: {}
|
2021-10-17 08:01:21 +00:00
|
|
|
}, function (items) {
|
|
|
|
var sites_custom = items.sites_custom;
|
2023-11-05 17:48:46 +00:00
|
|
|
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();
|
2021-11-13 10:43:09 +00:00
|
|
|
var sites_updated = items.sites_updated;
|
2021-11-15 17:13:46 +00:00
|
|
|
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();
|
2021-10-17 08:01:21 +00:00
|
|
|
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,
|
2023-11-05 17:48:46 +00:00
|
|
|
'group': 0,
|
2021-10-17 08:01:21 +00:00
|
|
|
'allow_cookies': 1,
|
2023-01-12 18:18:09 +00:00
|
|
|
'remove_cookies': 1,
|
2023-02-19 11:36:09 +00:00
|
|
|
'useragent': 0,
|
|
|
|
'referer': 0,
|
|
|
|
'random_ip': 0,
|
2022-12-24 16:05:55 +00:00
|
|
|
'block_js (domain)': 1,
|
|
|
|
'block_js_ext': 1,
|
|
|
|
'block_js_inline': 0,
|
2021-10-17 19:15:00 +00:00
|
|
|
'block_regex': 0,
|
2021-12-22 19:28:59 +00:00
|
|
|
'amp_unhide': 1,
|
2022-02-22 18:23:36 +00:00
|
|
|
'amp_redirect': 0,
|
2022-08-01 18:49:58 +00:00
|
|
|
'ld_json': 0,
|
2023-05-07 11:13:41 +00:00
|
|
|
'ld_json_next': 0,
|
2023-08-12 07:04:57 +00:00
|
|
|
'ld_json_url': 0,
|
2022-12-21 17:04:11 +00:00
|
|
|
'ld_google_webcache': 0,
|
2023-02-19 11:36:09 +00:00
|
|
|
'add_ext_link': 0,
|
|
|
|
'add_ext_link_type': 0,
|
2022-12-21 17:04:11 +00:00
|
|
|
'cs_code': 0,
|
2021-10-17 08:01:21 +00:00
|
|
|
};
|
2023-02-19 11:36:09 +00:00
|
|
|
var add_options = {
|
|
|
|
useragent: useragent_options,
|
|
|
|
referer: referer_options,
|
|
|
|
random_ip: random_ip_options,
|
|
|
|
add_ext_link_type: add_ext_link_type_options
|
|
|
|
};
|
2021-10-17 08:01:21 +00:00
|
|
|
for (var key in add_checkboxes) {
|
|
|
|
if (add_checkboxes[key]) {
|
2023-02-19 11:36:09 +00:00
|
|
|
inputEl = document.createElement('input');
|
2021-10-17 08:01:21 +00:00
|
|
|
inputEl.type = 'checkbox';
|
|
|
|
inputEl.dataset.value = 1;
|
2021-12-24 07:32:45 +00:00
|
|
|
} else {
|
2023-02-19 11:36:09 +00:00
|
|
|
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 {
|
2023-11-05 17:48:46 +00:00
|
|
|
if (!['cs_code', 'group'].includes(key)) {
|
2023-02-19 11:36:09 +00:00
|
|
|
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',
|
2023-11-05 17:48:46 +00:00
|
|
|
group: 'example1.com,example2.com',
|
2023-02-19 11:36:09 +00:00
|
|
|
block_js_inline: '\\.example\\.com\\/article\\/',
|
|
|
|
block_regex: '\\.example\\.com\\/js\\/',
|
|
|
|
amp_redirect: 'div.paywall',
|
|
|
|
ld_json: 'div.paywall|div.article',
|
2023-05-07 11:13:41 +00:00
|
|
|
ld_json_next: 'div.paywall|div.article',
|
2023-08-12 07:04:57 +00:00
|
|
|
ld_json_url: 'div.paywall|div.article',
|
2023-02-19 11:36:09 +00:00
|
|
|
ld_google_webcache: 'div.paywall|div.article',
|
|
|
|
add_ext_link: 'div.paywall|div.article',
|
|
|
|
cs_code: 'for dev: check GitLab examples',
|
|
|
|
};
|
|
|
|
if (placeholders[key])
|
|
|
|
inputEl.placeholder = placeholders[key];
|
|
|
|
}
|
2021-12-24 07:32:45 +00:00
|
|
|
}
|
2021-10-17 08:01:21 +00:00
|
|
|
labelEl = document.createElement('label');
|
2023-02-19 11:36:09 +00:00
|
|
|
labelEl.style = 'margin: 2px 0px;';
|
2022-02-22 18:23:36 +00:00
|
|
|
inputEl.dataset.key = key.split(' (')[0];
|
2021-10-17 08:01:21 +00:00
|
|
|
labelEl.appendChild(inputEl);
|
2023-02-19 11:36:09 +00:00
|
|
|
labelEl.appendChild(document.createTextNode(' ' + key));
|
2021-10-17 08:01:21 +00:00
|
|
|
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;
|
2023-11-05 17:48:46 +00:00
|
|
|
|
2021-10-17 08:01:21 +00:00
|
|
|
for (let key in sites_custom) {
|
|
|
|
optionEl = document.createElement('option');
|
|
|
|
let domain = sites_custom[key]['domain'];
|
2023-11-05 17:48:46 +00:00
|
|
|
let group = sites_custom[key]['group'];
|
|
|
|
|
2021-10-17 08:01:21 +00:00
|
|
|
let isDefaultSite = defaultSites_domains.includes(domain);
|
|
|
|
optionEl.text = isDefaultSite ? '*' : '';
|
|
|
|
optionEl.text += key + ': ' + domain +
|
|
|
|
(sites_custom[key]['allow_cookies'] > 0 ? ' | allow_cookies' : '') +
|
2023-01-12 18:18:09 +00:00
|
|
|
(sites_custom[key]['remove_cookies'] > 0 ? ' | remove_cookies' : '') +
|
2023-02-19 11:36:09 +00:00
|
|
|
(sites_custom[key]['useragent'] ? ' | useragent: ' + sites_custom[key]['useragent'] : '') +
|
|
|
|
(sites_custom[key]['googlebot'] > 0 ? ' | googlebot' : '') +
|
|
|
|
(sites_custom[key]['referer'] ? ' | referer: ' + sites_custom[key]['referer'] : '') +
|
|
|
|
(sites_custom[key]['random_ip'] ? ' | random_ip: ' + sites_custom[key]['random_ip'] : '') +
|
2022-12-24 16:05:55 +00:00
|
|
|
((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' : '') +
|
2021-12-22 19:28:59 +00:00
|
|
|
(sites_custom[key]['amp_unhide'] > 0 ? ' | amp_unhide' : '') +
|
2022-02-22 18:23:36 +00:00
|
|
|
(sites_custom[key]['amp_redirect'] ? ' | amp_redirect' : '') +
|
2022-08-01 18:49:58 +00:00
|
|
|
(sites_custom[key]['ld_json'] ? ' | ld_json' : '') +
|
2023-05-07 11:13:41 +00:00
|
|
|
(sites_custom[key]['ld_json_next'] ? ' | ld_json_next' : '') +
|
2023-08-12 07:04:57 +00:00
|
|
|
(sites_custom[key]['ld_json_url'] ? ' | ld_json_url' : '') +
|
2022-12-21 17:04:11 +00:00
|
|
|
(sites_custom[key]['ld_google_webcache'] ? ' | ld_google_webcache' : '') +
|
2023-02-19 11:36:09 +00:00
|
|
|
(sites_custom[key]['add_ext_link'] && sites_custom[key]['add_ext_link_type'] ? ' | add_ext_link' : '') +
|
2022-12-21 17:04:11 +00:00
|
|
|
(sites_custom[key]['cs_code'] ? ' | cs_code' : '');
|
2021-10-17 08:01:21 +00:00
|
|
|
optionEl.value = key;
|
|
|
|
selectEl.add(optionEl);
|
|
|
|
}
|
|
|
|
labelEl.appendChild(selectEl);
|
|
|
|
custom_sitesEl.appendChild(labelEl);
|
2021-11-15 17:13:46 +00:00
|
|
|
|
|
|
|
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.join()));
|
|
|
|
custom_sitesEl.appendChild(labelEl);
|
2021-11-13 10:43:09 +00:00
|
|
|
}
|
2021-10-17 08:01:21 +00:00
|
|
|
|
2023-11-05 17:48:46 +00:00
|
|
|
perm_origins = sites_custom_domains_new.concat(sites_updated_domains_new).filter(x => !x.includes('###')).map(x => '*://*.' + x + '/*');
|
2021-10-17 08:01:21 +00:00
|
|
|
var perm_custom = document.getElementById('perm-custom');
|
2020-10-13 15:11:35 +00:00
|
|
|
ext_api.permissions.contains({
|
2021-10-17 08:01:21 +00:00
|
|
|
origins: perm_origins
|
2020-10-13 15:11:35 +00:00
|
|
|
}, function (result) {
|
2021-10-17 08:01:21 +00:00
|
|
|
if (result) {
|
|
|
|
perm_custom.innerText = 'YES';
|
|
|
|
} else {
|
|
|
|
perm_custom.innerText = 'NO';
|
|
|
|
}
|
2020-02-28 15:23:17 +00:00
|
|
|
});
|
2021-11-17 16:45:33 +00:00
|
|
|
});
|
2021-10-17 08:01:21 +00:00
|
|
|
|
|
|
|
var custom_enabled = document.getElementById('custom-enabled');
|
|
|
|
ext_api.permissions.contains({
|
2021-12-03 16:21:08 +00:00
|
|
|
origins: ["*://*/*"]
|
2021-10-17 08:01:21 +00:00
|
|
|
}, function (result) {
|
|
|
|
if (result) {
|
|
|
|
custom_enabled.innerText = 'YES';
|
|
|
|
} else {
|
|
|
|
custom_enabled.innerText = 'NO';
|
|
|
|
}
|
|
|
|
});
|
2021-02-17 18:11:27 +00:00
|
|
|
}
|
2020-02-28 15:23:17 +00:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', renderOptions);
|
|
|
|
document.getElementById('save').addEventListener('click', save_options);
|
2020-04-11 17:40:12 +00:00
|
|
|
document.getElementById('sort').addEventListener('click', sort_options);
|
2020-03-08 18:45:19 +00:00
|
|
|
document.getElementById('export').addEventListener('click', export_options);
|
|
|
|
document.getElementById('import').onclick = function () {importInput.click()}
|
|
|
|
document.getElementById('importInput').addEventListener("change", import_options, false);
|
2022-07-24 16:25:42 +00:00
|
|
|
document.getElementById('import_gitlab').addEventListener('click', import_gitlab_options);
|
2020-03-02 17:36:11 +00:00
|
|
|
document.getElementById('add').addEventListener('click', add_options);
|
2020-08-18 18:19:15 +00:00
|
|
|
document.getElementById('delete').addEventListener('click', delete_options);
|
2023-11-06 18:48:00 +00:00
|
|
|
document.getElementById('delete_default').addEventListener('click', delete_default_options);
|
2021-04-29 17:35:59 +00:00
|
|
|
document.getElementById('edit').addEventListener('click', edit_options);
|
2023-07-17 14:40:53 +00:00
|
|
|
if (custom_switch) {
|
|
|
|
document.getElementById('perm_request').addEventListener('click', request_permissions);
|
|
|
|
document.getElementById('perm_remove').addEventListener('click', remove_permissions);
|
|
|
|
}
|