Created
August 25, 2025 18:29
-
-
Save maanimis/f952b22dd7231c0b6ed9d0fc9b59109d to your computer and use it in GitHub Desktop.
Extract all links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Link Gopher Lite (Userscript) | |
| // @namespace https://gist.github.com/maanimis | |
| // @version 1.0 | |
| // @description Extract all links | |
| // @author You | |
| // @match *://*/* | |
| // @grant GM_registerMenuCommand | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| /** | |
| * Extract all links from the page. | |
| */ | |
| function extractLinks() { | |
| const links = []; | |
| for (let i = 0; i < document.links.length; i++) { | |
| links.push(decodeURI(document.links[i].href)); | |
| } | |
| return links.length ? [...new Set(links)].sort() : []; | |
| } | |
| /** | |
| * Open results in a new styled tab. | |
| */ | |
| function showResults(title, list) { | |
| const win = window.open("", "_blank"); | |
| win.document.write(` | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>${title}</title> | |
| <style> | |
| body { | |
| font-family: system-ui, sans-serif; | |
| background: #f9fafb; | |
| margin: 0; | |
| padding: 2rem; | |
| color: #111827; | |
| } | |
| h1 { | |
| font-size: 1.8rem; | |
| margin-bottom: 1rem; | |
| color: #2563eb; | |
| text-align: center; | |
| } | |
| .link-list { | |
| background: #fff; | |
| border-radius: 0.75rem; | |
| padding: 1rem 1.5rem; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.08); | |
| max-width: 900px; | |
| margin: 0 auto; | |
| } | |
| .link-list a { | |
| display: block; | |
| padding: 6px 0; | |
| color: #2563eb; | |
| text-decoration: none; | |
| border-bottom: 1px solid #e5e7eb; | |
| word-break: break-all; | |
| transition: background 0.2s, color 0.2s; | |
| } | |
| .link-list a:hover { | |
| background: #eff6ff; | |
| color: #1e40af; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>${title} (${list.length})</h1> | |
| <div class="link-list"> | |
| ${list.map(link => `<a href="${link}" target="_blank">${link}</a>`).join("")} | |
| </div> | |
| </body> | |
| </html> | |
| `); | |
| win.document.close(); | |
| } | |
| function handler() { | |
| const links = extractLinks(); | |
| if (!links.length) { | |
| alert("No links found on this page."); | |
| return; | |
| } | |
| showResults("Extracted Links", links); | |
| } | |
| // Just one menu command | |
| GM_registerMenuCommand("Extract All Links", handler); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment