-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
60 lines (54 loc) · 1.81 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const projects = [
{
name: "Archive.is",
url: "https://archive.is/",
},
{
name: "12ft.io",
url: "https://12ft.io/",
},
{
name: "Archive.org",
url: "https://web.archive.org/web/",
},
];
const paywalls = []; // Add paywall domains from paywalls.json here
let titles = document.querySelectorAll("table tr.athing");
let postTitle = document.querySelector("tbody table.fatitem tr.athing");
// The main function that updates the UI with the links.
const passTheButter = (node) => {
let meta = node.nextSibling.querySelector(".subtext");
let link = node.querySelector(".titleline a").href;
let domain = node.querySelector("span.sitestr") ? node.querySelector("span.sitestr").innerText : "";
let paywall = paywalls.find((paywall) => domain.includes(paywall));
if (paywall) {
let paywallSpan = document.createElement("span");
paywallSpan.appendChild(document.createTextNode(" | 💰"));
projects.forEach((project) => {
const anchor = document.createElement("a");
const line = document.createElement("span");
line.textContent = " | ";
anchor.setAttribute("href", `${project.url}${link}`);
anchor.setAttribute("target", "_blank");
anchor.setAttribute("rel", "noopener noreferrer");
anchor.textContent = project.name;
paywallSpan.appendChild(line);
paywallSpan.appendChild(anchor);
});
paywallSpan.appendChild(document.createTextNode(" | "));
paywallSpan.appendChild(
Object.assign(document.createElement("a"), {
href: `https://github.com/MostlyEmre/hn-anti-paywall`,
target: "_blank",
rel: "noopener noreferrer",
textContent: "ℹ",
})
);
meta.appendChild(paywallSpan);
}
};
postTitle
? passTheButter(postTitle)
: titles.forEach((title) => {
passTheButter(title);
});