Copy Page URL on Alt+C with Top Center Toast

Copies the current page URL with Alt+C

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 Page URL on Alt+C with Top Center Toast
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Copies the current page URL with Alt+C
// @author       Druid
// @license MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==


(function () {
    'use strict';

    document.addEventListener('keydown', function (event) {
        if (event.altKey && event.code === 'KeyC') {
            event.preventDefault();

            const currentUrl = window.location.href;

            navigator.clipboard.writeText(currentUrl).then(() => {
                showToast("Page link copied!");
            }).catch(err => {
                showToast("Failed to copy link.");
                console.error("Clipboard copy failed:", err);
            });
        }
    });

    function showToast(message) {
        const toast = document.createElement('div');
        toast.textContent = message;
        Object.assign(toast.style, {
            position: 'fixed',
            top: '30px',
            left: '50%',
            transform: 'translateX(-50%)',
            background: '#222',
            color: '#fff',
            padding: '10px 20px',
            fontSize: '16px',
            borderRadius: '6px',
            boxShadow: '0 4px 12px rgba(0,0,0,0.2)',
            zIndex: '9999',
            opacity: '0',
            transition: 'opacity 0.3s ease-in-out',
        });

        document.body.appendChild(toast);

        // Fade in
        requestAnimationFrame(() => {
            toast.style.opacity = '1';
        });

        // Fade out and remove after 2 seconds
        setTimeout(() => {
            toast.style.opacity = '0';
            setTimeout(() => toast.remove(), 300);
        }, 2000);
    }
})();