-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
archive-submission.js
executable file
·41 lines (32 loc) · 1.12 KB
/
archive-submission.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
function init(metadata) {
if (metadata.path === "/item" && metadata.item.type === "story") {
const storyLink = document.querySelector("span.titleline a").href;
const separatorPipe = document.createTextNode(" | ");
const archiveButton = document.createElement("a");
archiveButton.innerText = "archive";
archiveButton.href =
"https://wayback.now.sh/" + encodeURIComponent(storyLink);
archiveButton.target = "_blank";
archiveButton.classList.add("__rhn__archive-button");
const targetParent =
document.querySelector("table.fatitem td.subtext span.subline") ||
document.querySelector("table.fatitem span.comhead");
if (!targetParent) return false;
const targetSibling = targetParent.querySelector("a.hnpast").nextSibling;
if (!targetSibling) return false;
targetParent.insertBefore(separatorPipe, targetSibling);
targetParent.insertBefore(archiveButton, targetSibling);
return true;
}
return false;
}
const details = {
id: "archive-submission",
pages: {
include: ["/item"],
exclude: [],
},
loginRequired: false,
init,
};
export default details;