// ==UserScript==
// @name Nachforderungen FMS 5 in Ad-Box
// @version 1.1.2
// @description Nachforderungen von Einsatzfahrzeuge in die Ad-Box spiegeln
// @author DrTraxx
// @match https://rettungssimulator.online/
// @match https://rettungssimulator.online/script/importantradiocalls/settings
// @icon https://www.google.com/s2/favicons?sz=64&domain=rettungssimulator.online
// @grant none
// ==/UserScript==
/* global $, socket, ControlCenter, systemMessage */
(function () {
const reportedMissions = {},
settings = localStorage.nfms5_settings ? JSON.parse(localStorage.nfms5_settings) : { color: "default", del_on_open: false },
path = window.location.pathname.replace(/\d+/g, "");
function insertMainPage() {
$("#ad > div")
.css({ "overflow": "auto", "max-height": "" })
.append(`
`);
$(document).on("DOMNodeInserted", "#radio-container-s5", e => {
const $target = $(e.target),
hasDelayClass = $target.hasClass("radio-message-delay"),
textContent = $target.text().trim();
if (hasDelayClass) {
const userMissionID = +$target.attr("usermissionid"),
isVehiclesNeeded = textContent.includes("benötigen zusätzlich:");
if (isVehiclesNeeded) {
const regex = /(?<=benötigen zusätzlich: )(?.+)\./g,
neededVehicles = regex.exec(textContent)?.groups?.vehicles,
mission = ControlCenter.missions?.[userMissionID],
missionName = mission?.missionName,
address = mission?.address;
if (!reportedMissions[userMissionID]) reportedMissions[userMissionID] = [];
if (!reportedMissions[userMissionID].includes(neededVehicles)) {
$("#fms_radio_reports")
.append(``);
reportedMissions[userMissionID].push(neededVehicles);
}
}
}
});
$(document).on("click", ".del_infofield", e => {
$(e.currentTarget).parent().remove();
});
$(document).on("click", ".nfms5_msg_txt", e => {
if (settings.del_on_open === false) {
return;
} else {
$(e.currentTarget).parent().remove();
}
});
socket.on("finishMission", userMissionID => {
if ($(`#vehicle_info_${ userMissionID }`).length > 0) {
$(`#vehicle_info_${ userMissionID }`).remove();
}
if (reportedMissions[userMissionID]) {
delete reportedMissions[userMissionID];
}
});
window.addEventListener("storage", e => {
if (e.key !== "nfms5_settings") return;
const { color, del_on_open } = JSON.parse(e.newValue);
settings.color = color;
settings.del_on_open = del_on_open;
$(`.nfms5_msg_txt >> span`).css("color", color);
});
}
function insertSettings() {
$("#scriptTitle").text("Einstellungen");
$("#scriptDescription")
.text("Ändere hier die Einstellungen zur Anzeige und zum Verhalten der Einsatznachforderungen")
.append(`
`);
$(".panel-body")
.append(``);
$(`#nfms5_color_${ settings.color }`).prop("checked", true);
$("#nfms5_del_on_open").prop("checked", settings.del_on_open);
$(document).on("click", "#nfms5_save", () => {
settings.del_on_open = $(`#nfms5_del_on_open`).is(":checked");
settings.color = $(`input[id^="nfms5_color_"]:checked`).val();
localStorage.nfms5_settings = JSON.stringify(settings);
parent.systemMessage({
"title": "Einsatznachforderungen",
"message": "Deine Einstellungen wurden erfolgreich gespeichert!",
"type": "success",
"timeout": 10000
});
});
}
if (path === "/") {
insertMainPage();
} else if (path === "/script/importantradiocalls/settings") {
insertSettings();
}
})();