Anime player hide

Toggle video control bar visibility on number 1 key press

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Anime player hide
// @namespace    dphdm
// @version      1.0.3
// @description  Toggle video control bar visibility on number 1 key press
// @author       dphdmn
// @match        https://jut.su/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jut.su
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let isHidden = false;

    // Function to toggle control bar visibility
    const toggleControlBar = () => {
        const controlBar = document.querySelector('.vjs-control-bar');
        if (controlBar) {
            controlBar.style.setProperty('transition', 'visibility 0.1s, opacity 0.1s', 'important');
            controlBar.style.opacity = isHidden ? '0' : '1';
            controlBar.style.visibility = isHidden ? 'hidden' : 'visible';
        }
    };

    // Function to wait for an element to be present in the DOM
    const waitForElement = (selector, callback, timeout = 10000, interval = 100) => {
        const startTime = Date.now();
        const checkInterval = setInterval(() => {
            const element = document.querySelector(selector);
            if (element) {
                clearInterval(checkInterval);
                callback(element);
            } else if (Date.now() - startTime >= timeout) {
                clearInterval(checkInterval);
                console.log(`Element "${selector}" not found after ${timeout}ms`);
            }
        }, interval);
    };

    // Wait for the control bar element to load
    waitForElement('.vjs-control-bar', () => {
        // Add number 1 key event listener
        document.addEventListener('keydown', (event) => {
            if (event.code === 'Digit1') {
                event.preventDefault();
                isHidden = !isHidden;
                toggleControlBar();
            }
        });
    });
})();