The problem concerns the particular site: tickets order on NS.nl. On that page there is text input field to enter the email, and that field has Ctrl-V (paste) disabled.
Question: What Greasemonkey script will enable paste on the field?
I have looked into various solutions, namely:
and came to the following script which (unfortunately) does not work for the given site (testing with FF v40, Greasemonkey v3.4):
// Taken from http://userscripts-mirror.org/scripts/review/40760
unsafeWindow.disable_paste = function() { return true; };
// jQuery is already available on the page:
var $j = jQuery.noConflict();
// Site generates the form on-the-fly, so we schedule the necessary modifications for later:
setTimeout(function() {
$j(document).off('copy paste', '[data-regex=email], [data-regex=emailRepeat]');
$j(document).off('keyup keydown keypress cut copy paste');
// Taken from https://stackoverflow.com/questions/28266689/how-to-enable-paste-on-html-page-with-locked-cmdv
$j('*').each(function(){
$j(this).unbind('paste');
});
}, 2000);
Delayed execution (via setTimeout()
) is used because the site builds the form dynamically. The "problematic" element is shown on the following screenshot:
Enable copy paste on websites that have disabled copy paste. How to use: - Click on the extension icon - After a popup is opened, use the “Enable copy paste for all websites” checkbox. - Manually refresh the page and see if the extension has successfully enabled copy paste functionality on the website.
Press Ctrl + U (PC) or ⌘ Cmd + ⌥ Option + U (Mac). This option will display the website's source code in any web browser. As long as the text you want to copy isn't an image, you'll be able to copy it from the source code and paste it anywhere.
In a HTML page user should not be allowed to copy a text, but at the same time I want to give option for the user to select a particular text (for highlighting purpose). That means CTRL + C should be disabled and CTRL + A should be enabled.
The selected answer did not work for me. I found this simple script did work though:
document.addEventListener('paste', function(e) {
e.stopImmediatePropagation();
return true;
}, true);
Which was found here: https://www.howtogeek.com/251807/how-to-enable-pasting-text-on-sites-that-block-it/
Edit: May need to stop propagation for keydown
as well for some websites.
document.addEventListener('keydown', function(e) {
e.stopImmediatePropagation();
return true;
}, true);
To unbind the events you should provide the original handler set by the page:
// ==UserScript==
// @name Re-enable copy/paste of emails
// @include https://www.ns.nl/producten/s/railrunner*
// @grant none
// ==/UserScript==
$(function() {
$(document).off("copy paste",
"[data-regex=email], [data-regex=emailRepeat]",
$._data(document, "events").paste[0].handler);
});
Another method that turned out to work only in Chrome is to assign a direct event listener for oncopy
/onpaste
element properties, thus it'll have a higher priority than the site's listeners attached to the document
. In your listener prevent other listeners from seeing the event via stopImmediatePropagation:
var input = document.querySelector("[data-regex=email], [data-regex=emailRepeat]");
input.onpaste = input.oncopy = function(event) { event.stopImmediatePropagation() };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With