Selection and Copying Restorer

Unlock right-click, remove restrictions on copy, cut, select text, right-click menu, text copying, text selection, image right-click, and enhance functionality: Alt key hyperlink text selection.

当前为 2024-05-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Selection and Copying Restorer
  3. // @version 0.1
  4. // @description Unlock right-click, remove restrictions on copy, cut, select text, right-click menu, text copying, text selection, image right-click, and enhance functionality: Alt key hyperlink text selection.
  5. // @namespace https://greasyfork.org/users/1300060
  6. // @author AstralRift
  7. // @run-at document-start
  8. // @match *://*/*
  9. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  10. // @exclude https://github.dev/*
  11. // @exclude https://vscode.dev/*
  12. // @exclude https://www.photopea.com/*
  13. // @exclude https://www.google.com/maps/*
  14. // @exclude https://docs.google.com/*
  15. // @exclude https://drive.google.com/*
  16. // @exclude https://mail.google.com/*
  17. // @exclude https://www.dropbox.com/*
  18. // @exclude https://outlook.live.com/mail/*
  19. // @exclude https://www.terabox.com/*
  20. // @exclude https://leetcode.cn/*
  21. // @exclude https://facebook.com/*
  22. // @exclude https://m.facebook.com/*
  23. // @grant GM_registerMenuCommand
  24. // @grant GM_unregisterMenuCommand
  25. // @grant GM.setValue
  26. // @grant GM.getValue
  27. // @grant GM_addValueChangeListener
  28. // @grant unsafeWindow
  29. // @inject-into page
  30. // @license MIT
  31. // ==/UserScript==
  32.  
  33. (async function() {
  34. 'use strict';
  35.  
  36. function getSelectionText() {
  37. return window.getSelection ? window.getSelection().toString() : '';
  38. }
  39.  
  40. function unlockTextSelection() {
  41. document.querySelectorAll('*').forEach(el => {
  42. el.style.userSelect = 'text';
  43. el.style.webkitUserSelect = 'text';
  44. el.style.MozUserSelect = 'text';
  45. });
  46. }
  47.  
  48. unlockTextSelection();
  49.  
  50. document.addEventListener('contextmenu', event => event.stopPropagation(), true);
  51. document.addEventListener('copy', event => {
  52. if (!getSelectionText()) {
  53. event.preventDefault();
  54. }
  55. }, true);
  56.  
  57. document.addEventListener('cut', event => {
  58. if (!getSelectionText()) {
  59. event.preventDefault();
  60. }
  61. }, true);
  62.  
  63. document.addEventListener('keydown', function(event) {
  64. if (event.altKey && (event.key === 'c' || event.key === 'C')) {
  65. navigator.clipboard.writeText(getSelectionText()).then(() => {
  66. console.log('Text copied to clipboard');
  67. }).catch(err => {
  68. console.error('Failed to copy text: ', err);
  69. });
  70. }
  71. });
  72. })();