magnet-target-blank

Open magnet links in a new tab

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         magnet-target-blank
// @namespace    github.com/kugland/magnet-target-blank
// @version      0.0.1
// @author       André Kugland <[email protected]>
// @description  Open magnet links in a new tab
// @license      MIT
// @homepage     https://github.com/kugland/magnet-target-blank
// @homepageURL  https://github.com/kugland/magnet-target-blank
// @match        *://*/*
// @grant        GM.openInTab
// ==/UserScript==

(function () {
  'use strict';

  const listener = (event) => {
    const target = event.target;
    if (target.tagName === "A") {
      const href = target.href;
      if (typeof href === "string" && href.startsWith("magnet:")) {
        event.preventDefault();
        event.stopPropagation();
        GM.openInTab(href);
      }
    }
  };
  document.addEventListener("click", listener, { capture: true });
  document.addEventListener("tap", listener, { capture: true });

})();