Anna's Archive Auto-Download (Pro Version)

Instantly finds and clicks the download button on Anna's Archive download pages using a smart observer.

当前为 2025-06-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Anna's Archive Auto-Download (Pro Version)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Instantly finds and clicks the download button on Anna's Archive download pages using a smart observer.
// @author       Your Best IT Guy Friend
// @match        *://annas-archive.org/slow_download/*
// @match        *://annas-archive.org/md5/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // --- Configuration ---
    // These are the "selectors" we'll use to find the button. They are like a precise address for an element on a webpage.
    // I've included several common ones for different download pages on the site.
    const DOWNLOAD_BUTTON_SELECTORS = [
        'a.btn.btn-primary.btn-lg', // The main "Download now" button
        'button[type="submit"]',    // A common fallback for form-based downloads
        'a[href*="/download/"]'     // A general selector for links containing "/download/"
    ];

    /**
     * Finds and clicks the first available download button from our list of selectors.
     * @returns {boolean} - True if a button was found and clicked, otherwise false.
     */
    const clickDownloadButton = () => {
        for (const selector of DOWNLOAD_BUTTON_SELECTORS) {
            const downloadBtn = document.querySelector(selector);
            if (downloadBtn) {
                console.log(`Found download button with selector: "${selector}". Clicking it now!`);
                downloadBtn.click();
                return true; // Found and clicked, our job is done.
            }
        }
        console.log('Waiting for a download button to appear...');
        return false; // No button found yet.
    };

    // --- The Magic: MutationObserver ---
    // This is our smart listener. It waits for changes in the webpage's HTML.
    const observer = new MutationObserver((mutationsList, obs) => {
        // We run our click function every time the page changes.
        if (clickDownloadButton()) {
            console.log('Success! Disconnecting the observer to save resources.');
            obs.disconnect(); // Stop watching once we've clicked the button.
        }
    });

    // --- Script Execution ---
    // Try to click the button immediately when the script runs.
    // This handles cases where the page loads fast and the button is already there.
    if (!clickDownloadButton()) {
        // If the button isn't there yet, we start our observer.
        // We tell it to watch the entire body of the page for new elements being added.
        console.log('Button not found immediately. Starting MutationObserver to wait for it.');
        observer.observe(document.body, {
            childList: true, // Watch for direct children being added or removed
            subtree: true    // Watch all descendants, not just direct children
        });
    }
})();