Skip to content

Commit

Permalink
added support for gazzetta+ paywall (thanks to Heliosmaster!)
Browse files Browse the repository at this point in the history
  • Loading branch information
gall0ws committed Sep 28, 2021
1 parent 075c782 commit 69eef18
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
48 changes: 39 additions & 9 deletions freeRep.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ==UserScript==
// @name freeRep
// @version 1.2
// @version 1.4
// @include https://*.repubblica.it/*
// @include https://*.lastampa.it/*
// @include https://*.gazzetta.it/*_preview.shtml*
// @grant none
// ==/UserScript==
const log = (...args) => console.log("freeRep:", ...args)
Expand All @@ -15,18 +16,33 @@ const checkAttr = (el, name, value) => {
return retv
}

const checkClassName = (el, name) => el.classList && el.classList.contains(name)
const hide = el => { if (el) { el.style.display = "none" } }
const removeAttr = (el, name) => { el && el.attributes.removeNamedItem(name) }

const isPaywall = el => checkAttr(el, "subscriptions-section", "content")
const isPreview = el => checkAttr(el, "subscriptions-section", "content-not-granted")
const isBanner = el => el && el.classList && el.classList.contains("paywall-static")
const isNewPaywall = el => el.classList && el.classList.contains("paywall__content")
const isBanner = el => checkClassName(el, "paywall-static")
const isNewPaywall = el => checkClassName(el, "paywall__content")
const isGazzettaPaywall = el => checkClassName(el, "bck-freemium__wall")
const isGazzettaPartnerLink = el => checkClassName(el, "is-partner-link")
const isGazzettaContent = el => checkAttr(el, "class", "content") // exact match
const isLaStampa = () => location.host.endsWith("lastampa.it")
const isGazzettaIt = () => location.host.endsWith("gazzetta.it")

const buildAmpPath = () => {
let path = "./amp/"
if (isLaStampa()) {
path = location.pathname + "/amp"
} else if (isGazzettaIt()) {
path = location.pathname.replace(/_preview(.shtml).*/, '$1/amp')
}
return path
}

const createAmpLink = () => {
const a = document.createElement("A")
a.href = (isLaStampa() ? location.pathname : ".") + "/amp"
a.href = buildAmpPath()
a.innerText = "Clicca qui per visualizzare l'articolo completo"
const div = document.createElement("DIV")
div.style = "margin: auto"
Expand Down Expand Up @@ -62,11 +78,25 @@ const tryFindNode = (root, predicate, timeout =50, tlimit =5000) => new Promise(
rec(timeout)
})

freeRep = () => {
let el;
if (!window.location.pathname.endsWith("/amp/") &&
(el = findNode(document, isNewPaywall))) {
el.replaceChildren(createAmpLink())
const freeRep = () => {
if (!window.location.pathname.endsWith("/amp/")) {
if (isGazzettaIt()) {
[isGazzettaPaywall, isGazzettaPartnerLink].forEach(p => {
const el = findNode(document, p)
if (el) {
el.remove()
}
})
const content = findNode(document, isGazzettaContent)
if (content) {
content.appendChild(createAmpLink())
}
} else {
const el = findNode(document, isNewPaywall);
if (el) {
el.replaceChildren(createAmpLink())
}
}
} else {
tryFindNode(document, isPaywall).then(paywall => {
hide(findNode(document, isBanner))
Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "free Rep:",
"version": "1.3",
"version": "1.4",
"description": "Bypass Rep: paywall.",
"icons": {
"48": "icons/freeRep-48.png"
Expand All @@ -10,7 +10,8 @@
{
"matches": [
"https://*.repubblica.it/*",
"https://*.lastampa.it/*"
"https://*.lastampa.it/*",
"https://*.gazzetta.it/*_preview.shtml*"
],
"run_at": "document_idle",
"js": [
Expand Down

0 comments on commit 69eef18

Please sign in to comment.