Disable CMD+S

Prevents websites from intercepting the CMD+S (Save) shortcut on Mac

  1. // ==UserScript==
  2. // @name Disable CMD+S
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Prevents websites from intercepting the CMD+S (Save) shortcut on Mac
  6. // @author Ben Whaley
  7. // @grant none
  8. // @license MIT
  9. // @match https://www.example.com
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function handleKeyDown(event) {
  16. // Check for CMD+S (metaKey is the Command key on Mac)
  17. if (event.metaKey && event.key === 's') {
  18. event.stopPropagation();
  19. console.log('Tampermonkey script intercepted CMD+S');
  20. }
  21. }
  22.  
  23. document.addEventListener('keydown', handleKeyDown, true);
  24.  
  25. function createCustomEventHandler() {
  26. const originalAddEventListener = EventTarget.prototype.addEventListener;
  27.  
  28. EventTarget.prototype.addEventListener = function(type, listener, options) {
  29. if (type === 'keydown') {
  30. const wrappedListener = function(event) {
  31. if (event.metaKey && event.key === 's') {
  32. return;
  33. }
  34. return listener.apply(this, arguments);
  35. };
  36.  
  37. return originalAddEventListener.call(this, type, wrappedListener, options);
  38. }
  39.  
  40. return originalAddEventListener.call(this, type, listener, options);
  41. };
  42. }
  43.  
  44. createCustomEventHandler();
  45.  
  46. console.log('Tampermonkey script loaded: CMD+S shortcut interceptor');
  47. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址