SHARE
TWEET

Untitled

a guest Dec 14th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         JustInTime
  3. // @version      1.0.3
  4. // @author       Allure149
  5. // @include      *://www.leitstellenspiel.de/*
  6. // @include      *://www.missionchief.com/*
  7. // @include      *://www.meldkamerspel.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10. /* global $ */
  11.  
  12. (function() {
  13.     'use strict';
  14.  
  15.     if (localStorage.getItem("jit_own_missions") === null) {
  16.         localStorage.jit_own_missions = true;
  17.         localStorage.jit_car_ids = "30,32";
  18.     }
  19.  
  20.     let car_ids = localStorage.jit_car_ids.split(","); // HLF 20, FuStW
  21.     let eigene_einsaetze = localStorage.jit_own_missions; // eigene_einsaetze = false wenn ausschliesslich Verbandseinsaetze geprueft werden sollen
  22.  
  23.     $("#group_max_distance").after('<div><button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#jit_options">JIT Optionen</button><div class="modal fade" id="jit_options" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="display: none;"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="exampleModalLabel">JustInTime Optionen</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body"><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="jit_own_missions" name="jit_own_missions"><label class="form-check-label" for="jit_own_missions"> Eigene Einsätze einbeziehen?</label></div><div class="form-group"><label for="jit_car_ids">IDs:</label><input type="text" name="jit_car_ids" id="jit_car_ids" class="form-control"></div><div class="modal-footer"></div><button type="button" class="btn btn-secondary" data-dismiss="modal">Schließen</button><button type="button" id="jit_save" class="btn btn-primary">Speichern</button></div></div></div></div></div>');
  24.  
  25.     if(eigene_einsaetze == "true") $("#jit_own_missions").prop("checked", true);
  26.     else $("#jit_own_missions").prop("checked", false);
  27.  
  28.     $("#jit_car_ids").val(localStorage.jit_car_ids);
  29.  
  30.     $("#jit_save").on("click", function(){
  31.         localStorage.jit_own_missions = $("#jit_own_missions").is(":checked");
  32.         localStorage.jit_car_ids = $("#jit_car_ids").val();
  33.         $("#jit_options").modal("toggle");
  34.     });
  35.  
  36.     const mission_verband = $("#missionH1").text().trim().startsWith("[Verband]") ? true : false;
  37.     const mission_id = $("#mission_reply_mission_id").val();
  38.     let mission_time = $(".mission_header_info").find("#mission_countdown_" + mission_id).text().split(":").map(function(x){ return parseInt(x,10) });
  39.     let mission_secs = (mission_time.length == 2) ? (mission_time[0] * 60) + mission_time[1] : (mission_time[0] * 3600) + (mission_time[1] * 60) + mission_time[2];
  40.     let vehicle_type_id = 0; // aktuell gefiltertes Fahrzeug
  41.     let car_id = 0; // != 0 wenn korrektes Fahrzeug gefunden wurde
  42.     let car_secs = 0;
  43.     let found = false;
  44.     let state = "danger";
  45.     let time_remain = 0;
  46.     let end_text = "";
  47.  
  48.     if (!window.location.href.match(/(missions\/\d+$)|(einsaetze\/\d+$)/g)) return false;
  49.  
  50.     if(eigene_einsaetze == "false" && !mission_verband) return false;
  51.  
  52.     $("#vehicle_show_table_body_all > tr").each(function(){
  53.         vehicle_type_id = $(this).find("td:nth-child(3)").attr("vehicle_type_id");
  54.         car_secs = $(this).find("td:nth-child(4)").attr("timevalue");
  55.         time_remain = mission_secs - car_secs;
  56.         found = false;
  57.  
  58.         $.each(car_ids, function(i,e){
  59.             if(e == vehicle_type_id) {
  60.                 car_id = vehicle_type_id;
  61.                 return false;
  62.             }
  63.         });
  64.  
  65.         if(car_id != 0) {
  66.             if(time_remain > 60) {
  67.                 state = "success";
  68.             } else if(time_remain <= 60 && time_remain > 0) {
  69.                 state = "warning";
  70.             } else if(time_remain < 0){
  71.                 state = "danger";
  72.                 end_text = "Zeitfenster überschritten!";
  73.             }
  74.  
  75.             found = true;
  76.             return false;
  77.         } else {
  78.             state = "danger";
  79.             end_text = "Kein Fahrzeug gefunden!";
  80.         }
  81.  
  82.         if(found) return false;
  83.     });
  84.  
  85.     if(isNaN(mission_secs)) {
  86.         end_text = "Einsatz hat noch nicht begonnen.";
  87.         state = "warning";
  88.     }
  89.  
  90.     console.log("mission_id: " + mission_id);
  91.     console.log("mission_time: " + mission_time);
  92.     console.log("mission_secs: " + mission_secs);
  93.     console.log("car_secs: " + car_secs);
  94.     console.log("vehicle_type_id: " + car_id);
  95.     console.log("time_remain: " + time_remain);
  96.  
  97.     $("#missionH1").after("<div id='mission_countdown_remaining' class='alert alert-" + state + "' style='float:right; padding: 2px 5px; margin:0'></div>");
  98.  
  99.     if(time_remain > 0) missionCountdown(time_remain, 'remaining');
  100.     else $("#mission_countdown_remaining").text(end_text);
  101. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top