Unblock text selection, copy, right-click and remove overlay blockers on all sites
当前为
// ==UserScript==
// @name Copy & Select Unlocker
// @namespace http://shinobu-scripts.local/
// @version 2.1
// @description Unblock text selection, copy, right-click and remove overlay blockers on all sites
// @author Shinobu
// @match *://*/*
// @run-at document-end
// @license GPLv3
// ==/UserScript==
(function() {
'use strict';
// Add CSS to allow text selection
function injectSelectionStyles() {
const css = '* { user-select: text !important; -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; } [style*="user-select: none"], [style*="user-select:none"] { user-select: text !important; }';
const styleEl = document.createElement('style');
styleEl.textContent = css;
document.head.appendChild(styleEl);
}
// Remove full-page overlays
function removeOverlays() {
document.querySelectorAll('div, section').forEach(el => {
const st = getComputedStyle(el);
if ((st.position === 'fixed' || st.position === 'absolute') &&
el.offsetWidth >= window.innerWidth * 0.9 &&
el.offsetHeight >= window.innerHeight * 0.9) {
el.remove();
}
});
}
// Observe and clean overlays
function observeOverlays() {
const obs = new MutationObserver(removeOverlays);
obs.observe(document, { childList: true, subtree: true });
removeOverlays();
}
// Restore native selection events
function restoreEvents() {
['onselectstart', 'onmousedown', 'ondragstart'].forEach(evt => {
document[evt] = null;
});
if (window.getSelection().empty) {
window.getSelection().empty = () => {};
}
}
// Prevent blocking handlers
function stopPropagation(e) {
e.stopImmediatePropagation();
}
// Initialise all features
function init() {
injectSelectionStyles();
document.addEventListener('contextmenu', stopPropagation, true);
document.addEventListener('selectstart', stopPropagation, true);
document.addEventListener('copy', stopPropagation, true);
document.addEventListener('keydown', e => {
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
e.stopImmediatePropagation();
}
}, true);
restoreEvents();
observeOverlays();
console.log('Copy & Select Liberator active');
}
if (document.readyState === 'loading') {
window.addEventListener('load', init);
} else {
init();
}
})();