//=require ../node_modules/dexie/dist/dexie.js class AutomaticDispose { // Variablen get ADisSettings() { return { url: "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/", branch: "master", all_missions: /***ADis_AllMissions***/ 0, name: this.name } } constructor() { this.ADis_MyHead = document.getElementsByTagName('head')[0]; this.ADis_MyBody = document.getElementsByTagName('body')[0]; // - // - Sprechwunsch Variablen // - this.Jails = []; this.JailRegEx = /\(Freie Zellen\:\s+(\d)\,\s+Entfernung\:\s+(\d+\,\d+)\s+km(?:\,\s+Abgabe an Besitzer\:\s+(\d+)%)?\)/g; this.Hospitals = []; this.RescueVehicleFrameWatchDog = null; this.PoliceVehicleFrameWatchDog = null; let that = this; this.ADisDB = new Dexie('LSS_AutomaticDispo'); this.ADisDB.version(1).stores({ /** * AvailabelMissions * - missionID * - type * - name * - jsondata */ ADisAvailabelMissions: "++missionID,type,name", /** * Sprechwunsch * - vehicleID * - done */ ADisSprechwunsch: "++vehicleID,done", /** * Sprechwunsch Police * - missionID * - done */ ADisSprechwunschPolice: "++missionID,last_check,next_check,done", /** * Krankentransport * - missionID * - done */ ADisKrankentransport: "++missionID,last_check,next_check,done", /** * Settings * - id * - name * - done */ ADisSettings: "&name,value", /** * MissionsOwn * MissionsVerband * MissionsVerbandEvent * - missionID * - type * - name * - available * - done * - street * - village * - last_check * - next_check */ ADisMissionsOwn: "++missionID,type,name,last_check,next_check,available,done", ADisMissionsVerband: "++missionID,type,name,last_check,next_check,available,done", ADisMissionsVerbandEvent: "++missionID,type,name,last_check,next_check,available,done", }); this.ADisDB.on("populate", function () { ADisDB.ADisSettings.add({ name: "Krankentransport-Automatic", value: 'true' }); ADisDB.ADisSettings.add({ name: "Sprechwunsch-Automatic", value: 'true' }); ADisDB.ADisSettings.add({ name: "MissionsOwn-Automatic", value: 'true' }); ADisDB.ADisSettings.add({ name: "Alliance-Automatic", value: 'false' }); ADisDB.ADisSettings.add({ name: "AllianceEvent-Automatic", value: 'false' }); }); this.ADisDB.open().catch(function (err) { console.error(err.stack || err); }); this.ADisDB.on("ready", () => { if (window.location.pathname === "/" || window.location.pathname === "/#") { that.IndexPage() setInterval(that.CollectRescueSprechwuensche, 2500); setInterval(that.OpenNextRescueSprechwunsch, 2500); that.CollectRescueSprechwuensche(); setInterval(that.CollectPoliceSprechwuensche, 2500); setInterval(that.OpenNextPoliceSprechwunsch, 2500); that.CollectPoliceSprechwuensche(); } //=require ../script/mission.js //=require ../script/sprechwunsch.js }); console.log('nonstatic', this.ADisSettings) } get Settings() { console.log('static', this.ADisSettings); console.log('static WindowName', this); return this.ADisSettings; } includesString(string1, string2) { return string1.toLowerCase().includes(string2.toLowerCase()); } get ADSettings() { return (async () => { var res = {}; await this.ADisDB.ADisSettings.each((setting) => { res[setting.name] = setting.value; }); return res; })() } get WindowName() { return window.name } // - // - Sprechwunsch Queue // - RemovePoliceSprechwunschFromQueue(WunschID) { return this.ADisDB.ADisSprechwunschPolice.where({ missionID: WunschID }).delete(); } RemoveRescueSprechwunschFromQueue(WunschID) { return this.ADisDB.ADisSprechwunsch.where({ vehicleID: WunschID }).delete(); } // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // - // - Assign & Unassign Missions to Dispatchers // - // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- CollectRescueSprechwuensche() { let that = this; new Promise(async function (resolve, reject) { await that.ADisDB.ADisSprechwunsch.where({ done: 'false' }).each((myWunsch) => { console.log('that.CollectRescueSprechwuensche: remove', myWunsch); if ($("#vehicle_list_" + myWunsch.vehicleID).find(".building_list_fms").text() != "5") { return that.RemoveRescueSprechwunschFromQueue(myWunsch.vehicleID); } }) return resolve(); }).then(() => { $("#building_list").find(".building_list_vehicle_element").each(function () { var VehicleStatus = $(this).find(".building_list_fms").text(); var VehicleType = Number(parseInt($(this).find("a").attr("vehicle_type_id"))); var VehicleID = $(this).attr("vehicle_id"); if (VehicleStatus == "5" && [32, 52].indexOf(VehicleType) === -1) { that.AddRescueSprechwunschToQueue(VehicleID); } }); }); } OpenNextRescueSprechwunsch() { let that = this; this.ADSettings().then((setting) => { if (setting['Sprechwunsch-Automatic'] == 'true') { return that.ADisDB.ADisSprechwunsch.where({ done: 'false' }).limit(1) } }).then((Wunsch) => { if (Wunsch !== undefined) { Wunsch.each((myWunsch) => { let VehicleID = myWunsch.vehicleID; that.UpdateRescueSprechwunschToDone(VehicleID).then(() => { if ($("#adis-sprechwunsch-rescue-frame").attr("vehicle_id") == "empty") { $("#adis-sprechwunsch-rescue-frame").attr("src", "https://www.leitstellenspiel.de/vehicles/" + VehicleID); $("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", VehicleID); that.RescueVehicleFrameWatchDog = setTimeout(async function () { that.RemoveRescueSprechwunschFromQueue(VehicleID).then((deleteCount) => { $("#adis-sprechwunsch-rescue-frame").attr("src", ""); $("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", "empty"); }); }, 1500); } }); }); } }); } AddRescueSprechwunschToQueue(WunschID) { return this.ADisDB.ADisSprechwunsch.put({ vehicleID: WunschID, done: 'false' }).catch((err) => {}) } UpdateRescueSprechwunschToDone(WunschID) { return this.ADisDB.ADisSprechwunsch.put({ vehicleID: WunschID, done: 'true' }).catch((err) => {}) } // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // - // - Assign & Unassign Missions to Dispatchers // - // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- CollectPoliceSprechwuensche() { let that = this; new Promise(async function (resolve, reject) { await that.ADisDB.ADisSprechwunschPolice.where({ done: 'false' }).each((myWunsch) => { if (!$("#mission_" + myWunsch.missionID).text().match(/Gefangene sollen abtransportiert werden/g)) { $("#mission_" + myWunsch.missionID).remove(); return that.RemovePoliceSprechwunschFromQueue(myWunsch.missionID); } }) return resolve(); }).then(() => { var MOIODOS = $('div#mission_list div.missionSideBarEntry:visible'); return MOIODOS.each(function (index) { if ($(this).text().match(/Gefangene sollen abtransportiert werden/g)) { var MissionID = $(this).attr("mission_id"); that.AddPoliceSprechwunschToQueue(MissionID); } }); }).then(() => { $("#building_list").find(".building_list_vehicle_element").each(function () { var VehicleStatus = $(this).find(".building_list_fms").text(); var VehicleType = Number(parseInt($(this).find("a").attr("vehicle_type_id"))); var VehicleID = $(this).attr("vehicle_id"); if (VehicleStatus == "5" && [32, 52].indexOf(VehicleType) !== -1) { var map2 = $('#radio_messages_important > li.radio_message_vehicle_' + VehicleID + ' a:contains("Zum Einsatz")'); if (map2.length > 0) { var _meap = String(map2.attr('href')); var MissionID = _meap.substr(_meap.lastIndexOf("/") + 1); if (MissionID) { that.AddPoliceSprechwunschToQueue(MissionID); } } } }); }); } OpenNextPoliceSprechwunsch() { let that = this; this.ADSettings().then((setting) => { if (setting['Sprechwunsch-Automatic'] == 'true') { return that.ADisDB.ADisSprechwunschPolice.where({ done: 'false' }).limit(1) } }).then((Wunsch) => { if (Wunsch !== undefined) { Wunsch.each((myWunsch) => { let MissionID = myWunsch.missionID; that.UpdatePoliceSprechwunschToDone(MissionID).then(() => { if ($("#adis-sprechwunsch-police-frame").attr("mission_id") == "empty") { $("#adis-sprechwunsch-police-frame").attr("src", "https://www.leitstellenspiel.de/missions/" + MissionID); $("#adis-sprechwunsch-police-frame").attr("mission_id", MissionID); that.PoliceVehicleFrameWatchDog = setTimeout(async function (MissionID) { that.RemovePoliceSprechwunschFromQueue(MissionID).then((deleteCount) => { $("#adis-sprechwunsch-police-frame").attr("src", ""); $("#adis-sprechwunsch-police-frame").attr("mission_id", "empty"); }); }, 2500, MissionID); } }); }); } }); } AddPoliceSprechwunschToQueue(WunschID) { return this.ADisDB.ADisSprechwunschPolice.put({ missionID: WunschID, done: 'false' }).catch((err) => {}) } UpdatePoliceSprechwunschToDone(WunschID) { console.log(WunschID, typeof WunschID); return this.ADisDB.ADisSprechwunschPolice.add({ missionID: WunschID, done: 'true' }).catch((err) => {}) } // - // - Index Page Loader // - IndexPage() { // - // - Google Font // - var styleElement = document.createElement("link"); styleElement.rel = "stylesheet"; styleElement.href = "https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700"; this.ADis_MyHead.appendChild(styleElement); // - // - FontAwesome 5 // - var scriptElement = document.createElement("script"); scriptElement.type = "text/javascript"; scriptElement.src = "https://use.fontawesome.com/releases/v5.5.0/js/all.js"; this.ADis_MyHead.appendChild(scriptElement); // - // - Navbar Dashboard // - var styleElement = document.createElement("link"); styleElement.rel = "stylesheet"; styleElement.type = "text/css"; styleElement.media = "screen"; styleElement.href = this.ADisSettings.url + this.ADisSettings.branch + "/style/interface.css"; this.ADis_MyHead.appendChild(styleElement); // Create Dashboard $('#news_li').before('
'); $('#adis-nav-item').html(` `) $("#adis-dashboard").css({ display: "none", opacity: "0" }); // Create Iframes $("body").append(''); $("#adis-frame-container").html(` `); $("#adis-frame-container").css({ display: "none", opacity: "0" }); } } window.AutomaticDisposeCall = new AutomaticDispose();