问题涉及特定站点:tickets order on NS.nl .在该页面上有用于输入电子邮件的文本输入字段,并且该字段已禁用 Ctrl-V(粘贴)。
问题:什么 Greasemonkey 脚本可以在字段上启用粘贴?
我研究了各种解决方案,即:
并得出以下脚本(不幸的是)不适用于给定站点(使用 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);
使用延迟执行(通过 setTimeout()
)是因为站点动态构建表单。 “有问题的”元素显示在以下屏幕截图中:
最佳答案
所选答案对我不起作用。我发现这个简单的脚本确实有效:
document.addEventListener('paste', function(e) {
e.stopImmediatePropagation();
return true;
}, true);
在此处找到:https://www.howtogeek.com/251807/how-to-enable-pasting-text-on-sites-that-block-it/
编辑:可能需要停止传播 keydown
以及某些网站。
document.addEventListener('keydown', function(e) {
e.stopImmediatePropagation();
return true;
}, true);
关于javascript - 在网站上启用 "paste"的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32784487/