// ==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 // @downloadURL none // ==/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); };