Greasy Fork

GBF周回本胜利跳过

修改自GBF Victory Skip https://greasyfork.org/zh-CN/scripts/35840-gbf-victory-skip

目前为 2025-04-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         GBF周回本胜利跳过
// @version      1.0
// @author       Alk
// @license GPL3.0
// @description  修改自GBF Victory Skip https://greasyfork.org/zh-CN/scripts/35840-gbf-victory-skip
// @match        *.granbluefantasy.jp/
// @grant        unsafeWindow
// @run-at       document-start
// @namespace https://greasyfork.org/users/1455240
// ==/UserScript==
const tryParseJSON = text => {
    let json;
    try {
        json = JSON.parse(text);
    } catch (e) {
        if (e instanceof SyntaxError) {
            return text;
        }
        throw e;
    }
    return json;
};
const customLoad = (xhr, ...args) => {
    // ex:
    // http://game.granbluefantasy.jp/rest/multiraid/ability_result.json
    const url = new URL(xhr.responseURL);
    const req = tryParseJSON(args[0]);
    const res = tryParseJSON(xhr.response);

    if (url.pathname.indexOf('.json') < 0) return;
    if (url.pathname.indexOf('/rest') < 0) return;

    if (!res.scenario) return;

    const win = res.scenario.find(s => s.cmd === "win");
    if (win) {
        history.go(-1);
    }
};

const origSend = unsafeWindow.XMLHttpRequest.prototype.send;
unsafeWindow.XMLHttpRequest.prototype.send = function (...args) {
    this.addEventListener('load', () => {
        if (this.status === 200) {
            customLoad(this, args);
        }
    });
    origSend.apply(this, args);
};