Scrollbar Hider

Hides scrollbars globally but keeps scrolling functionality

当前为 2024-09-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scrollbar Hider
  3. // @description Hides scrollbars globally but keeps scrolling functionality
  4. // @author SSL-ACTX
  5. // @version 1.0.0
  6. // @license MIT
  7. // @grant sr_IRS
  8. // @run-at document-start
  9. // @match *://*/*
  10. // @namespace https://greasyfork.org/users/1365732
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // CSS rules to hide scrollbars but retain scrolling functionality :)
  17. const scrollbarHiderCSS = `
  18. /* Remove WebKit-based browsers' scrollbars */
  19. *::-webkit-scrollbar {
  20. width: 0;
  21. height: 0;
  22. }
  23.  
  24. /* Hide scrollbars in Firefox, IE, and Edge; just making sure lol. */
  25. * {
  26. scrollbar-width: none;
  27. -ms-overflow-style: none;
  28. }
  29.  
  30. /* Ensure html and body can still scroll vertically */
  31. html, body {
  32. overflow-y: auto;
  33. overflow-x: hidden;
  34. }
  35. `;
  36.  
  37. /**
  38. * Injects the provided CSS into the document.
  39. */
  40. const injectCSS = (cssRules) => {
  41. const styleElement = document.createElement('style');
  42. styleElement.type = 'text/css';
  43. styleElement.textContent = cssRules;
  44. document.head.appendChild(styleElement);
  45. };
  46.  
  47. /**
  48. * Applies the CSS for hiding scrollbars either using sr_IRS or by injecting it manually. >_<
  49. */
  50. const applyScrollbarHider = () => {
  51. if (typeof sr_IRS === 'function') {
  52. sr_IRS(scrollbarHiderCSS);
  53. } else {
  54. injectCSS(scrollbarHiderCSS);
  55. }
  56. };
  57.  
  58. applyScrollbarHider();
  59. })();