script-raifinder

Find more revelent AOO for the current mission in the mission page of operateur112.fr

目前為 2025-02-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         script-raifinder
// @namespace    https://github.com/Poul0s/script-raifinder
// @version      2025-02-23.02
// @description  Find more revelent AOO for the current mission in the mission page of operateur112.fr
// @author       Thunlos
// @match        https://www.operateur112.fr/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=operateur112.fr
// @grant        none
// ==/UserScript==


(function() {
	'use strict';
	
	const mostRevelentStyles = {
		fontSize: "1.2em",
		color: "red"
	}



	async function loadMissionPageInjection(iframeNode, iframeContentWindow) {

		let missionInfo = iframeContentWindow.document.getElementById("mission_general_info");
		let RAIContainer = iframeContentWindow.document.getElementById("mission-aao-group");
		if (!RAIContainer || !missionInfo)
			return;
		let missionName = missionInfo.dataset.missionTitle.toUpperCase()
		let RAIs = RAIContainer.querySelectorAll("a span");
		let mostRevelent = null;
		for (let RAISpan of RAIs) {
			let RAIName = RAISpan.innerText;
			let RAINameUpper = RAIName.toUpperCase();
			let foundCharIdx = [];

			let i = 0;
			for (let j in missionName) {
				let current_i = i;
				while (current_i < RAINameUpper.length && RAINameUpper[current_i] != missionName[j]) {
					current_i++;
				}
				if (current_i !== RAINameUpper.length) {
					i = current_i + 1;
					foundCharIdx.push(current_i);
				}
			}
			if (foundCharIdx.length === 0)
				continue;
			let relevency = foundCharIdx.length / RAINameUpper.length;
			if (relevency > 0 && (!mostRevelent || mostRevelent.relevency < relevency)) {
				mostRevelent = { DOMElement: RAISpan, RAIName: RAIName, relevency: relevency };
			}

			let newRAIName = "";
			let bolding = false;
			i = 0;
			let j = 0;
			while (i < RAIName.length) {
				if (j < foundCharIdx.length && foundCharIdx[j] == i) {
					if (!bolding) {
						bolding = true;
						newRAIName += "<b>";
					}
					j++;
				} else {
					if (bolding) {
						bolding = false;
						newRAIName += "</b>";
					}
				}
				newRAIName += RAIName[i];
				i++;
			}
			if (bolding)
				newRAIName += "</b>";
			RAISpan.innerHTML = newRAIName;
		}

		if (mostRevelent) {
			if (mostRevelentStyles) {
				for (let style in mostRevelentStyles) {
					mostRevelent.DOMElement.style[style] = mostRevelentStyles[style];
				}
			}

			let panel = mostRevelent.DOMElement.closest("[role=tabpanel]");
			if (panel.id && panel.id.startsWith("aao_category_")) {
				let panelBtn = RAIContainer.querySelector("#aao-tabs li a[href='#" + panel.id + "']");
				if (panelBtn) {
					panelBtn.click();
				}
			}
		}

	}


	let popupPage = document.getElementById("lightbox_box");
	const callback = (mutationList, observer) => {
		for (const mutation of mutationList) {
			if (mutation.type === "childList") {
				for (let node of mutation.addedNodes) {
					if (node.classList.contains("lightbox_iframe")) {
						node.onload = () => {
							if (node.src.startsWith(window.location.origin + "/missions/"))
								loadMissionPageInjection(node, node.contentWindow);
						}
					}
				}
			}
		}
	};

	const observer = new MutationObserver(callback)
	observer.observe(popupPage, { attributes: false, childList: true, subtree: false });
})();