139 lines
4.8 KiB
JavaScript
139 lines
4.8 KiB
JavaScript
// ==UserScript==
|
|
// @name Bypass Paywalls Clean - fi/se
|
|
// @version 3.8.8.0
|
|
// @description Bypass Paywalls of news sites
|
|
// @author magnolia1234
|
|
// @downloadURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.fi.se.user.js
|
|
// @updateURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=userscript/bpc.fi.se.user.js
|
|
// @homepageURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
|
|
// @supportURL https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters
|
|
// @license MIT; https://gitflic.ru/project/magnolia1234/bypass-paywalls-clean-filters/blob/raw?file=LICENSE
|
|
// @match *://*.etc.se/*
|
|
// @match *://*.suomensotilas.fi/*
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
window.setTimeout(function () {
|
|
|
|
var domain;
|
|
var mobile = window.navigator.userAgent.toLowerCase().includes('mobile');
|
|
var csDoneOnce;
|
|
|
|
var overlay = document.querySelector('body.didomi-popup-open');
|
|
if (overlay)
|
|
overlay.classList.remove('didomi-popup-open');
|
|
var ads = 'div.OUTBRAIN, div[id^="taboola-"], div.ad, div.ad-container, div[class*="-ad-container"], div[class*="_ad-container"], div.arc_ad';
|
|
hideDOMStyle(ads, 10);
|
|
|
|
if (matchDomain('etc.se')) {
|
|
let paywall = document.querySelector('div.paywalled');
|
|
if (paywall) {
|
|
paywall.removeAttribute('class');
|
|
let gradient = document.querySelector('div.bg-gradient-white');
|
|
if (gradient)
|
|
gradient.removeAttribute('class');
|
|
let footer = document.querySelector('section > footer');
|
|
if (footer)
|
|
removeDOMElement(footer.parentNode);
|
|
}
|
|
let ads = 'div[class$="-ad"]';
|
|
hideDOMStyle(ads);
|
|
let video_iframes = document.querySelectorAll('div.embed-block > iframe[width][height]');
|
|
for (let elem of video_iframes) {
|
|
if (elem.width > 1000) {
|
|
let ratio = elem.width / (mobile ? 320 : 640);
|
|
elem.width = elem.width / ratio;
|
|
elem.height = elem.height / ratio;
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (matchDomain('suomensotilas.fi')) {
|
|
let obscured = document.querySelector('div.epfl-pw-obscured');
|
|
if (obscured)
|
|
obscured.classList.remove('epfl-pw-obscured');
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
// General Functions
|
|
|
|
function matchDomain(domains, hostname) {
|
|
var matched_domain = false;
|
|
if (!hostname)
|
|
hostname = window.location.hostname;
|
|
if (typeof domains === 'string')
|
|
domains = [domains];
|
|
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
|
|
return matched_domain;
|
|
}
|
|
|
|
function removeDOMElement(...elements) {
|
|
for (let element of elements) {
|
|
if (element)
|
|
element.remove();
|
|
}
|
|
}
|
|
|
|
function hideDOMElement(...elements) {
|
|
for (let element of elements) {
|
|
if (element)
|
|
element.style = 'display:none !important;';
|
|
}
|
|
}
|
|
|
|
function hideDOMStyle(selector, id = 1) {
|
|
let style = document.querySelector('head > style#ext'+ id);
|
|
if (!style && document.head) {
|
|
let sheet = document.createElement('style');
|
|
sheet.id = 'ext' + id;
|
|
sheet.innerText = selector + ' {display: none !important;}';
|
|
document.head.appendChild(sheet);
|
|
}
|
|
}
|
|
|
|
function addStyle(css, id = 1) {
|
|
let style = document.querySelector('head > style#add'+ id);
|
|
if (!style && document.head) {
|
|
let sheet = document.createElement('style');
|
|
sheet.id = 'add' + id;
|
|
sheet.innerText = css;
|
|
document.head.appendChild(sheet);
|
|
}
|
|
}
|
|
|
|
function archiveLink(url, text_fail = 'BPC > Try for full article text (no need to report issue for external site):\r\n') {
|
|
return externalLink(['archive.today', 'archive.is'], 'https://{domain}?run=1&url={url}', url, text_fail);
|
|
}
|
|
|
|
function nftLink(url, text_fail = 'BPC > Full article text:\r\n') {
|
|
return externalLink(['1ft.io'], 'https://{domain}/{url}', url, text_fail);
|
|
}
|
|
|
|
function externalLink(domains, ext_url_templ, url, text_fail = 'BPC > Full article text:\r\n') {
|
|
let text_fail_div = document.createElement('div');
|
|
text_fail_div.id = 'bpc_archive';
|
|
text_fail_div.setAttribute('style', 'margin: 20px; font-size: 20px; font-weight: bold; color: red;');
|
|
let parser = new DOMParser();
|
|
text_fail = text_fail.replace(/\[(?<url>[^\]]+)\]/g, function (match, url) {
|
|
return "<a href='" + url + "' target='_blank' style='color: red'>" + new URL(url).hostname + "</a>";
|
|
});
|
|
let doc = parser.parseFromString('<span>' + text_fail + '</span>', 'text/html');
|
|
let elem = doc.querySelector('span');
|
|
text_fail_div.appendChild(elem);
|
|
for (let domain of domains) {
|
|
let ext_url = ext_url_templ.replace('{domain}', domain).replace('{url}', url.split('?')[0]);
|
|
let a_link = document.createElement('a');
|
|
a_link.innerText = domain;
|
|
a_link.href = ext_url;
|
|
a_link.target = '_blank';
|
|
text_fail_div.appendChild(document.createTextNode(' | '));
|
|
text_fail_div.appendChild(a_link);
|
|
}
|
|
return text_fail_div;
|
|
}
|
|
|
|
})();
|