Disable Ctrl+C Override

Prevents websites from overriding the default Ctrl+C copy functionality.

  1. // ==UserScript==
  2. // @name Disable Ctrl+C Override
  3. // @version 1.0
  4. // @description Prevents websites from overriding the default Ctrl+C copy functionality.
  5. // @grant none
  6. // @match http://*/*
  7. // @match https://*/*
  8. // @run-at document-start
  9. // @namespace http://tampermonkey.net/
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. function preventCopyOverride(e) {
  15. if (e.ctrlKey && e.keyCode === 67) { // Check for Ctrl+C
  16. e.preventDefault();
  17. e.stopImmediatePropagation();
  18.  
  19. // Manually copy selected text to clipboard if there's a selection
  20. const selection = window.getSelection().toString();
  21. if (selection) {
  22. navigator.clipboard.writeText(selection);
  23. }
  24. }
  25. }
  26.  
  27. document.addEventListener('keydown', preventCopyOverride, true);
  28. })();