Skip to content

Instantly share code, notes, and snippets.

@itszechs
Last active January 10, 2024 16:21
Show Gist options
  • Select an option

  • Save itszechs/c5f69d5e05aa749599324f0cdb30efce to your computer and use it in GitHub Desktop.

Select an option

Save itszechs/c5f69d5e05aa749599324f0cdb30efce to your computer and use it in GitHub Desktop.
Copy all the magnet links from the page
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