script-ShowVPR

Show vehicle and personnel requirements in the mission page of operateur112.fr without clicking mission help button

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         script-ShowVPR
// @namespace    https://github.com/Poul0s/script-showvpr
// @version      2025-03-01.01
// @description  Show vehicle and personnel requirements in the mission page of operateur112.fr without clicking mission help button
// @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';
	
	async function loadMissionPageInjection(iframeNode, iframeContentWindow) {
		let lightbox = document.getElementById("lightbox_box");
		let lightboxOldStyle = lightbox.style.cssText;
		let lightboxCloseButton = document.getElementById("lightbox_close");
		let lightboxCloseButtonOldStyle = lightboxCloseButton.style.cssText;
		let iframeOldStyle = iframeNode.style.cssText;
		function restoreStyle() {
			lightbox.style.cssText = lightboxOldStyle;
			lightboxCloseButton.style.cssText = lightboxCloseButtonOldStyle;
			iframeNode.style.cssText = iframeOldStyle;
		}

		let helpButton = iframeContentWindow.document.getElementById("mission_help");

		/** @type {HTMLIFrameElement} */
		let missionHelpIframe = document.createElement('iframe');
		missionHelpIframe.style.visibility = "hidden";
		missionHelpIframe.style.width = "1px";
		missionHelpIframe.style.height = "1px";
		missionHelpIframe.style.position = "absolute";
		document.body.appendChild(missionHelpIframe);

		missionHelpIframe.onerror = () => {
			missionHelpIframe.remove();
			restoreStyle();
		}

		missionHelpIframe.onload = () => {
			let missionHelpWindow = missionHelpIframe.contentWindow;
			let missionHelpDocument = missionHelpWindow.document;
			let requirements = missionHelpDocument.querySelector(".row .col-md-4:nth-child(2)");

			let targetRow = iframeContentWindow.document.querySelector(".row .col-lg-6#col_left");
			let nextElem = iframeContentWindow.document.getElementById("mission-aao-group");
			let requirementsClone = requirements.cloneNode(true);
			targetRow.insertBefore(requirementsClone, nextElem);
			missionHelpIframe.remove();
			restoreStyle();
		}

		missionHelpIframe.src = helpButton.href;
	}


	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.addEventListener("load", () => {
							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 });
})();