-
Notifications
You must be signed in to change notification settings - Fork 1
/
LSS_radio_call_police_table.user.js
304 lines (274 loc) · 13 KB
/
LSS_radio_call_police_table.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// ==UserScript==
// @name LSS radio call police table
// @version 1.3.1
// @author Crazycake
// @include /^https?:\/\/(?:w{3}\.)?(?:operacni-stredisko\.cz|alarmcentral-spil\.dk|leitstellenspiel\.de|missionchief\.gr|(?:missionchief-australia|missionchief|hatakeskuspeli|missionchief-japan|missionchief-korea|nodsentralspillet|meldkamerspel|operador193|jogo-operador112|jocdispecerat112|dispecerske-centrum|112-merkez|dyspetcher101-game)\.com|missionchief\.co\.uk|centro-de-mando\.es|centro-de-mando\.mx|operateur112\.fr|operatore112\.it|operatorratunkowy\.pl|dispetcher112\.ru|larmcentralen-spelet\.se)\/vehicles\/\d*\/?$
// @include /^https?:\/\/(?:w{3}\.)?(?:operacni-stredisko\.cz|alarmcentral-spil\.dk|leitstellenspiel\.de|missionchief\.gr|(?:missionchief-australia|missionchief|hatakeskuspeli|missionchief-japan|missionchief-korea|nodsentralspillet|meldkamerspel|operador193|jogo-operador112|jocdispecerat112|dispecerske-centrum|112-merkez|dyspetcher101-game)\.com|missionchief\.co\.uk|centro-de-mando\.es|centro-de-mando\.mx|operateur112\.fr|operatore112\.it|operatorratunkowy\.pl|dispetcher112\.ru|larmcentralen-spelet\.se)\/missions/\d*\/?$
// @grant none
// @updateURL https://github.com/Cr4zyc4k3/LSS/raw/master/LSS_radio_call_police_table.user.js
// ==/UserScript==
(function () {
'use strict';
if (localStorage.getItem('ccPrisonTable') === null || JSON.parse(localStorage.getItem('ccPrisonTable')).userId !== user_id) {
localStorage.setItem('ccPrisonTable', JSON.stringify({maxAllianceCells: -1, maxOwnCells: -1, userId: user_id}));
}
var ccPrisonTableLS = localStorage.getItem('ccPrisonTable');
//create settings in a modal
$('#btn_to_mission_place').parent().children().last().after(`
<a data-toggle="modal" data-target="#ccPrisonTableModal" class="btn btn-default pull-right">
<span class="glyphicon glyphicon-cog">
</span>
</a>
<div class="modal fade" id="ccPrisonTableModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centerd" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ccPrisonTableModalHeader">Einstellungen</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body form-group">
<label for="ccPrisonTableOwnCellsInput" class="col-form-label">Maximal angezeigte eigene Zellen: </label>
<input type="number" class="form-control-sm" id="ccPrisonTableOwnCellsInput" value="">
<label for="ccPrisonTableAllianceCellsInput" class="col-form-label">Maximal angezeigte Verbanszellen:</label>
<input type="number" class="form-control-sm" id="ccPrisonTableAllianceCellsInput" value=""><br>
<small class="form-text text-muted">"-1" zeigt alle Zellen an.</small>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
<button type="button" class="btn btn-success" data-dismiss="modal" id="ccPrisonTableModalSave">Speichern</button>
</div>
</div>
</div>
</div>
`);
//Raw table, to be injected later
const ccPrisonTableHTMLTable = `
<h4 id="ccPrisonerTableHeading">Eigene Zellen</h4>
<table id="ccPrisonerTable" class="table table-striped">
<thead>
<tr>
<th class="hidden-xs">Gebäude</th>
<th class="hidden-xs">Entfernung</th>
<th class="hidden-xs">Freie Zellen</th>
<th></th>
</tr>
</thead>
<tbody id="ccPrisonerTableBody">
</tbody>
</table>
<h4 id="ccPrisonerTableHeadingAlliance">Verbandszellen</h4>
<table id="ccPrisonerTableAlliance" class="table table-striped">
<thead>
<tr>
<th class="hidden-xs">Gebäude</th>
<th class="hidden-xs">Entfernung</th>
<th class="hidden-xs">Freie Zellen</th>
<th class="hidden-xs">Gebühr</th>
<th></th>
</tr>
</thead>
<tbody id="ccPrisonerTableAllianceBody">
</tbody>
</table>
`;
//Abort for resuce missions
if ($('h2').first().parent().children().length < 1) {
return;
}
// Selector whether it is the mission or vehicle tab. Here for vehicles
if (window.location.pathname.indexOf('vehicles') != -1) {
var ccPrisonTableCellArray = [];
//Get PrisonDiv
var ccPrisonTableDiv = $('#btn_to_mission_place').parent().next();
//Push every cell in Array
ccPrisonTableCellArray = ccPrisonTableDiv.children().first().children().toArray();
//Remove "Eigene Zellen"-Headline
ccPrisonTableCellArray.shift();
//Find "Verbandszellen"-Headline, important to differ between celltypes
const ccPrisonTableAllianceCellsHeadline = ccPrisonTableCellArray.indexOf(ccPrisonTableCellArray.find((el) => el.attributes.length == 0));
//Inject table from above
ccPrisonTableDiv.html(ccPrisonTableHTMLTable);
//Get "Eject Prisoner"-button and move it to top
const ccPrsionTableEjecetPrisoner = ccPrisonTableCellArray.slice(-1)[0];
ccPrsionTableEjecetPrisoner.classList.remove('btn-xs');
$('#btn_to_mission_place').after(ccPrsionTableEjecetPrisoner);
//Removes eject button and 2 <br>
ccPrisonTableCellArray.length = ccPrisonTableCellArray.length - 3;
get_ccPrisonTableLS();
if (ccPrisonTableLS.maxOwnCells == -1) {
var ccPrisonTablemaxOwnCells = ccPrisonTableAllianceCellsHeadline;
} else if (ccPrisonTableLS.maxOwnCells <= ccPrisonTableAllianceCellsHeadline) {
ccPrisonTablemaxOwnCells = ccPrisonTableLS.maxOwnCells;
} else {
ccPrisonTablemaxOwnCells = ccPrisonTableAllianceCellsHeadline;
}
//Fill the own-cells table
for (let i = 0; i < ccPrisonTablemaxOwnCells; i++) {
let stationName = ccPrisonTableCellArray[i].innerText.split('(')[0];
let freeCells = ccPrisonTableCellArray[i].innerText.split('(')[1].split(',')[0].split(':')[1];
let distance = ccPrisonTableCellArray[i].innerText.split(':')[2].split(')')[0];
let btn = '';
let disabled = '';
if (freeCells == 0) {
btn = 'btn-danger';
disabled = 'disabled';
} else if (freeCells > 0 && freeCells < 5) {
btn = 'btn-warning';
} else if (freeCells >= 5) {
btn = 'btn-success';
}
$('#ccPrisonerTable').append(
`<tr>
<td>${stationName}</td>
<td class="hidden-xs">${distance}</td>
<td class="hidden-xs">${freeCells}</td>
<td><a class="btn ${btn}" href="${ccPrisonTableCellArray[i].href}" ${disabled} >Anfahren</a></td>
</tr>`
);
}
if (ccPrisonTableLS.maxAllianceCells == -1) {
var ccPrisonTablemaxAllianceCells = ccPrisonTableCellArray.length;
} else if (Number(ccPrisonTableLS.maxAllianceCells) + Number(ccPrisonTableAllianceCellsHeadline) + 1 <= ccPrisonTableCellArray.length) {
ccPrisonTablemaxAllianceCells = Number(ccPrisonTableLS.maxAllianceCells) + Number(ccPrisonTableAllianceCellsHeadline) + 1;
} else {
ccPrisonTablemaxAllianceCells = ccPrisonTableCellArray.length;
}
//Fill the alliance cell table
for (let i = ccPrisonTableAllianceCellsHeadline + 1; i < ccPrisonTablemaxAllianceCells; i++) {
let stationName = ccPrisonTableCellArray[i].innerText.split('(')[0];
let freeCells = ccPrisonTableCellArray[i].innerText.split(': ')[1].split(',')[0];
let distance = ccPrisonTableCellArray[i].innerText.split(': ')[2].split(', ')[0];
let fee = ccPrisonTableCellArray[i].innerText.split(': ')[3].split(')')[0];
let btn = '';
let disabled = '';
if (freeCells == 0) {
btn = 'btn-danger';
disabled = 'disabled';
} else if (freeCells > 0 && freeCells < 5) {
btn = 'btn-warning';
} else if (freeCells >= 5) {
btn = 'btn-success';
}
$('#ccPrisonerTableAlliance').append(
`<tr>
<td>${stationName}</td>
<td class="hidden-xs">${distance}</td>
<td class="hidden-xs">${freeCells}</td>
<td class="hidden-xs">${fee}</td>
<td><a class="btn ${btn}" href="${ccPrisonTableCellArray[i].href}" ${disabled} >Anfahren</a></td>
</tr>`
);
}
}
//Here for missions
else if (window.location.pathname.indexOf('missions') != -1) {
} /* else if (window.location.pathname.indexOf('missions') != -1) {
$('[id^=vehicle_prisoner_select_]').each(function () {
console.log('Wörks for' + $(this).attr('id'));
let ccPrisonTableDiv = $(this);
let ccPrisonTableCellArray = ccPrisonTableDiv.children().toArray();
//Find "Load-more button", important to differ between celltype
for (let i = 0; i < ccPrisonTableCellArray.length; i++) {
if (ccPrisonTableCellArray[i].classList.contains('load_cells')) {
console.log(ccPrisonTableCellArray);
ccPrisonTableCellArray.splice(i - 1, 3);
var ccPrisonTableAllianceCellsHeadline = i;
break;
}
}
//Inject table from above
ccPrisonTableDiv.html(ccPrisonTableHTMLTable);
if (ccPrisonTableLS.maxOwnCells == -1) {
var ccPrisonTablemaxOwnCells = ccPrisonTableAllianceCellsHeadline;
} else if (ccPrisonTableLS.maxOwnCells <= ccPrisonTableAllianceCellsHeadline) {
ccPrisonTablemaxOwnCells = ccPrisonTableLS.maxOwnCells;
} else {
ccPrisonTablemaxOwnCells = ccPrisonTableAllianceCellsHeadline;
}
console.log(ccPrisonTableCellArray);
//Fill the own-cells table
for (let i = 0; i < ccPrisonTablemaxOwnCells; i++) {
let stationName = ccPrisonTableCellArray[i].innerText.split('(')[0];
let freeCells = ccPrisonTableCellArray[i].innerText.split('(')[1].split(',')[0].split(':')[1];
let distance = ccPrisonTableCellArray[i].innerText.split(':')[2].split(')')[0];
let btn = '';
let disabled = '';
if (freeCells == 0) {
btn = 'btn-danger';
disabled = 'disabled';
} else if (freeCells > 0 && freeCells < 5) {
btn = 'btn-warning';
} else if (freeCells >= 5) {
btn = 'btn-success';
}
$('#ccPrisonerTable').append(
`<tr>
<td>${stationName}</td>
<td class="hidden-xs">${distance}</td>
<td class="hidden-xs">${freeCells}</td>
<td>
<a class="btn ${btn}" href="${ccPrisonTableCellArray[i].href}" ${disabled} >Anfahren</a>
</td>
</tr>`
);
}
get_ccPrisonTableLS();
if (ccPrisonTableLS.maxAllianceCells == -1) {
var ccPrisonTablemaxAllianceCells = ccPrisonTableCellArray.length;
} else if (Number(ccPrisonTableLS.maxAllianceCells) + Number(ccPrisonTableAllianceCellsHeadline) + 1 <= ccPrisonTableCellArray.length) {
ccPrisonTablemaxAllianceCells = Number(ccPrisonTableLS.maxAllianceCells) + Number(ccPrisonTableAllianceCellsHeadline) + 1;
} else {
ccPrisonTablemaxAllianceCells = ccPrisonTableCellArray.length;
}
//Fill the alliance cell table
for (let i = ccPrisonTableAllianceCellsHeadline + 1; i < ccPrisonTablemaxAllianceCells; i++) {
let stationName = ccPrisonTableCellArray[i].innerText.split('(')[0];
let freeCells = ccPrisonTableCellArray[i].innerText.split(': ')[1].split(',')[0];
let distance = ccPrisonTableCellArray[i].innerText.split(': ')[2].split(', ')[0];
let fee = ccPrisonTableCellArray[i].innerText.split(': ')[3].split(')')[0];
let btn = '';
if (freeCells == 0) {
btn = 'btn-danger btn-disabled';
} else if (freeCells > 0 && freeCells < 5) {
btn = 'btn-warning';
} else if (freeCells >= 5) {
btn = 'btn-success';
}
$('#ccPrisonerTableAlliance').append(
`<tr>
<td>${stationName}</td>
<td class="hidden-xs">${distance}</td>
<td class="hidden-xs">${freeCells}</td>
<td class="hidden-xs">${fee}</td>
<td><a class="btn ${btn}" href="${ccPrisonTableCellArray[i].href}">Anfahren</a></td>
</tr>`
);
}
});
} */
function get_ccPrisonTableLS() {
ccPrisonTableLS = JSON.parse(localStorage.getItem('ccPrisonTable'));
$('#ccPrisonTableOwnCellsInput').val(ccPrisonTableLS.maxOwnCells);
$('#ccPrisonTableAllianceCellsInput').val(ccPrisonTableLS.maxAllianceCells);
return ccPrisonTableLS;
}
function set_ccPrisonTableLS(value) {
localStorage.setItem('ccPrisonTable', JSON.stringify({maxAllianceCells: value.maxAllianceCells, maxOwnCells: value.maxOwnCells, userId: user_id}));
}
$('#ccPrisonTableModalSave').on('click', function () {
if (!isNaN($('#ccPrisonTableOwnCellsInput').val())) {
ccPrisonTableLS.maxOwnCells = $('#ccPrisonTableOwnCellsInput').val();
} else {
ccPrisonTableLS.maxOwnCells = -1;
}
if (!isNaN($('#ccPrisonTableAllianceCellsInput').val())) {
ccPrisonTableLS.maxAllianceCells = $('#ccPrisonTableAllianceCellsInput').val();
} else {
ccPrisonTableLS.maxAllianceCells = -1;
}
set_ccPrisonTableLS(ccPrisonTableLS);
location.reload();
});
})();