解除复制限制

解除复制限制...

// ==UserScript==
// @name         解除复制限制1
// @name:en      解除复制限制.
// @name:zh-CN   解除复制限制
// @namespace    https://palerock.cn
// @version      0.01
// @description:en  解除复制限制en..
// @description:zh-CN  解除复制限制...
// @require      https://greasyfork.org/scripts/372672-everything-hook/code/Everything-Hook.js?version=659315
// @include      *
// @author       qi_liu
// @match        http://*/*
// @run-at       document-start
// @grant        none
// @description 解除复制限制
// @license MIT
// ==/UserScript==
 
'use strict';

(function (global) {
  function removeCopyEvent() {
    Array.prototype.concat.call(document.querySelectorAll('*'), document)
      .forEach(function (ele) {
        ele.oncopy = undefined;
        ele.oncontextmenu = undefined;
      });
  }

  function core() {
    global.addEventListener('contextmenu', removeCopyEvent);
    global.addEventListener('keydown', (e) => {
      if (e.ctrlKey || [17, 91, 93, 224].includes(e.keyCode)) {
        removeCopyEvent();
      }
    });

    // 这里不使用 hook,直接覆盖 addEventListener 也可以,但稍复杂

    // 注入 CSS
    const style = `
      body *:not(input):not(textarea) {
        -webkit-user-select: auto !important;
        -moz-user-select: auto !important;
        -ms-user-select: auto !important;
        user-select: auto !important;
      }
    `;

    const styleNode = document.createElement('style');
    styleNode.type = 'text/css';
    if (styleNode.styleSheet) {
      styleNode.styleSheet.cssText = style;
    } else {
      styleNode.appendChild(document.createTextNode(style));
    }

    document.addEventListener('readystatechange', () => {
      if (['interactive', 'complete'].includes(document.readyState)) {
        setTimeout(() => {
          document.head.appendChild(styleNode);
        }, 2000);
      }
    });
  }

  core();

})(window);