YouTube - Hover + Q = Add to Queue

Hover → Q → instantly add to queue (works even when video preview is playing)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube - Hover + Q = Add to Queue
// @namespace    http://tampermonkey.net/
// @version      6.5
// @description  Hover → Q → instantly add to queue (works even when video preview is playing)
// @author       Grok × me
// @match        https://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    let hovered = null;
    let isProcessing = false;

    // HOVER DETECTION – tahan preview video
    document.addEventListener('mouseover', e => {
        let target = e.target;

        if (target.id === 'movie_player' || target.closest('#movie_player, #ytd-player, .html5-video-container')) {
            const thumbnail = target.closest('ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer, ytd-compact-video-renderer, ytd-playlist-video-renderer, ytd-reel-item-renderer')
                           || document.elementFromPoint(e.clientX, e.clientY)?.closest('ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer, ytd-compact-video-renderer, ytd-playlist-video-renderer, ytd-reel-item-renderer');
            if (thumbnail) hovered = thumbnail;
            return;
        }

        const normal = target.closest('ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer, ytd-compact-video-renderer, ytd-playlist-video-renderer, ytd-reel-item-renderer');
        if (normal) hovered = normal;
    }, true);

    // ENGLISH TOAST ONLY
    const toast = (msg, ok = true) => {
        const old = document.getElementById('grokq');
        if (old) old.remove();
        const el = document.createElement('div');
        el.id = 'grokq';
        el.textContent = msg;
        el.style.cssText = `position:fixed;bottom:28px;left:28px;padding:9px 20px;border-radius:50px;background:${ok?'#00d26a':'#ff3b30'};color:#fff;font:700 13px 'Roboto';z-index:999999;box-shadow:0 6px 20px rgba(0,0,0,0.4);pointer-events:none;opacity:0;transform:translateY(10px);transition:all .3s ease;`;
        document.body.appendChild(el);
        requestAnimationFrame(() => { el.style.opacity = '1'; el.style.transform = 'translateY(0)'; });
        setTimeout(() => { el.style.opacity = '0'; el.style.transform = 'translateY(10px)'; }, 1200);
        setTimeout(() => el.remove(), 1600);
    };

    // MAIN LOGIC (tidak diubah sama sekali)
    document.addEventListener('keydown', e => {
        if (e.key.toLowerCase() !== 'q' || e.ctrlKey || e.altKey || e.metaKey || isProcessing) return;
        if (['INPUT','TEXTAREA'].includes(document.activeElement.tagName) || document.activeElement.isContentEditable) return;

        e.preventDefault();
        e.stopImmediatePropagation();

        if (!hovered) return toast('Hover a video first', false);

        isProcessing = true;

        const menuBtn = hovered.querySelector('button.yt-spec-button-shape-next--icon-button, button[aria-label*="aksi"], button[aria-label*="action"], button-view-model button');
        if (!menuBtn) { isProcessing = false; return toast('Menu button not found', false); }

        menuBtn.click();

        let attempts = 0;
        const turbo = setInterval(() => {
            attempts++;
            const item = Array.from(document.querySelectorAll('yt-list-item-view-model, ytd-menu-service-item-renderer'))
                .find(el => el.offsetParent && /antrean|queue|play next/i.test(el.textContent));

            if (item) {
                item.click();
                clearInterval(turbo);
                toast('Added to queue');
                setTimeout(() => document.body.click(), 50);
                setTimeout(() => isProcessing = false, 150);
            } else if (attempts > 40) {
                clearInterval(turbo);
                document.body.click();
                toast('Timeout', false);
                isProcessing = false;
            }
        }, 10);
    }, true);

    console.log('%cYouTube Hover + Q → GOD MODE v6.1 (English Toast) ACTIVE!','color:#00ffff;font-size:18px;font-weight:900;');
})();