-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport Image links from session-0.1.user.js
63 lines (53 loc) · 2.04 KB
/
Export Image links from session-0.1.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
63
// ==UserScript==
// @name Extract Image links from session (remove Duplicate)
// @namespace https://github.com/noarche/TamperMonkey-Scripts
// @version 0.1
// @description Scrape IMG URL from visited sites, save as list.txt - Removes duplicate links.
// @author noarche
// @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.endsWith('.jpg') || href.endsWith('.jpeg') || href.endsWith('.png') || href.endsWith('.gif') || href.endsWith('.webp'))) {
// To ensure we are only collecting valid URLs and filtering based on extensions
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 = 'Links';
downloadButton.style.position = 'fixed';
downloadButton.style.bottom = '10px';
downloadButton.style.right = '10px';
downloadButton.style.zIndex = '9999';
GM_addStyle(`
button {
padding: 5px 7px;
font-size: 12px;
cursor: pointer;
background-color: #6781a1;
color: #FFF;
border: none;
border-radius: 5px;
transition: background-color 1.5s;
}
button:hover {
background-color: #6bb28e;
}
`);
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);
})();