Delink on Touch

Stop showing context menu when long-pressing a link, enable text selection.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name Delink on Touch
// @version 0.1.2
// @description Stop showing context menu when long-pressing a link, enable text selection.
// @homepageURL https://github.com/eight04/delink-on-touch
// @supportURL https://github.com/eight04/delink-on-touch/issues
// @license MIT
// @author eight04 <[email protected]>
// @namespace https://github.com/eight04
// @match *://*/*
// @grant GM_registerMenuCommand
// ==/UserScript==

/* global GM_registerMenuCommand */

let id;

register();

function register() {
  id = GM_registerMenuCommand("Enable", init, {id});
}

function init() {
  const links = new Map();
  GM_registerMenuCommand("Disable", uninit, {id});

  document.addEventListener("touchstart", onTouchStart);
  document.addEventListener("touchend", onTouchEnd);

  let timeoutId;

  function onTouchStart(e) {
    clearTimeout(timeoutId);
    // add a delay so users can still tap the link without triggering this
    timeoutId = setTimeout(() => {
      const a = e.target.closest("a");
      if (a && a.getAttribute("href") && e.target.textContent) {
        links.set(a, a.href);
        a.href = "";
      }
    }, 150);
  }

  function onTouchEnd() {
    clearTimeout(timeoutId)
    for (const [a, href] of links) {
      a.href = href;
    }
    links.clear();
  }

  function uninit() {
    register();
    document.removeEventListener("touchstart", onTouchStart);
    document.removeEventListener("touchend", onTouchEnd)
  }
}