YouTube shorts: Disable scrolling

Disables all the possible ways you can scroll down youtube shorts

当前为 2024-12-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube shorts: Disable scrolling
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Disables all the possible ways you can scroll down youtube shorts
  6. // @icon https://github.com/kuronekozero/youtube-shorts-disable-scrolling/blob/main/logo.webp
  7. // @author Timothy (kuronek0zero)
  8. // @namespace https://github.com/kuronekozero/youtube-shorts-disable-scrolling
  9. // @match https://www.youtube.com/shorts/*
  10. // @grant GM_addStyle
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to block events
  18. const blockEvent = (e) => {
  19. e.preventDefault();
  20. e.stopImmediatePropagation();
  21. return false;
  22. };
  23.  
  24. // Function to remove navigation buttons
  25. const removeNavButtons = () => {
  26. const navButtons = document.querySelectorAll(
  27. '#navigation-button-up, #navigation-button-down'
  28. );
  29. navButtons.forEach((btn) => {
  30. btn.remove();
  31. console.log("Removed:", btn.id);
  32. });
  33. };
  34.  
  35. // Disable all scrolling methods
  36. const disableScrolling = () => {
  37. // Disable mouse wheel
  38. document.addEventListener('wheel', blockEvent, { passive: false, capture: true });
  39.  
  40. // Disable touch scrolling
  41. document.addEventListener('touchmove', blockEvent, { passive: false, capture: true });
  42.  
  43. // Disable key scrolling
  44. document.addEventListener('keydown', (e) => {
  45. const keysToBlock = [
  46. 'ArrowUp', 'ArrowDown',
  47. 'ArrowLeft', 'ArrowRight',
  48. 'Space', 'PageUp', 'PageDown',
  49. 'Home', 'End', 'Tab'
  50. ];
  51. if (keysToBlock.includes(e.code)) {
  52. blockEvent(e);
  53. }
  54. }, { passive: false, capture: true });
  55.  
  56. // Disable window scrolling
  57. window.addEventListener('scroll', () => {
  58. window.scrollTo(0, 0);
  59. });
  60.  
  61. // Disable scrollbar visibility
  62. document.documentElement.style.overflow = 'hidden';
  63. document.body.style.overflow = 'hidden';
  64.  
  65. console.log("YouTube Shorts Scroll Blocker Activated!");
  66. };
  67.  
  68. // Reapply scroll lock and remove navigation buttons when DOM changes
  69. const observer = new MutationObserver(() => {
  70. disableScrolling();
  71. removeNavButtons();
  72. });
  73. observer.observe(document, { childList: true, subtree: true });
  74.  
  75. // Apply on load
  76. disableScrolling();
  77. removeNavButtons();
  78. })();