批量自动领取FF14女儿节偶像应援计划道具

批量自动领取FF14女儿节【偶像应援计划】道具

ของเมื่อวันที่ 05-06-2022 ดู เวอร์ชันล่าสุด

/* eslint-disable require-atomic-updates */
// ==UserScript==
// @name        批量自动领取FF14女儿节偶像应援计划道具
// @namespace   AnnAngela
// @match       https://actff1.web.sdo.com/20220420_DaughterDay/index.html
// @grant       unsafeWindow
// @version     1.0
// @author      AnnAngela
// @run-at      document-idle
// @description 批量自动领取FF14女儿节【偶像应援计划】道具
// ==/UserScript==
"use strict";
setInterval(() => {
    const anchor = document.querySelector("body > div.el-dialog__wrapper > .ff_passbox > div.el-dialog__body > div.ff_pass_cont > div > div.passbox > div.tc_mogu > div.voteList.wid");
    if (!anchor || document.getElementById("allInOne")) {
        return;
    }
    const button = document.createElement("div");
    button.id = "allInOne";
    button.innerText = "一键领取可直接领取奖励";
    anchor.after(button);
    button.setAttribute("style", "background: #8782ab; color: #fff; border-radius: .5rem; font-size: .13rem; height: .24rem; line-height: .24rem; text-align: center; cursor: pointer; margin-left: .3rem; width: 1.9rem; position: absolute; right: -3.45rem; bottom: auto; top: 1.44rem;");
    button.addEventListener("click", async () => {
        if (button.innerText !== "一键领取可直接领取奖励") {
            return;
        }
        if (!confirm("您确定要一键领取所有可以直接领取(即非任选)的奖励吗?")) {
            return;
        }
        button.style.cursor = "not-allowed";
        button.innerText = "领取中,请稍候……";
        const messages = [];
        const { vItemConfig } = await (await fetch("https://actff1.web.sdo.com/20220420_DaughterDay/Handler/Item/GetItemConfig.ashx", {
            referrer: "https://actff1.web.sdo.com/20220420_DaughterDay/index.html",
            referrerPolicy: "strict-origin-when-cross-origin",
            body: null,
            method: "POST",
            mode: "cors",
            credentials: "include",
        })).json();
        const availableItems = vItemConfig.filter(({ Status }) => Status === 0);
        const allInOneItems = availableItems.filter(({ ItemCode }) => !!ItemCode);
        messages.push(`共有 ${allInOneItems.length} 个奖励可以直接领取,有 ${availableItems.filter(({ ItemCode }) => !ItemCode).length} 个奖励需要手动选择。`);
        messages.push("-".repeat(37));
        let index = 0, successCount = 0, failedCount = 0;
        for (const { ItemCode, ItemName, ItemLevel, ItemType } of allInOneItems) {
            button.innerText = `领取中,请稍候(${index++}/${allInOneItems.length})……`;
            messages.push(`正在领取第 ${ItemLevel + 1}级${ItemType === 0 ? "免费" : "付费"}奖励:${ItemName}`);
            const data = new URLSearchParams({ ItemCode: ItemCode.replace(/^MOG-/, ""), ItemCount: 1, ItemLevel, ItemType });
            const response = await (await fetch("https://actff1.web.sdo.com/20220420_DaughterDay/Handler/Item/ItemExchange.ashx", {
                headers: {
                    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                },
                referrer: "https://actff1.web.sdo.com/20220420_DaughterDay/index.html",
                referrerPolicy: "strict-origin-when-cross-origin",
                body: `${data}`,
                method: "POST",
                mode: "cors",
                credentials: "include",
            })).json();
            if (response.result === "1") {
                messages.push("    结果:成功!");
                successCount++;
            } else {
                messages.push(`    结果:失败 - ${JSON.stringify(response)}`);
                failedCount++;
            }
        }
        document.querySelector("body > .el-dialog__wrapper > .ff_passbox > div.el-dialog__body > div.ff_pass_cont > div > div.passbox > div.tc_resh")?.click?.();
        messages.push("-".repeat(37));
        messages.push(`总数:${index},成功:${successCount},失败:${failedCount}`);
        alert(messages.join("\n"));
        button.innerText = "一键领取可直接领取奖励";
        button.style.cursor = "pointer";
    });
}, 100);