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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Hide UI on Arrow Keys, Show on Mouse Move
// @version      1.9
// @namespace    https://github.com/KaanAlper/youtube-ui-hide
// @license      GPL-3.0
// @description  Ok tuşları UI'yi açmasın ama mouse hareketinde görünsün (tüm .ytp- elemanları otomatik algılanır)
// @author       Kaan Alper Karaaslan
// @match        http://*.youtube.com/*
// @match        http://youtube.com/*
// @match        https://*.youtube.com/*
// @match        https://youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let elements = document.querySelectorAll(`
        .ytp-doubletap-tooltip,
        .ytp-chrome-bottom,
        .ytp-gradient-bottom,
        .ytp-title-text,
        .ytp-share-button,
        .ytp-right-controls,
        .ytp-watch-later-button,
        .ytp-doubletap-ui-legacy
    `);
    let hideTimeout;
    let cursorTimeout;

    let hideUI = () => {
        //document.querySelectorAll('[class^="ytp-"]').forEach(el => {
        elements.forEach(el => {
            el.style.opacity = '0';
            el.style.pointerEvents = 'none';
        });
    };
    let hideCursor = () => {
        document.body.style.cursor = 'none';
    };

    let showUI = () => {
        //document.querySelectorAll('[class^="ytp-"]').forEach(el =>
        elements.forEach(el => {
            el.style.opacity = '1';
            el.style.pointerEvents = 'auto';
        });
    };

    document.addEventListener('keydown', function(event) {
        if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'F'].includes(event.key)) {
            clearTimeout(hideTimeout);
            clearTimeout(cursorTimeout);
            hideUI(); // 100ms sonra UI tamamen gizle
            hideCursor();
        }
    });

    document.addEventListener('mousemove', function() {
        document.body.style.cursor = 'auto';
        clearTimeout(hideTimeout);
        clearTimeout(cursorTimeout);
        showUI();
        hideTimeout = setTimeout(hideUI, 2000); // 2 saniye sonra tekrar gizle
        cursorTimeout =setTimeout(hideCursor, 2000);
    });

})();