YouTube Hide UI on Arrow Keys, Show on Mouse Move

Ok tuşları UI'yi açmasın ama mouse hareketinde görünsün (tüm .ytp- elemanları otomatik algılanır)

目前为 2025-02-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Hide UI on Arrow Keys, Show on Mouse Move
  3. // @version 2.0
  4. // @namespace https://github.com/KaanAlper/youtube-ui-hide
  5. // @license GPL-3.0
  6. // @description Ok tuşları UI'yi açmasın ama mouse hareketinde görünsün (tüm .ytp- elemanları otomatik algılanır)
  7. // @author Kaan Alper Karaaslan
  8. // @match http://*.youtube.com/*
  9. // @match http://youtube.com/*
  10. // @match https://*.youtube.com/*
  11. // @match https://youtube.com/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. const elements = document.querySelectorAll(`
  18. .ytp-doubletap-tooltip, .ytp-chrome-bottom, .ytp-gradient-bottom,
  19. .ytp-title-text, .ytp-share-button, .ytp-right-controls,
  20. .ytp-watch-later-button, .ytp-doubletap-ui-legacy
  21. `);
  22.  
  23. let hideTimeout, cursorTimeout;
  24.  
  25. const toggleUI = (show) => {
  26. elements.forEach(el => Object.assign(el.style, {
  27. opacity: show ? '1' : '0',
  28. pointerEvents: show ? 'auto' : 'none'
  29. }));
  30. document.body.style.cursor = show ? 'auto' : 'none';
  31. };
  32.  
  33. const resetTimers = () => {
  34. clearTimeout(hideTimeout);
  35. clearTimeout(cursorTimeout);
  36. hideTimeout = setTimeout(() => toggleUI(false), 2000);
  37. cursorTimeout = setTimeout(() => document.body.style.cursor = 'none', 2000);
  38. };
  39.  
  40. document.addEventListener('keydown', (e) => {
  41. if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'F'].includes(e.key)) {
  42. clearTimeout(hideTimeout);
  43. clearTimeout(cursorTimeout);
  44. toggleUI(false);
  45. }
  46. });
  47.  
  48. document.addEventListener('mousemove', () => {
  49. toggleUI(true);
  50. resetTimers();
  51. });
  52.  
  53. })();