// ==UserScript== // @name 问卷星解除复制粘贴限制 // @namespace https://scriptscat.org/ // @version 1.0.0 // @description 解除问卷星页面的复制/粘贴/右键/选中限制 // @match *://*.wjx.cn/* // @match *://ks.wjx.com/* // @match *://*.wjx.top/* // @run-at document-start // @grant none // @tag 问卷星 // @tag 学习 // @tag copy // @tag paste // @author ayiyaha // @license Apache-2.0 // ==/UserScript== (function () { 'use strict'; const BLOCK_EVENTS = [ 'contextmenu', 'copy', 'cut', 'paste', 'selectstart', 'dragstart' ]; const style = document.createElement('style'); style.textContent = ` html, body, * { -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); const allowHandler = (e) => { e.stopImmediatePropagation(); e.stopPropagation(); }; BLOCK_EVENTS.forEach((evt) => { document.addEventListener(evt, allowHandler, true); window.addEventListener(evt, allowHandler, true); }); function clearDom0Handlers(root = document) { const nodes = root.querySelectorAll ? root.querySelectorAll('*') : []; const all = [root, ...nodes]; for (const el of all) { for (const evt of BLOCK_EVENTS) { const key = 'on' + evt; if (key in el) { try { el[key] = null; } catch (_) {} } } } } function removeOverlays(root = document) { const selectors = [ '#divS', '#divWorkError', '[id*="mask"]', '[class*="mask"]', '[class*="overlay"]' ]; for (const sel of selectors) { root.querySelectorAll(sel).forEach((el) => { const styleText = (el.getAttribute('style') || '').toLowerCase(); const isFullscreen = styleText.includes('position: fixed') && styleText.includes('top: 0') && styleText.includes('left: 0') && styleText.includes('right: 0') && styleText.includes('bottom: 0'); if (sel === '#divS' || isFullscreen) { el.style.display = 'none'; el.style.pointerEvents = 'none'; } }); } } function unlockInputs(root = document) { const inputs = root.querySelectorAll('textarea, input[type="text"], input:not([type])'); inputs.forEach((el) => { if (el.hasAttribute('readonly')) { el.removeAttribute('readonly'); } if (el.hasAttribute('disabled')) { el.removeAttribute('disabled'); } el.style.userSelect = 'text'; el.style.webkitUserSelect = 'text'; }); } function applyAll(root = document) { clearDom0Handlers(root); removeOverlays(root); unlockInputs(root); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => applyAll(document), { once: true }); } else { applyAll(document); } const observer = new MutationObserver((mutations) => { for (const m of mutations) { m.addedNodes.forEach((node) => { if (node.nodeType === 1) { applyAll(node); } }); } }); observer.observe(document.documentElement, { childList: true, subtree: true }); setInterval(() => applyAll(document), 1500); console.log('[WJX-Unlock] copy/paste/contextmenu unlock injected.'); })();