Greasy Fork

Greasy Fork is available in English.

luolcy & PikPak 自动跳转下载脚本(最新版)

自动点击 luolcy.com 与 PikPak 的下载按钮并在完成后关闭页面

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         luolcy & PikPak 自动跳转下载脚本(最新版)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  自动点击 luolcy.com 与 PikPak 的下载按钮并在完成后关闭页面
// @match        https://luolcy.com/11*
// @match        https://luolcy.com/download?post_id=*
// @match        https://mypikpak.com/s/*
// @grant        none
// ==/UserScript==

(function () {
    "use strict";

    // 工具:等待元素出现
    function waitForElement(selector, callback, interval = 400) {
        const timer = setInterval(() => {
            const el = document.querySelector(selector);
            if (el) {
                clearInterval(timer);
                callback(el);
            }
        }, interval);
    }

    // ==========================================
    // ① 页面:luolcy.com/11*
    // 点击:.download-button-box button
    // ==========================================
    if (location.href.includes("luolcy.com/11")) {
        waitForElement(".download-button-box button", (btn) => {
            console.log("自动点击:download-button-box 里的按钮");
            btn.click();
        });
    }

    // ==========================================
    // ② 页面:luolcy.com/download?post_id=*
    // 点击:a.empty.button
    // ==========================================
    if (location.href.includes("luolcy.com/download?post_id")) {
        waitForElement("a.empty.button", (a) => {
            console.log("自动点击:empty button");
            a.click();
        });
    }

    // ==========================================
    // ③ 页面:mypikpak.com/s/*
    // 点击:class="el-button el-button--primary pp-primary-button restore-btn"
    // 监听提示“已全部儲存到我的 PikPak”,出现后关闭窗口
    // ==========================================
    if (location.href.includes("mypikpak.com/s/")) {

        // 点击新版 restore 按钮
        waitForElement(".el-button.el-button--primary.pp-primary-button.restore-btn", (btn) => {
            console.log("自动点击:PikPak restore-btn 按钮");
            btn.click();
        });

        // 监听:成功提示出现后关闭页面
        const observer = new MutationObserver(() => {
            if (document.body.innerText.includes("已全部儲存到我的 PikPak")) {
                console.log("检测到已全部储存,准备关闭页面");
                observer.disconnect();
                setTimeout(() => window.close(), 1200);
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }
})();