Code
JavaScript
(function() {
'use strict';
console.log("@zd6", "color: white; background: green; padding: 4px; font-weight: bold;");
function forcePasteText(element, text) {
element.focus();
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
const start = element.selectionStart;
const end = element.selectionEnd;
const currentVal = element.value;
element.value = currentVal.slice(0, start) + text + currentVal.slice(end);
element.selectionStart = element.selectionEnd = start + text.length;
} else if (element.isContentEditable) {
const selection = window.getSelection();
if (selection.rangeCount) {
selection.deleteFromDocument();
selection.getRangeAt(0).insertNode(document.createTextNode(text));
selection.collapseToEnd();
}
}
const events = ['input', 'change', 'blur'];
events.forEach(type => {
element.dispatchEvent(new Event(type, { bubbles: true }));
});
}
window.addEventListener('paste', function(e) {
const text = (e.clipboardData || window.clipboardData).getData('text/plain');
const target = document.activeElement;
if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)) {
e.preventDefault();
e.stopImmediatePropagation();
forcePasteText(target, text);
console.log("@zd6");
}
}, true);
const style = document.createElement('style');
style.innerHTML = '*{user-select:text!important;-webkit-user-select:text!important;}';
document.head.appendChild(style);
})();
Advanced
Fast
Simple
Updated
Compatible
Reliable