-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save Links from Webpages.user.js
62 lines (52 loc) · 1.81 KB
/
Save Links from Webpages.user.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
61
62
// ==UserScript==
// @name Save Links from Webpages
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Save links from all websites visited
// @author You
// @match *://*/*
// @grant GM_download
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
const storageKey = 'collectedLinks';
let links = new Set(JSON.parse(localStorage.getItem(storageKey) || "[]"));
// Collect all the links from the current page
document.querySelectorAll('a').forEach(a => {
const href = a.href;
if (href && href.startsWith('http')) { // To ensure we are only collecting valid URLs
links.add(href);
}
});
// Store the updated set of links in local storage
localStorage.setItem(storageKey, JSON.stringify([...links]));
// Provide a button to download the links
const downloadButton = document.createElement('button');
downloadButton.innerText = 'Download Links';
downloadButton.style.position = 'fixed';
downloadButton.style.bottom = '10px';
downloadButton.style.right = '10px';
downloadButton.style.zIndex = '9999';
GM_addStyle(`
button {
padding: 5px 15px;
font-size: 14px;
cursor: pointer;
background-color: #007BFF;
color: #FFF;
border: none;
border-radius: 5px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
`);
downloadButton.onclick = () => {
const blob = new Blob([[...links].join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
GM_download({url: url, name: 'links.txt', saveAs: true});
};
document.body.appendChild(downloadButton);
})();