禁用浏览器快捷键窗口

chrome、edge等浏览器中会弹出窗口,经常会误触,故禁用所有页面中的快捷键

  1. // ==UserScript==
  2. // @name 禁用浏览器快捷键窗口
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @license MIT
  6. // @grant none
  7. // @author forcier
  8. // @match *://*/*
  9. // @grant unsafeWindow
  10. // @run-at document-start
  11. // @match *://kimi.moonshot.cn/*
  12. // @description chrome、edge等浏览器中会弹出窗口,经常会误触,故禁用所有页面中的快捷键
  13. // @supportURL https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=270
  14. // @homepage https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=270
  15. // ==/UserScript==
  16. (function () {
  17. "use strict";
  18. const style = document.createElement('style');
  19. style.innerHTML = `*{font-size: 苹方-简 !important}`;
  20. document.head.appendChild(style);
  21. function debounce(func, delay) {
  22. let timeout;
  23. return function (...args) {
  24. clearTimeout(timeout);
  25. timeout = setTimeout(() => func.apply(this, args), delay);
  26. };
  27. }
  28. const handleMouseDown = debounce((event) => {
  29. if ('which' in event) {
  30. switch (event.which) {
  31. case 1:
  32. case 2:
  33. case 3:
  34. break;
  35. default:
  36. if (window.history.length === 1) window.close();
  37. break;
  38. }
  39. }
  40. }, 200);
  41. document.addEventListener('mousedown', handleMouseDown);
  42. // 处理键盘按下事件
  43. const keysToPrevent = ['F1', 'F3', 'F7', 'F9'];
  44. document.addEventListener('keydown', function (event) {
  45. if (keysToPrevent.includes(event.key)) {
  46. event.preventDefault();
  47. } else if (event.ctrlKey && (event.key === 's' || event.key === 'e')) {
  48. event.preventDefault();
  49. }
  50. });
  51.  
  52. // 选中复制,自动跳转选中的url
  53. document.addEventListener('mouseup', () => {
  54. let selectedText = window.getSelection().toString();
  55. try {
  56. new URL(selectedText);
  57. document.getSelection().removeAllRanges();
  58. window.open(selectedText);
  59. } catch (err) {
  60. if (selectedText.length > 0) navigator.clipboard.writeText(selectedText)
  61. }
  62. });
  63. })();

QingJ © 2025

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