Prevent Paste Hijacking

Prevents websites from hijacking paste events and forces native text insertion. Hides paste event from the website.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Prevent Paste Hijacking
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @grant       none
// @version     1.1
// @description Prevents websites from hijacking paste events and forces native text insertion. Hides paste event from the website.
// @run-at      document-start
// @author      koza.dev
// @license     MIT
// ==/UserScript==



// Hide Ctrl+V keydown from the site unconditionally,
// since we cannot read the clipboard during a keydown event
window.addEventListener('keydown', function(e) {
    if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'v') {
        e.stopImmediatePropagation()
    }
}, true)

window.addEventListener('paste', function(e) {
    if (!e.clipboardData) return

    // If the clipboard contains files (like an image), abort the script
    // and let the website process the paste normally
    if (e.clipboardData.files.length > 0) return

    // If it's just text, hide the event from the website and force native paste
    e.stopImmediatePropagation()
}, true)