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-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Hide UI on Arrow Keys, Show on Mouse Move
  3. // @version 1.9
  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. let elements = document.querySelectorAll(`
  18. .ytp-doubletap-tooltip,
  19. .ytp-chrome-bottom,
  20. .ytp-gradient-bottom,
  21. .ytp-title-text,
  22. .ytp-share-button,
  23. .ytp-right-controls,
  24. .ytp-watch-later-button,
  25. .ytp-doubletap-ui-legacy
  26. `);
  27. let hideTimeout;
  28. let cursorTimeout;
  29.  
  30. let hideUI = () => {
  31. //document.querySelectorAll('[class^="ytp-"]').forEach(el => {
  32. elements.forEach(el => {
  33. el.style.opacity = '0';
  34. el.style.pointerEvents = 'none';
  35. });
  36. };
  37. let hideCursor = () => {
  38. document.body.style.cursor = 'none';
  39. };
  40.  
  41. let showUI = () => {
  42. //document.querySelectorAll('[class^="ytp-"]').forEach(el =>
  43. elements.forEach(el => {
  44. el.style.opacity = '1';
  45. el.style.pointerEvents = 'auto';
  46. });
  47. };
  48.  
  49. document.addEventListener('keydown', function(event) {
  50. if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'F'].includes(event.key)) {
  51. clearTimeout(hideTimeout);
  52. clearTimeout(cursorTimeout);
  53. hideUI(); // 100ms sonra UI tamamen gizle
  54. hideCursor();
  55. }
  56. });
  57.  
  58. document.addEventListener('mousemove', function() {
  59. document.body.style.cursor = 'auto';
  60. clearTimeout(hideTimeout);
  61. clearTimeout(cursorTimeout);
  62. showUI();
  63. hideTimeout = setTimeout(hideUI, 2000); // 2 saniye sonra tekrar gizle
  64. cursorTimeout =setTimeout(hideCursor, 2000);
  65. });
  66.  
  67. })();