forked from jxn-30/LSS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox-multiselect.user.js
99 lines (86 loc) · 4.25 KB
/
checkbox-multiselect.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
// ==UserScript==
// @name LSS checkbox-multiselect
// @version 1.0.0
// @author Jan (jxn_30)
// @description Allows to select multiple checkbox in a row by pressing the shift key
// @namespace https://jxn.lss-manager.de/
// @match https://www.operacni-stredisko.cz/*
// @match https://policie.operacni-stredisko.cz/*
// @match https://www.alarmcentral-spil.dk/*
// @match https://politi.alarmcentral-spil.dk/*
// @match https://www.leitstellenspiel.de/*
// @match https://polizei.leitstellenspiel.de/*
// @match https://www.missionchief-australia.com/*
// @match https://police.missionchief-australia.com/*
// @match https://www.missionchief.co.uk/*
// @match https://police.missionchief.co.uk/*
// @match https://www.missionchief.com/*
// @match https://police.missionchief.com/*
// @match https://www.centro-de-mando.es/*
// @match https://www.centro-de-mando.mx/*
// @match https://www.hatakeskuspeli.com/*
// @match https://poliisi.hatakeskuspeli.com/*
// @match https://www.operateur112.fr/*
// @match https://police.operateur112.fr/*
// @match https://www.operatore112.it/*
// @match https://polizia.operatore112.it/*
// @match https://www.missionchief-japan.com/*
// @match https://www.missionchief-korea.com/*
// @match https://www.nodsentralspillet.com/*
// @match https://politiet.nodsentralspillet.com/*
// @match https://www.meldkamerspel.com/*
// @match https://politie.meldkamerspel.com/*
// @match https://www.operatorratunkowy.pl/*
// @match https://policja.operatorratunkowy.pl/*
// @match https://www.operador193.com/*
// @match https://www.jogo-operador112.com/*
// @match https://policia.jogo-operador112.com/*
// @match https://www.jocdispecerat112.com/*
// @match https://www.dispetcher112.ru/*
// @match https://www.dispecerske-centrum.com/*
// @match https://www.larmcentralen-spelet.se/*
// @match https://polis.larmcentralen-spelet.se/*
// @match https://www.112-merkez.com/*
// @match https://www.dyspetcher101-game.com/*
// @run-at document-idle
// ==/UserScript==
(() => {
let firstCheckbox = null;
const firstCheckboxParentClass = 'checkbox-multiselect-first-checkbox-parent';
const lastCheckboxClass = 'checkbox-multiselect-last-checkbox';
document.addEventListener('click', e => {
const target = e.target;
if (!target || !(target instanceof HTMLElement)) return;
const checkbox = target.closest('input[type="checkbox"]');
if (!checkbox) return (firstCheckbox = null);
if (!e.shiftKey || !firstCheckbox) return (firstCheckbox = checkbox);
let parentFirst = firstCheckbox.parentElement;
let prevParentFirst = firstCheckbox;
let parentLast = checkbox.parentElement;
const parentTags = [];
while (parentFirst && parentLast && parentFirst !== parentLast) {
const parentFirstTag = parentFirst.tagName;
const parentLastTag = parentLast.tagName;
if (parentFirstTag !== parentLastTag) parentTags.push([parentFirstTag, parentLastTag]);
else parentTags.push(parentFirstTag);
prevParentFirst = parentFirst;
parentFirst = parentFirst.parentElement;
parentLast = parentLast.parentElement;
}
if (!parentFirst) return;
prevParentFirst.classList.add(firstCheckboxParentClass);
checkbox.classList.add(lastCheckboxClass);
const querySelector = `:scope > .${firstCheckboxParentClass} ~ ${parentTags
.reverse()
.map(tag => (Array.isArray(tag) ? `:is(${tag.join(', ')})` : tag))
.join(' > ')} > input[type="checkbox"]:is(:not(:checked), .${lastCheckboxClass})`;
const checkboxes = parentFirst.querySelectorAll(querySelector);
for (const listCheckbox of checkboxes) {
if (listCheckbox.classList.contains(lastCheckboxClass)) break;
listCheckbox.click();
}
prevParentFirst.classList.remove(firstCheckboxParentClass);
checkbox.classList.remove(lastCheckboxClass);
firstCheckbox = checkbox;
});
})();