Copy current url

Copy current website url by pressing yy

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo 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         Copy current url
// @namespace    https://greasyfork.org/en/users/901750-gooseob
// @version      1.1.1
// @description  Copy current website url by pressing yy
// @author       GooseOb
// @license      MIT
// @match        *://*/*
// ==/UserScript==

(function () {
  const isInput = (element) => {
    const tagName = element.tagName.toLowerCase();
    return (
      tagName === "input" || tagName === "textarea" || element.isContentEditable
    );
  };

  const listenForDoublePress = (check, action) => {
    let timeout = 0;
    document.addEventListener("keyup", (e) => {
      if (check(e)) {
        if (timeout) {
          action();
          clearTimeout(timeout);
          timeout = 0;
        } else {
          timeout = setTimeout(() => {
            timeout = 0;
          }, 1000);
        }
      }
    });
  };

  listenForDoublePress(
    // 89 is y. Using `e.code` to support different keyboard layouts
    (e) => e.code === "KeyY" && !isInput(e.target),
    () => navigator.clipboard.writeText(window.location.href),
  );
})();