21 lines
708 B
JavaScript
21 lines
708 B
JavaScript
let magnets = [...document.querySelectorAll('a')].map(a => a.href).filter(href => href.startsWith('magnet:')).join('\n');
|
|
|
|
if (magnets.length > 0) {
|
|
let tempTextArea = document.createElement('textarea');
|
|
tempTextArea.value = magnets;
|
|
document.body.appendChild(tempTextArea);
|
|
tempTextArea.select();
|
|
|
|
try {
|
|
let successful = document.execCommand('copy');
|
|
let msg = successful ? 'Successfully copied to clipboard!' : 'Failed to copy to clipboard!';
|
|
console.log(msg);
|
|
} catch (err) {
|
|
console.error('Fallback: Oops, unable to copy', err);
|
|
}
|
|
|
|
document.body.removeChild(tempTextArea);
|
|
} else {
|
|
console.log('No magnet links found on this page.');
|
|
}
|