-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiveExtractor.js
68 lines (58 loc) · 2.29 KB
/
archiveExtractor.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
64
65
66
67
68
// ==UserScript==
// @name Extract National Archives Release Links
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Extracts All Links To TXT
// @match https://www.archives.gov/research/jfk/release-2025
// @match https://www.archives.gov/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const baseURL = "https://www.archives.gov";
function downloadFile(content, filename) {
const blob = new Blob([content], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function extractLinks() {
console.log("Extracting links...");
const links = document.querySelectorAll("td a");
let linkList = "";
links.forEach(link => {
let href = link.getAttribute("href");
if (!href.startsWith("http")) {
href = baseURL + href;
}
console.log("Found link:", href);
linkList += href + "\n";
});
downloadFile(linkList, "Release_Links.txt");
console.log("Download initiated.");
}
// Create a start button
const startButton = document.createElement("button");
startButton.textContent = "Start Script";
startButton.style.position = "fixed";
startButton.style.top = "10px";
startButton.style.right = "10px";
startButton.style.zIndex = "1000";
document.body.appendChild(startButton);
startButton.addEventListener("click", function() {
console.log("Script started.");
// Add a button to trigger the extraction
const downloadButton = document.createElement("button");
downloadButton.textContent = "Download Links";
downloadButton.style.position = "fixed";
downloadButton.style.top = "40px";
downloadButton.style.right = "10px";
downloadButton.style.zIndex = "1000";
downloadButton.addEventListener("click", extractLinks);
document.body.appendChild(downloadButton);
startButton.remove(); // Remove start button after activation
});
})();