-
Notifications
You must be signed in to change notification settings - Fork 4
/
Mission-Less-ELW-Highlight.user.js
54 lines (52 loc) · 2.03 KB
/
Mission-Less-ELW-Highlight.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ==UserScript==
// @name LSS-Mission-Less-ELW-Highlight
// @version 1.0.5
// @description Highlights missions in missionlist with less than required ELWs
// @author Jan (jxn_30)
// @match https://www.leitstellenspiel.de/
// @grant none
// ==/UserScript==
(function() {
'use strict';
fetch('/einsaetze.json')
.then(res => res.json())
.then(data => {
const colorize = missionId => {
const panel = document.getElementById(`mission_${missionId}`);
const missionType = panel.getAttribute('mission_type_id');
const specs = data.find(m => m.id === missionType);
const mission = document.getElementById(`mission_missing_${missionId}`);
if (Number.isNaN(missionType) || !specs || !mission) return;
const reqElw1 = specs.requirements.battalion_chief_vehicles || 0;
const reqElw2 = specs.requirements.mobile_command_vehicles || 0;
const elws = mission.textContent
.replace(/^\D+: /, '')
.split(/[.,]/)
.filter(r => r.match(/\d+ ELW [12]/));
const elw = {
1: 0,
2: 0,
};
elws.forEach(
type =>
(elw[type.match(/\d+$/)] = parseInt(
type.trim().match(/^\d+/)[0]
))
);
if (elw[1] < reqElw1 || elw[2] < reqElw2)
panel.querySelector('.panel-heading').style.background =
'blue';
else panel.querySelector('.panel-heading').style.background = null;
};
Array.from(
document.querySelectorAll(
':not(#mission_list_sicherheitswache) [id^="mission_missing_"].alert'
)
).forEach(({id}) => colorize(id.replace(/\D*/, '')));
const missionMarkerAddOrig = window.missionMarkerAdd;
window.missionMarkerAdd = (...args) => {
missionMarkerAddOrig(...args);
colorize(args[0].id);
};
});
})();