You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用用户脚本禁用Squarespace网站占用的ESC快捷键

原代码失效的核心原因是仅完成了ESC按键识别,未阻止事件的默认行为与后续传播,且监听执行顺序晚于Squarespace自身绑定的回调,无法实现拦截。

解决代码

// 识别Squarespace站点
if (document.querySelector('meta[content*="Squarespace"]') || document.head.innerHTML.includes('squarespace')) {
  // 同时监听keydown、keyup事件,覆盖所有触发场景
  ['keydown', 'keyup'].forEach(eventType => {
    // 第三个参数设为true开启捕获模式,优先于网站自身的冒泡监听执行
    window.addEventListener(eventType, e => {
      if (e.key === 'Escape') {
        e.preventDefault();
        // 阻断所有后续同事件回调的执行
        e.stopImmediatePropagation();
        console.log('已拦截Squarespace ESC跳转逻辑');
      }
    }, true);
  });
}

使用说明

  • 若通过油猴(Tampermonkey)类脚本注入使用,可在脚本头部添加// @run-at document-start配置,保证监听逻辑早于网站自身代码加载,进一步提升拦截成功率。
  • 若仅临时使用,直接在浏览器控制台粘贴代码运行即可,页面刷新后配置会失效。

内容的提问来源于stack exchange,提问作者MagTun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 22:45:04