Google Drive Auto Download Countdown

Countdown + auto-click for Google Drive, cancels on user manual click

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Google Drive Auto Download Countdown
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Countdown + auto-click for Google Drive, cancels on user manual click
// @author       MoodyMonkey
// @match        *://drive.usercontent.google.com/download?id=*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function startCountdown() {
        const downloadButton = document.getElementById('uc-download-link');
        if (!downloadButton) {
            console.log('Waiting for download button... 🕛');
            setTimeout(startCountdown, 500);
            return;
        }

        const countdownText = document.createElement('div');
        countdownText.style.marginBottom = '10px';
        countdownText.style.fontSize = '16px';
        countdownText.style.fontWeight = 'bold';
        countdownText.style.color = '#d9534f';

        downloadButton.parentNode.insertBefore(countdownText, downloadButton);

        let count = 5;
        let timer = null;
        let manuallyClicked = false;

        countdownText.textContent = `Download will start automatically in ${count}...`;

        function updateCountdown() {
            if (manuallyClicked) {
                console.log('Countdown canceled due to manual click.');
                clearInterval(timer);
                countdownText.textContent = 'Download started manually.';
                return;
            }

            count--;
            if (count >= 0) {
                countdownText.textContent = `Download will start automatically in ${count}...`;
            }
            if (count === 0) {
                clearInterval(timer);
                console.log('Countdown reached zero. Triggering download!');
                if (!manuallyClicked) {
                    downloadButton.click();
                }
            }
        }

        timer = setInterval(updateCountdown, 1000);

        //  Listen for mousedown (fires BEFORE click+submit)
        downloadButton.addEventListener('mousedown', () => {
            manuallyClicked = true;
            console.log('Manual mousedown detected! Countdown canceled immediately');
            clearInterval(timer);
            countdownText.textContent = 'Download started manually.';
        }, { once: true }); // Fires only once
    }

    startCountdown();
})();