script-ShowVPR

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

  1. // ==UserScript==
  2. // @name script-ShowVPR
  3. // @namespace https://github.com/Poul0s/script-showvpr
  4. // @version 2025-03-01.01
  5. // @description Show vehicle and personnel requirements in the mission page of operateur112.fr without clicking mission help button
  6. // @author Thunlos
  7. // @match https://www.operateur112.fr/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=operateur112.fr
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15. async function loadMissionPageInjection(iframeNode, iframeContentWindow) {
  16. let lightbox = document.getElementById("lightbox_box");
  17. let lightboxOldStyle = lightbox.style.cssText;
  18. let lightboxCloseButton = document.getElementById("lightbox_close");
  19. let lightboxCloseButtonOldStyle = lightboxCloseButton.style.cssText;
  20. let iframeOldStyle = iframeNode.style.cssText;
  21. function restoreStyle() {
  22. lightbox.style.cssText = lightboxOldStyle;
  23. lightboxCloseButton.style.cssText = lightboxCloseButtonOldStyle;
  24. iframeNode.style.cssText = iframeOldStyle;
  25. }
  26.  
  27. let helpButton = iframeContentWindow.document.getElementById("mission_help");
  28.  
  29. /** @type {HTMLIFrameElement} */
  30. let missionHelpIframe = document.createElement('iframe');
  31. missionHelpIframe.style.visibility = "hidden";
  32. missionHelpIframe.style.width = "1px";
  33. missionHelpIframe.style.height = "1px";
  34. missionHelpIframe.style.position = "absolute";
  35. document.body.appendChild(missionHelpIframe);
  36.  
  37. missionHelpIframe.onerror = () => {
  38. missionHelpIframe.remove();
  39. restoreStyle();
  40. }
  41.  
  42. missionHelpIframe.onload = () => {
  43. let missionHelpWindow = missionHelpIframe.contentWindow;
  44. let missionHelpDocument = missionHelpWindow.document;
  45. let requirements = missionHelpDocument.querySelector(".row .col-md-4:nth-child(2)");
  46.  
  47. let targetRow = iframeContentWindow.document.querySelector(".row .col-lg-6#col_left");
  48. let nextElem = iframeContentWindow.document.getElementById("mission-aao-group");
  49. let requirementsClone = requirements.cloneNode(true);
  50. targetRow.insertBefore(requirementsClone, nextElem);
  51. missionHelpIframe.remove();
  52. restoreStyle();
  53. }
  54.  
  55. missionHelpIframe.src = helpButton.href;
  56. }
  57.  
  58.  
  59. let popupPage = document.getElementById("lightbox_box");
  60. const callback = (mutationList, observer) => {
  61. for (const mutation of mutationList) {
  62. if (mutation.type === "childList") {
  63. for (let node of mutation.addedNodes) {
  64. if (node.classList.contains("lightbox_iframe")) {
  65. node.addEventListener("load", () => {
  66. if (node.src.startsWith(window.location.origin + "/missions/"))
  67. loadMissionPageInjection(node, node.contentWindow);
  68. })
  69. }
  70. }
  71. }
  72. }
  73. };
  74.  
  75. const observer = new MutationObserver(callback)
  76. observer.observe(popupPage, { attributes: false, childList: true, subtree: false });
  77. })();