forked from plibither8/refined-hacker-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-submission.js
39 lines (31 loc) · 1.01 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
function init(metadata) {
if (metadata.path === '/item' && metadata.item.type === 'story') {
const storyLink = document.querySelector('a.storylink').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') ||
document.querySelector('table.fatitem span.comhead');
const targetSibling = targetParent.querySelector('a[href^="https://www.google.com"]').nextSibling;
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;