Greasy Fork is available in English.
原名GBF周回本胜利跳过。已重构。现支持1.关闭左侧边栏,2.攻击后刷新,3.胜利跳过,待追加:4.五神复活增益显示。
当前为
// ==UserScript==
// @name 榭洛科特的背包
// @version 1.3
// @author Alk
// @license GPL3.0
// @description 原名GBF周回本胜利跳过。已重构。现支持1.关闭左侧边栏,2.攻击后刷新,3.胜利跳过,待追加:4.五神复活增益显示。
// @match *.granbluefantasy.jp
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// @namespace http://greasyfork.icu/users/1455240
// @icon https://raw.githubusercontent.com/enorsona/thirdparty/refs/heads/master/sherurotes_carrybag.ico
// ==/UserScript==
// Settings
const checkEnabledAttackRefresh = () => {
return GM_getValue('AttackRefresh', true);
}
const switchEnabledAttackRefresh = () => {
GM_setValue('AttackRefresh', !ar_enabled);
reload();
}
// Functions Refresh Related
const tryParseJSON = (response) => {
let json;
try {
json = JSON.parse(response);
} catch (e) {
if (e instanceof SyntaxError) {
return response;
}
throw e;
}
return json;
};
const getURL = (base) => {
const url = new URL(base);
return {
pathname: url.pathname,
levels: url.pathname.split('/'),
url_type: url.pathname.split('/')[1],
action_type: url.pathname.split('/')[3],
}
}
const detectURL = (action_type) => {
if (action_type === 'normal_attack_result.json') {
return 'attack'
} else if (action_type === 'ability_result.json') {
return 'ability'
} else if (action_type === 'summon_result.json') {
return 'summon'
} else {
return 'other'
}
};
const reload = () => {
location.reload(true);
}
const goback = () => {
history.go(-1);
}
const checkWin = (scenario) => {
const win = scenario.find(s => s.cmd === "win");
if (win) {
write_log(win.is_last_raid);
if (win.is_last_raid === 1) {
return 1
} else {
return 2;
}
} else return 0;
}
const log_key = 'SierokarteLog';
const enable_write_log = false;
const write_log = (log) => {
if (!enable_write_log) return;
const raw_logs = localStorage.getItem(log_key);
const logs = raw_logs === null ? [] : JSON.parse(raw_logs);
logs.push({
'date_time': Date.now(),
'log': log
});
localStorage.setItem(log_key, JSON.stringify(logs));
}
const customLoad = (xhr, ...args) => {
const {
pathname,
levels,
url_type,
action_type,
} = getURL(xhr.responseURL);
if (url_type !== 'rest') return;
if (!action_type.includes('.json')) return;
if (action_type.includes('start.json')) return;
const response = tryParseJSON(xhr.response);
if (!response.scenario) return;
const is_attack = detectURL(action_type) === 'attack';
write_log(`当前操作为普通攻击:${is_attack}`);
const status = checkWin(response.scenario);
write_log(`当前状态为:${status}`);
if (ar_enabled && is_attack) {
if (status === 0) {
write_log('执行刷新当前页。');
reload();
} else if (status === 1) {
write_log('执行返回上一页。');
goback();
} else if (status === 2) {
write_log('执行刷新当前页。');
reload();
}
} else {
if (status === 1) {
write_log('执行返回上一页。');
goback();
} else if (status === 2) {
write_log('执行刷新当前页。');
reload();
}
}
};
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);
};
// Register Global Variables
let ar_enabled = checkEnabledAttackRefresh();
// Register Commands
(
GM_registerMenuCommand(
`攻击后自动刷新:${ar_enabled
? '已开启' : '已关闭'}`
, switchEnabledAttackRefresh)
)
// Functions Left Bar Related
window.onload = () => {
const target = document.body.firstElementChild;
target.removeChild(target.firstElementChild);
};