Forcefully remove webpage copy restrictions.

"Remove the webpage's copy restrictions, and disable the right-click and text selection restrictions."

  1. // ==UserScript==
  2. // @name Forcefully remove webpage copy restrictions.
  3. // @namespace https://www.cnblogs.com/lusuo
  4. // @version 1.0
  5. // @description "Remove the webpage's copy restrictions, and disable the right-click and text selection restrictions."
  6. // @author Joanne
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13. // 解锁右键菜单
  14. document.addEventListener('contextmenu', function (e) {
  15. e.stopPropagation();
  16. }, true);
  17. // 解锁复制功能
  18. document.addEventListener('copy', function (e) {
  19. e.stopPropagation();
  20. }, true);
  21. // 解锁选择文本功能
  22. document.addEventListener('selectstart', function (e) {
  23. e.stopPropagation();
  24. }, true);
  25. // 遍历所有元素,移除相关属性
  26. const elements = document.querySelectorAll('*');
  27. elements.forEach(el => {
  28. el.removeAttribute('oncopy');
  29. el.removeAttribute('onpaste');
  30. el.removeAttribute('oncut');
  31. el.removeAttribute('oncontextmenu');
  32. el.removeAttribute('onselectstart');
  33. el.removeAttribute('onmousedown');
  34. });
  35. // 设置样式来解除选择限制
  36. const style = document.createElement('style');
  37. style.innerHTML = `
  38. * {
  39. -webkit-user-select: text !important;
  40. -moz-user-select: text !important;
  41. -ms-user-select: text !important;
  42. user-select: text !important;
  43. }
  44. `;
  45. document.head.appendChild(style);
  46. console.log('脚本已运行:解除网页复制限制成功!');
  47. })();