Skip to content

Instantly share code, notes, and snippets.

@fallaciousreasoning
Created August 18, 2019 02:14
Show Gist options
  • Save fallaciousreasoning/7bda9a82307abdd140789dc6ee41e3f6 to your computer and use it in GitHub Desktop.
Save fallaciousreasoning/7bda9a82307abdd140789dc6ee41e3f6 to your computer and use it in GitHub Desktop.
Opens magnet links in a new tab. This is useful if you have a website registered as a handler for magnet:// links (such as instant.io, or Deluge Web)
// ==UserScript==
// @name Magnet Links in New Tab
// @namespace Violentmonkey Scripts
// @match https://thepiratebay.*/*
// @match *://audiobookbay.*/*
// @grant none
// ==/UserScript==
const poll = (action, regularity) => {
action();
setTimeout(() => poll(action, regularity), regularity);
}
const openMagnetsInNewTab = () => {
const untargeted = document.querySelectorAll("a[href^='magnet']:not([target])");
for (const a of untargeted)
a.setAttribute('target', '_blank');
}
poll(openMagnetsInNewTab, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment