Skip to content

Commit

Permalink
background listener work
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed Mar 14, 2020
1 parent 0bcadd8 commit fbce4bb
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -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"]
);
33 changes: 19 additions & 14 deletions components/funke.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const d = document;
// ____
// __ _____ ___ ___ ___ ___ _____ _/ / /
// / // / _ \/ _ \/ _ `/ // / |/|/ / _ `/ / /
// \_,_/_//_/ .__/\_,_/\_, /|__,__/\_,_/_/_/
// /_/ /___/
//
// lensing media component
// github.com/tobimori/unpaywall
//
// notes:
// blocking of funke script done in background.js
//

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")
);
}
});
const d = document;

observer.observe(document, {
childList: true,
subtree: true
});
if (d.getElementsByClassName('article__header__headline ispayedcontent')) {
removeElements(
d.getElementsByClassName("paging__wrapper"),
d.getElementsByClassName("pager pager__bottom")
);
};
6 changes: 2 additions & 4 deletions components/lensingmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;};
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
"128": "icons/icon-128.png"
},

"background": {
"scripts": ["lib.js", "background.js"]
},

"permissions": [
"<all_urls>",
"webRequest",
"webRequestBlocking"
],

"content_scripts": [
{
"matches": [
Expand Down
3 changes: 2 additions & 1 deletion popout/popout.css
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit fbce4bb

Please sign in to comment.