enable-copy.user.js
// ==UserScript==
// @name Enable Copy & Selection Everywhere
// @namespace http://tampermonkey.net/
// @version 1.2
// @description แแฆแแแแแแก แแแแแจแแแแก, แแแแแ แแแแก แแ แฉแแกแแแก แงแแแแ แกแแแขแแ (แแแแแ แแฃแแ แแแ แกแแ)
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
const blockedEvents = [
'copy', 'cut', 'paste',
'contextmenu',
'selectstart',
'dragstart',
'keydown', 'keyup', 'keypress'
];
blockedEvents.forEach(function (evt) {
window.addEventListener(evt, function (e) {
e.stopImmediatePropagation();
}, true);
});
// --- CSS แแฎแแแแ แแ แแฎแแ ---
function injectStyleOnce() {
if (document.getElementById('tm-unlock-style')) return;
const style = document.createElement('style');
style.id = 'tm-unlock-style';
style.innerHTML = `
* {
-webkit-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
-webkit-touch-callout: default !important;
}
`;
(document.head || document.documentElement).appendChild(style);
}
// --- แแขแ แแแฃแขแแแแก แแแฌแแแแแ, debounce-แแ ---
let debounceTimer = null;
function unlockElements() {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(function () {
document.querySelectorAll('[oncopy], [oncut], [onpaste], [oncontextmenu], [onselectstart], [ondragstart], [unselectable]')
.forEach(function (el) {
el.oncopy = null;
el.oncut = null;
el.onpaste = null;
el.oncontextmenu = null;
el.onselectstart = null;
el.ondragstart = null;
el.removeAttribute('unselectable');
});
}, 300); // 300ms-แจแ แแ แแฎแแ แแแฅแกแแแฃแ
}
injectStyleOnce();
unlockElements();
window.addEventListener('DOMContentLoaded', function () {
injectStyleOnce();
unlockElements();
});
// observer แแฎแแ แแซแแแก แแฎแแแแ แแฎแแ แแขแ แแแฃแขแแแก/แแแแแแแขแแแก, แแ แ แงแแแแแคแแ แก แงแแแแ แฌแแแก
const observer = new MutationObserver(function (mutations) {
// แแคแแแขแ แแแ แฉแแแแแแ style แขแแแแ แ แแแฅแชแแแก
const relevant = mutations.some(m =>
!(m.addedNodes.length === 1 && m.addedNodes[0].id === 'tm-unlock-style')
);
if (relevant) unlockElements();
});
observer.observe(document.documentElement, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['oncopy', 'oncontextmenu', 'onselectstart', 'style', 'unselectable']
});
})();