Last active
January 10, 2024 16:21
-
-
Save itszechs/c5f69d5e05aa749599324f0cdb30efce to your computer and use it in GitHub Desktop.
Copy all the magnet links from the page
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
| const magnetLinksXPath = document.evaluate( | |
| "//tr[@class='default']/td[@class='text-center'][1]/a[2]/@href", | |
| document, | |
| null, | |
| XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, | |
| null | |
| ); | |
| const magnetLinks = []; | |
| for (let i = 0; i < magnetLinksXPath.snapshotLength; i++) { | |
| const link = magnetLinksXPath.snapshotItem(i).nodeValue; | |
| magnetLinks.push(link); | |
| } | |
| if (magnetLinks.length > 0) { | |
| const tempTextarea = document.createElement('textarea'); | |
| tempTextarea.style.cssText = 'position: absolute; top: -9999px;'; | |
| tempTextarea.textContent = magnetLinks.join('\n'); | |
| document.body.appendChild(tempTextarea); | |
| tempTextarea.select(); | |
| document.execCommand('copy'); | |
| document.body.removeChild(tempTextarea); | |
| alert(`${magnetLinks.length} magnet links copied to clipboard.`); | |
| } else { | |
| alert('No magnet links found'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment