background listener work

This commit is contained in:
tobimori 2020-03-14 23:38:01 +01:00
parent 0bcadd870c
commit fbce4bbe54
7 changed files with 60 additions and 22 deletions

View File

@ -77,9 +77,7 @@ This unlock mechanism is currently disabled.
### Saarbrücker Zeitung
The Saarbrücker Zeitung saves the complete article and replaces it afterwards.
This unlock mechanism is buggy, but the script providing the paywall mechanisms are blocked in the famous ad blocker uBlock Origin anyways.
The Saarbrücker Zeitung saves the complete article and replaces it afterwards. Their paywall script is pretty bad and blocked by all common adblockers.
### NahverkehrHAMBURG

21
background.js Normal file
View File

@ -0,0 +1,21 @@
// ____
// __ _____ ___ ___ ___ ___ _____ _/ / /
// / // / _ \/ _ \/ _ `/ // / |/|/ / _ `/ / /
// \_,_/_//_/ .__/\_,_/\_, /|__,__/\_,_/_/_/
// /_/ /___/
//
// background listener
// github.com/tobimori/unpaywall
//
// block all tinypass scripts (used by lensing media & funke)
browser.webRequest.onBeforeRequest.addListener(
function(details) {
if (!isListenerPaywalled(details)) return;
return {cancel: true};
}, {
urls: ["*://*.tinypass.com/*"],
types: ["script"]
},
["blocking"]
);

View File

@ -1,16 +1,21 @@
// ____
// __ _____ ___ ___ ___ ___ _____ _/ / /
// / // / _ \/ _ \/ _ `/ // / |/|/ / _ `/ / /
// \_,_/_//_/ .__/\_,_/\_, /|__,__/\_,_/_/_/
// /_/ /___/
//
// lensing media component
// github.com/tobimori/unpaywall
//
// notes:
// blocking of funke script done in background.js
//
const d = document;
const observer = new MutationObserver(function (mutations, me) {
if (d.getElementsByClassName('article__header__headline ispayedcontent')) {
removeElements(
d.getElementsByTagName("script"),
d.getElementsByClassName("paging__wrapper"),
d.getElementsByClassName("pager pager__bottom")
);
}
});
observer.observe(document, {
childList: true,
subtree: true
});
if (d.getElementsByClassName('article__header__headline ispayedcontent')) {
removeElements(
d.getElementsByClassName("paging__wrapper"),
d.getElementsByClassName("pager pager__bottom")
);
};

View File

@ -8,9 +8,7 @@
// github.com/tobimori/unpaywall
//
// notes:
// lensing media uses piano/tinypass, content gets removed afterwards
// blocking of tinypass script done in background.js
//
// TODO: Block Tinypass from loading
document.getElementById("BaseText").classList.remove("PianoContent");
document.getElementById("BaseText").classList.contains("PianoContent") && document.getElementById("BaseText").classList.remove("PianoContent");

5
lib.js
View File

@ -16,3 +16,8 @@ const removeElements = (...arrays) => {
);
}
const listenerPaywalls = [
"abendblatt",
]
const isListenerPaywalled = (details) => { if(listenerPaywalls.contains(details.originUrl.split("/", 3)[2].split(".",2)[1])) return true;};

View File

@ -18,6 +18,16 @@
"128": "icons/icon-128.png"
},
"background": {
"scripts": ["lib.js", "background.js"]
},
"permissions": [
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"content_scripts": [
{
"matches": [

View File

@ -1,4 +1,5 @@
/* The switch - the box around the slider */
/* w3 schools stuff */
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;