No Space Scroll

在页面加载初期即拦截全局的空格键(Space)和 Shift+Space 事件,仅在非输入框、非文本域及非可编辑区域触发时阻止默认的上下翻页行为,确保表单和富文本编辑区中的空格输入功能不受影响。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         No Space Scroll
// @name:zh-CN   禁用空格翻页
// @version      1.12
// @description  在页面加载初期即拦截全局的空格键(Space)和 Shift+Space 事件,仅在非输入框、非文本域及非可编辑区域触发时阻止默认的上下翻页行为,确保表单和富文本编辑区中的空格输入功能不受影响。
// @author       珞雪
// @match        *://*/*
// @match        *://*.bilibili.com/*
// @match        *://*.youtube.com
// @match        *://*.vimeo.com/*
// @match        *://*.iqiyi.com/*
// @match        *://*.youku.com/*
// @match        *://*.tudou.com/*
// @match        *://*.pptv.com/*
// @match        *://*.v.qq.com/*
// @match        *://*.mgtv.com/*
// @match        *://*.sohu.com/*
// @match        *://*.acfun.cn/*
// @match        *://*.netflix.com/*
// @match        *://*.primevideo.com/*
// @match        *://*.hulu.com/*
// @match        *://*.dailymotion.com/*
// @match        *://*.twitch.tv/*
// @exclude      *://*.bilibili.com/*/*
// @exclude      *://*.youtube.com/shorts/*
// @exclude      *://*.youtube.com/watch/*
// @exclude      *://*.vimeo.com/*/*
// @exclude      *://*.iqiyi.com/*/*
// @exclude      *://*.youku.com/*/*
// @exclude      *://*.tudou.com/*/*
// @exclude      *://*.pptv.com/*/*
// @exclude      *://*.v.qq.com/*/*
// @exclude      *://*.mgtv.com/*/*
// @exclude      *://*.sohu.com/*/*
// @exclude      *://*.acfun.cn/*/*
// @exclude      *://*.netflix.com/*/*
// @exclude      *://*.primevideo.com/*/*
// @exclude      *://*.hulu.com/*/*
// @exclude      *://*.dailymotion.com/*/*
// @exclude      *://*.twitch.tv/*/*
// @noframes
// @run-at       document-start
// @license      MIT
// @grant        none
// @namespace    https://github.com/luoxue3943/NoSpaceScroll
// ==/UserScript==

/*
声明:请您知晓本插件本是个人测试自用,本不完美也不保证可用性。
相关功能及代码均来自互联网及网友分享,我们仅做了相关功能的整合。
如无意中侵犯了哪个企业或个人等的知识产权,请联系我们将及时删除等相关处理
如果误杀请自行关闭被动去广告
*/

(function () {
  function isEditable(el) {
    return el.matches(
      'input, textarea, [contenteditable="true"], video, audio'
    );
  }

  function killSpace(e) {
    const active = document.activeElement;
    if (e.code === "Space" && !isEditable(active)) {
      e.preventDefault();
      e.stopImmediatePropagation();
    }
  }

  window.addEventListener("keydown", killSpace, { capture: true });
  window.addEventListener("keypress", killSpace, { capture: true });
})();