diff --git a/dist/autoloader.js b/dist/autoloader.js index fb5a7e1..16db24f 100755 --- a/dist/autoloader.js +++ b/dist/autoloader.js @@ -1,4 +1,4 @@ -/*Generated on:Wed Nov 28 2018 20:37:28 GMT+0100 (CET)*/ +/*Generated on:Wed Nov 28 2018 20:54:50 GMT+0100 (CET)*/ var AutomaticDispose_Branch = "master"; var AutomaticDispose_URL = "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/"; var da_lss_adis_time = new Date().getTime(); diff --git a/dist/autoloaderV2.js b/dist/autoloaderV2.js index f88b7b4..427d023 100644 --- a/dist/autoloaderV2.js +++ b/dist/autoloaderV2.js @@ -1,4 +1,4 @@ -/*Generated on:Wed Nov 28 2018 20:37:28 GMT+0100 (CET)*/ +/*Generated on:Wed Nov 28 2018 20:54:50 GMT+0100 (CET)*/ /* * Dexie.js - a minimalistic wrapper for IndexedDB * =============================================== @@ -4502,7 +4502,7 @@ class AutomaticDispose { this.RescueVehicleFrameWatchDog = null; this.PoliceVehicleFrameWatchDog = null; - + this.ADisDB = new Dexie('LSS_AutomaticDispo'); this.ADisDB.version(1).stores({ @@ -4595,9 +4595,21 @@ class AutomaticDispose { } /** - * / /=require ../script/mission.js - * / /=require ../script/sprechwunsch.js - */ + * / /=require ../script/mission.js + */ + // - + // - Sprechwunsch Handler Rettung + // - + if (window.location.pathname.indexOf("/vehicles/") !== -1 && window.name == 'adis-sprechwunsch-rescue') { + that.Check_Call_Hospitals(); + } + + // - + // - Sprechwunsch Handler Polizei/Gefangene + // - + if (window.location.pathname.indexOf("/missions/") !== -1 && window.name == 'adis-sprechwunsch-police') { + that.Check_Call_Police_Active(); + } }); console.log('nonstatic', this.ADisSettings) @@ -4615,7 +4627,7 @@ class AutomaticDispose { ADSettings() { let that = this; - return new Promise((resolve, reject) =>{ + return new Promise((resolve, reject) => { let res = {}; that.ADisDB.ADisSettings.each((setting) => { res[setting.name] = setting.value; @@ -4718,6 +4730,103 @@ class AutomaticDispose { } + Check_Call_Hospitals() { + if ($("h4:contains('Eigene Krankenhäuser')").length > 0 || $("h4:contains('Verbandskrankenhäuser')").length > 0) { + this.Collect_Hospitals(); + } else { + VehicleID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1); + this.RemoveRescueSprechwunschFromQueue(VehicleID).then((deleteCount) => { + $("#adis-sprechwunsch-rescue-frame").attr("src", ""); + $("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", "empty"); + }); + } + } + + // Krankenhaus auswählen + Collect_Hospitals() { + if ($("h4:contains('Eigene Krankenhäuser')").length > 0) { + $("h4:contains('Eigene Krankenhäuser')").next("table").find("tbody").find("tr").each(function () { + var HospitalHref = $(this).find("a:contains('Anfahren')").attr("href"); + var HospitalID = Number(parseInt($(this).find("a:contains('Anfahren')").attr("id").replace("btn_approach_", ""))); + var HospitalDistance = parseInt($(this).find("td").eq("1").text()); + var HospitalFreeBeds = parseInt($(this).find("td").eq("2").text()); + + var HospitalValue = HospitalDistance * 450 * -1; + HospitalValue += 2000; // Own Hospitals are better :-) + if ($(this).find(".label:contains('Ja')").length > 0) { + HospitalValue += 2000; + } + + if (HospitalFreeBeds > 0) { + Hospitals.push({ + "id": HospitalID, + "value": HospitalValue, + "distance": HospitalDistance, + "href": HospitalHref + }); + } + }); + } + + if ($("h4:contains('Verbandskrankenhäuser')").length > 0) { + $("h4:contains('Verbandskrankenhäuser')").next("table").find("tbody").find("tr").each(function () { + var HospitalHref = $(this).find("a").attr("href") + var HospitalID = Number(parseInt(HospitalHref.substr(HospitalHref.lastIndexOf("/") + 1))); + var HospitalDistance = parseInt($(this).find("td").eq("1").text()); + var HospitalFreeBeds = parseInt($(this).find("td").eq("2").text()); + var HospitalTaxes = parseInt($(this).find("td").eq("3").text()); + var HospitalSpecialDepartment = false; + + // Add Button-ID to Alliance-Hospital + $(this).find("a").attr("id", "btn_approach_" + HospitalID.toString()); + + var HospitalValue = HospitalDistance * 450 * -1; + + if ($(this).find(".label:contains('Ja')").length > 0) { + HospitalSpecialDepartment = true; + HospitalValue += 2000; + } + + if (HospitalTaxes == 0) { + HospitalValue += 2000; + } else if (HospitalTaxes > 0 && HospitalTaxes <= 10) { + HospitalValue += 1000; + } else if (HospitalTaxes > 10 && HospitalTaxes <= 20) { + HospitalValue += 0; + } else { + HospitalValue -= 5000; + } + + if (HospitalFreeBeds > 0 && HospitalSpecialDepartment) { + Hospitals.push({ + "id": HospitalID, + "value": HospitalValue, + "taxes": HospitalTaxes, + "distance": HospitalDistance, + "href": HospitalHref + }); + } + }); + } + + Hospitals.sort(function (a, b) { + return a.value - b.value; + }); + + Hospitals.reverse(); + this.Send_Vehicle_To_Hospital() + } + + // Krankenhaus einlieferung + Send_Vehicle_To_Hospital() { + //var HospitalID = Hospitals[0].id; + var HospitalHref = Hospitals[0].href; + + // TODO: tellParent("ADisMissionDone(" + window.name + "," + MissionID + ");"); + document.location.href = document.location.origin + HospitalHref; + + } + // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // - // - Assign & Unassign Missions to Dispatchers @@ -4808,6 +4917,202 @@ class AutomaticDispose { }).catch((err) => {}) } + + Check_Call_Police_Active() { + if ($('#h2_prisoners').length > 0) { + this.Collect_Jails(); + } else { + this.RemovePoliceSprechwunschFromQueue(MissionID).then((deleteCount) => { + $("#adis-sprechwunsch-police-frame").attr("src", ""); + $("#adis-sprechwunsch-police-frame").attr("mission_id", "empty"); + }); + } + } + + // Gefängnis auswählen + Collect_Jails() { + var CountGefangene = Number(parseInt($('#h2_prisoners').text())); + var parentNode = $('#mission_vehicle_at_mission tr > td:nth-child(5) > a:contains("Jomaar")').parent().parent(); + var GefKw = parentNode.find('td:nth-child(2) > a[vehicle_type_id="52"]'); + var FuStW = parentNode.find('td:nth-child(2) > a[vehicle_type_id="32"]'); + var GefKwGefaegnisse = $(GefKw[0]).parent().parent().next('tr'); + var FuStWGefaegnisse = $(FuStW[0]).parent().parent().next('tr'); + + GefKwGefaegnisse.find("a:contains('Freie Zellen')").each(function () { + var JailHref = $(this).attr("href"); + var JailID = JailHref.split("/").pop(); + var JailText = $(this).text(); + var JailFreeBeds = 0; + var JailDistance = 0; + var JailTax = 0; + let m; + while ((m = JailRegEx.exec(JailText)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === JailRegEx.lastIndex) { + JailRegEx.lastIndex++; + } + + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + if (groupIndex == 1) { + JailFreeBeds = parseInt(match.trim()); + } else if (groupIndex == 2) { + JailDistance = parseInt(match.trim()); + } else if (groupIndex == 3 && typeof match != "undefined") { + JailTax = parseInt(match.trim()); + } + }); + } + + var JailValue = JailDistance * 450 * -1; + JailValue += 11; //GefKw bevorzugt + + if (JailTax == 0) { + JailValue += 10000; + } else if (JailTax > 0 && JailTax <= 10) { + JailValue += 5000; + } else if (JailTax > 10 && JailTax <= 20) { + JailValue += 1000; + } else { + JailValue -= 10000; + } + + if (JailFreeBeds >= 5) { + JailValue += 15000; + } else if (JailFreeBeds >= 1) { + JailValue += 1000; + } else { + JailValue -= 5000; + } + + if (JailFreeBeds >= 5) { + Jails.push({ + "id": JailID, + "value": JailValue + 1000, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } else if (JailFreeBeds >= 1) { + Jails.push({ + "id": JailID, + "value": JailValue, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } + }); + FuStWGefaegnisse.find("a:contains('Freie Zellen')").each(function () { + var JailHref = $(this).attr("href"); + var JailID = JailHref.split("/").pop(); + var JailText = $(this).text(); + var JailFreeBeds = 0; + var JailDistance = 0; + var JailTax = 0; + let m; + while ((m = JailRegEx.exec(JailText)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === JailRegEx.lastIndex) { + JailRegEx.lastIndex++; + } + + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + if (groupIndex == 1) { + JailFreeBeds = parseInt(match.trim()); + } else if (groupIndex == 2) { + JailDistance = parseInt(match.trim()); + } else if (groupIndex == 3 && typeof match != "undefined") { + JailTax = parseInt(match.trim()); + } + }); + } + + var JailValue = JailDistance * 450 * -1; + + if (JailTax == 0) { + JailValue += 10000; + } else if (JailTax > 0 && JailTax <= 10) { + JailValue += 5000; + } else if (JailTax > 10 && JailTax <= 20) { + JailValue += 1000; + } else { + JailValue -= 10000; + } + + if (JailFreeBeds >= 5) { + JailValue += 15000; + } else if (JailFreeBeds >= 1) { + JailValue += 1000; + } else { + JailValue -= 5000; + } + + if (JailFreeBeds >= CountGefangene) { + Jails.push({ + "id": JailID, + "value": JailValue + 1000, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } else if (JailFreeBeds >= 1) { + Jails.push({ + "id": JailID, + "value": JailValue, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } + }); + + Jails.sort(function (a, b) { + return a.value - b.value; + }); + + Jails.reverse(); + if (Jails.length > 0) { + this.Send_Vehicle_To_Jail() + } else { + $("#mission_vehicle_driving tbody, #mission_vehicle_at_mission tbody").find("tr").each(function () { + var CalledVehicleID = parseInt($(this).find("a").first().attr("vehicle_type_id")); + if (CalledVehicleID == 52) { + CountGefangene -= 5; + } else if (CalledVehicleID == 32) { + CountGefangene -= 1; + } + }); + + if ($('#vehicle_show_table_all tr[vehicle_type="GefKw"] input[type="checkbox"]').size() > 0 && CountGefangene >= 5) { + $('#vehicle_show_table_all tr[vehicle_type="GefKw"] input[type="checkbox"]').each(function () { + if (CountGefangene > 0) { + $(this).click() + CountGefangene -= 5; + } + }); + } + if ($('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]').size() > 0 && CountGefangene > 0) { + $('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]').each(function () { + if (CountGefangene > 0) { + $(this).click() + CountGefangene -= 1; + } + }); + } + if ($('#vehicle_show_table_all input[type="checkbox"]:checked').size() > 0) { + $('#mission_alarm_btn').click(); + } + } + } + + // Gefängnis einlieferung + Send_Vehicle_To_Jail() { + var JailHref = Jails[0].href + document.location.href = document.location.origin + JailHref; + } + // - // - Index Page Loader // - diff --git a/src/autoloaderV2.js b/src/autoloaderV2.js index 52917fd..22bacc8 100644 --- a/src/autoloaderV2.js +++ b/src/autoloaderV2.js @@ -27,7 +27,7 @@ class AutomaticDispose { this.RescueVehicleFrameWatchDog = null; this.PoliceVehicleFrameWatchDog = null; - + this.ADisDB = new Dexie('LSS_AutomaticDispo'); this.ADisDB.version(1).stores({ @@ -120,9 +120,21 @@ class AutomaticDispose { } /** - * / /=require ../script/mission.js - * / /=require ../script/sprechwunsch.js - */ + * / /=require ../script/mission.js + */ + // - + // - Sprechwunsch Handler Rettung + // - + if (window.location.pathname.indexOf("/vehicles/") !== -1 && window.name == 'adis-sprechwunsch-rescue') { + that.Check_Call_Hospitals(); + } + + // - + // - Sprechwunsch Handler Polizei/Gefangene + // - + if (window.location.pathname.indexOf("/missions/") !== -1 && window.name == 'adis-sprechwunsch-police') { + that.Check_Call_Police_Active(); + } }); console.log('nonstatic', this.ADisSettings) @@ -140,7 +152,7 @@ class AutomaticDispose { ADSettings() { let that = this; - return new Promise((resolve, reject) =>{ + return new Promise((resolve, reject) => { let res = {}; that.ADisDB.ADisSettings.each((setting) => { res[setting.name] = setting.value; @@ -243,6 +255,103 @@ class AutomaticDispose { } + Check_Call_Hospitals() { + if ($("h4:contains('Eigene Krankenhäuser')").length > 0 || $("h4:contains('Verbandskrankenhäuser')").length > 0) { + this.Collect_Hospitals(); + } else { + VehicleID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1); + this.RemoveRescueSprechwunschFromQueue(VehicleID).then((deleteCount) => { + $("#adis-sprechwunsch-rescue-frame").attr("src", ""); + $("#adis-sprechwunsch-rescue-frame").attr("vehicle_id", "empty"); + }); + } + } + + // Krankenhaus auswählen + Collect_Hospitals() { + if ($("h4:contains('Eigene Krankenhäuser')").length > 0) { + $("h4:contains('Eigene Krankenhäuser')").next("table").find("tbody").find("tr").each(function () { + var HospitalHref = $(this).find("a:contains('Anfahren')").attr("href"); + var HospitalID = Number(parseInt($(this).find("a:contains('Anfahren')").attr("id").replace("btn_approach_", ""))); + var HospitalDistance = parseInt($(this).find("td").eq("1").text()); + var HospitalFreeBeds = parseInt($(this).find("td").eq("2").text()); + + var HospitalValue = HospitalDistance * 450 * -1; + HospitalValue += 2000; // Own Hospitals are better :-) + if ($(this).find(".label:contains('Ja')").length > 0) { + HospitalValue += 2000; + } + + if (HospitalFreeBeds > 0) { + Hospitals.push({ + "id": HospitalID, + "value": HospitalValue, + "distance": HospitalDistance, + "href": HospitalHref + }); + } + }); + } + + if ($("h4:contains('Verbandskrankenhäuser')").length > 0) { + $("h4:contains('Verbandskrankenhäuser')").next("table").find("tbody").find("tr").each(function () { + var HospitalHref = $(this).find("a").attr("href") + var HospitalID = Number(parseInt(HospitalHref.substr(HospitalHref.lastIndexOf("/") + 1))); + var HospitalDistance = parseInt($(this).find("td").eq("1").text()); + var HospitalFreeBeds = parseInt($(this).find("td").eq("2").text()); + var HospitalTaxes = parseInt($(this).find("td").eq("3").text()); + var HospitalSpecialDepartment = false; + + // Add Button-ID to Alliance-Hospital + $(this).find("a").attr("id", "btn_approach_" + HospitalID.toString()); + + var HospitalValue = HospitalDistance * 450 * -1; + + if ($(this).find(".label:contains('Ja')").length > 0) { + HospitalSpecialDepartment = true; + HospitalValue += 2000; + } + + if (HospitalTaxes == 0) { + HospitalValue += 2000; + } else if (HospitalTaxes > 0 && HospitalTaxes <= 10) { + HospitalValue += 1000; + } else if (HospitalTaxes > 10 && HospitalTaxes <= 20) { + HospitalValue += 0; + } else { + HospitalValue -= 5000; + } + + if (HospitalFreeBeds > 0 && HospitalSpecialDepartment) { + Hospitals.push({ + "id": HospitalID, + "value": HospitalValue, + "taxes": HospitalTaxes, + "distance": HospitalDistance, + "href": HospitalHref + }); + } + }); + } + + Hospitals.sort(function (a, b) { + return a.value - b.value; + }); + + Hospitals.reverse(); + this.Send_Vehicle_To_Hospital() + } + + // Krankenhaus einlieferung + Send_Vehicle_To_Hospital() { + //var HospitalID = Hospitals[0].id; + var HospitalHref = Hospitals[0].href; + + // TODO: tellParent("ADisMissionDone(" + window.name + "," + MissionID + ");"); + document.location.href = document.location.origin + HospitalHref; + + } + // - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // - // - Assign & Unassign Missions to Dispatchers @@ -333,6 +442,202 @@ class AutomaticDispose { }).catch((err) => {}) } + + Check_Call_Police_Active() { + if ($('#h2_prisoners').length > 0) { + this.Collect_Jails(); + } else { + this.RemovePoliceSprechwunschFromQueue(MissionID).then((deleteCount) => { + $("#adis-sprechwunsch-police-frame").attr("src", ""); + $("#adis-sprechwunsch-police-frame").attr("mission_id", "empty"); + }); + } + } + + // Gefängnis auswählen + Collect_Jails() { + var CountGefangene = Number(parseInt($('#h2_prisoners').text())); + var parentNode = $('#mission_vehicle_at_mission tr > td:nth-child(5) > a:contains("Jomaar")').parent().parent(); + var GefKw = parentNode.find('td:nth-child(2) > a[vehicle_type_id="52"]'); + var FuStW = parentNode.find('td:nth-child(2) > a[vehicle_type_id="32"]'); + var GefKwGefaegnisse = $(GefKw[0]).parent().parent().next('tr'); + var FuStWGefaegnisse = $(FuStW[0]).parent().parent().next('tr'); + + GefKwGefaegnisse.find("a:contains('Freie Zellen')").each(function () { + var JailHref = $(this).attr("href"); + var JailID = JailHref.split("/").pop(); + var JailText = $(this).text(); + var JailFreeBeds = 0; + var JailDistance = 0; + var JailTax = 0; + let m; + while ((m = JailRegEx.exec(JailText)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === JailRegEx.lastIndex) { + JailRegEx.lastIndex++; + } + + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + if (groupIndex == 1) { + JailFreeBeds = parseInt(match.trim()); + } else if (groupIndex == 2) { + JailDistance = parseInt(match.trim()); + } else if (groupIndex == 3 && typeof match != "undefined") { + JailTax = parseInt(match.trim()); + } + }); + } + + var JailValue = JailDistance * 450 * -1; + JailValue += 11; //GefKw bevorzugt + + if (JailTax == 0) { + JailValue += 10000; + } else if (JailTax > 0 && JailTax <= 10) { + JailValue += 5000; + } else if (JailTax > 10 && JailTax <= 20) { + JailValue += 1000; + } else { + JailValue -= 10000; + } + + if (JailFreeBeds >= 5) { + JailValue += 15000; + } else if (JailFreeBeds >= 1) { + JailValue += 1000; + } else { + JailValue -= 5000; + } + + if (JailFreeBeds >= 5) { + Jails.push({ + "id": JailID, + "value": JailValue + 1000, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } else if (JailFreeBeds >= 1) { + Jails.push({ + "id": JailID, + "value": JailValue, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } + }); + FuStWGefaegnisse.find("a:contains('Freie Zellen')").each(function () { + var JailHref = $(this).attr("href"); + var JailID = JailHref.split("/").pop(); + var JailText = $(this).text(); + var JailFreeBeds = 0; + var JailDistance = 0; + var JailTax = 0; + let m; + while ((m = JailRegEx.exec(JailText)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === JailRegEx.lastIndex) { + JailRegEx.lastIndex++; + } + + // The result can be accessed through the `m`-variable. + m.forEach((match, groupIndex) => { + if (groupIndex == 1) { + JailFreeBeds = parseInt(match.trim()); + } else if (groupIndex == 2) { + JailDistance = parseInt(match.trim()); + } else if (groupIndex == 3 && typeof match != "undefined") { + JailTax = parseInt(match.trim()); + } + }); + } + + var JailValue = JailDistance * 450 * -1; + + if (JailTax == 0) { + JailValue += 10000; + } else if (JailTax > 0 && JailTax <= 10) { + JailValue += 5000; + } else if (JailTax > 10 && JailTax <= 20) { + JailValue += 1000; + } else { + JailValue -= 10000; + } + + if (JailFreeBeds >= 5) { + JailValue += 15000; + } else if (JailFreeBeds >= 1) { + JailValue += 1000; + } else { + JailValue -= 5000; + } + + if (JailFreeBeds >= CountGefangene) { + Jails.push({ + "id": JailID, + "value": JailValue + 1000, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } else if (JailFreeBeds >= 1) { + Jails.push({ + "id": JailID, + "value": JailValue, + "text": JailText, + "distance": JailDistance, + "href": JailHref + }); + } + }); + + Jails.sort(function (a, b) { + return a.value - b.value; + }); + + Jails.reverse(); + if (Jails.length > 0) { + this.Send_Vehicle_To_Jail() + } else { + $("#mission_vehicle_driving tbody, #mission_vehicle_at_mission tbody").find("tr").each(function () { + var CalledVehicleID = parseInt($(this).find("a").first().attr("vehicle_type_id")); + if (CalledVehicleID == 52) { + CountGefangene -= 5; + } else if (CalledVehicleID == 32) { + CountGefangene -= 1; + } + }); + + if ($('#vehicle_show_table_all tr[vehicle_type="GefKw"] input[type="checkbox"]').size() > 0 && CountGefangene >= 5) { + $('#vehicle_show_table_all tr[vehicle_type="GefKw"] input[type="checkbox"]').each(function () { + if (CountGefangene > 0) { + $(this).click() + CountGefangene -= 5; + } + }); + } + if ($('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]').size() > 0 && CountGefangene > 0) { + $('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]').each(function () { + if (CountGefangene > 0) { + $(this).click() + CountGefangene -= 1; + } + }); + } + if ($('#vehicle_show_table_all input[type="checkbox"]:checked').size() > 0) { + $('#mission_alarm_btn').click(); + } + } + } + + // Gefängnis einlieferung + Send_Vehicle_To_Jail() { + var JailHref = Jails[0].href + document.location.href = document.location.origin + JailHref; + } + // - // - Index Page Loader // -