// ==UserScript== // @name 碧蓝幻想救援人数筛选 // @namespace https://github.com/Less01 // @version 0.0.1 // @description 筛除人数过多和血量过少的房间,使其变为透明 // @author Less01 // @match *://game.granbluefantasy.jp/ // @match *://gbf.game.mbga.jp/* // @icon https://pjsekai.sega.jp/assets/images/favicon.ico // @run-at document-end // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 设定部分 let opacity = GM_getValue('gbf_assist_opacity', 0.25); let playerCount = GM_getValue('gbf_assist_playerCount', 5); let enemyHp = GM_getValue('gbf_assist_enemyHp', 50); // console.log(`Alpha: ${opacity}, 最大人数: ${playerCount}, 最低血量: ${enemyHp}`); // 油猴按钮,修改在刷新后生效 // 可以设定的人数限制为1~9,血量限制为0~90 GM_registerMenuCommand('显示设定并开启', () => { opacity = 0.25; GM_setValue('gbf_assist_opacity', opacity); alert(`Alpha: ${opacity}, 最大人数: ${playerCount}, 最低血量: ${enemyHp}`); }); GM_registerMenuCommand('关闭', () => { opacity = 1.0; GM_setValue('gbf_assist_opacity', opacity); }); GM_registerMenuCommand('降低最大人数1', () => { if (playerCount > 1) GM_setValue('gbf_assist_playerCount', --playerCount); }); GM_registerMenuCommand('提高最大人数1', () => { if (playerCount < 9) GM_setValue('gbf_assist_playerCount', ++playerCount); }); GM_registerMenuCommand('降低最低血量10', () => { if (enemyHp > 0) GM_setValue('gbf_assist_enemyHp', enemyHp -= 10); }); GM_registerMenuCommand('提高最低血量10', () => { if (enemyHp < 90) GM_setValue('gbf_assist_enemyHp', enemyHp += 10); }); // 监听页面内容变化,当救援列表改变时修改透明度 const targetNode = document.querySelector("#wrapper>.contents"); const config = { childList: true, subtree: true }; const observer = new MutationObserver( (mutationsList) => { for (let mutation of mutationsList) { // 改为mutation.target.id == "prt-search-list"可以只在救援检索启用 if (mutation.target.className == "prt-raid-list") { let raid_list = mutation.target.querySelectorAll(".btn-multi-raid"); // console.log(`raid list length: ${raid_list.length}\n`); for (let raid of raid_list) { let count = raid.querySelector(".prt-flees-in").innerText.replace(/\/\d+/, ""); let hp = raid.querySelector(".prt-raid-gauge-inner").getAttribute("style").slice(7, -2); // console.log(`count: ${count}, hp: ${hp}\n`); if (count >= playerCount || hp <= enemyHp) { raid.style.opacity = opacity; } } } } } ); // 打开网页时、游戏内跳转时启用 function run() { if (/^#quest\/assist(\/multi\/\d+|\/event)?$/.test(location.hash)) { observer.observe(targetNode, config); // console.log("observe\n"); } else { observer.disconnect(); // console.log("disconnect\n"); } } run(); window.addEventListener('hashchange', run); })();