-
Notifications
You must be signed in to change notification settings - Fork 1
/
LSS_delete_multiple_aaos.user.js
84 lines (77 loc) · 3.48 KB
/
LSS_delete_multiple_aaos.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
// ==UserScript==
// @name LSS delete multiple AAOs
// @version 1.0
// @author Crazycake
// @include *.leitstellenspiel.de/aaos*
// @description Allows you to delete multiple AAOs at once
// @grant none
// ==/UserScript==
(function () {
'use strict';
sleep(100);
if (sessionStorage.getItem('LSS_crazycakeselectedAAOs') != null) {
deleteSelectedAAOs();
}
var crazycakeselectedAAOs = [];
$("#tutorial_video_show").parent().before('<div class="btn-group"><a href="#" class="btn btn-xs btn-danger" id="crazycakeDeleteSelectedAAOs">Ausgewählte AAOs löschen</a><a href="#" class="btn btn-xs btn-default" id="crazycakeToggleAAOs">AAOs auswählen</a></div>');
$('#crazycakeToggleAAOs').on('click', function () {
$(this).toggleClass('btn-default btn-success');
if ($(this).hasClass('btn-success')) {
deleteBtnDisable();
selectAAOs();
}
else {
deleteBtnEnable();
}
$('#crazycakeDeleteSelectedAAOs').on('click', function (event) {
event.preventDefault();
deleteSelectedAAOs();
})
function selectAAOs() {
$('a[href*="/aaos/"]').on('click', function (event) {
if ($(this).attr('href').search(/\d/) != -1) {
event.preventDefault();
if (!$(this).hasClass('crazycakeSelectedAAO')) {
$(this).addClass('crazycakeSelectedAAO');
$(this).before('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>');
$(this).prev().attr('id', 'crazycakeAAOId' + $(this).attr('href').split('/')[2]);
crazycakeselectedAAOs.push($(this).attr('href').split('/')[2]);
sessionStorage.setItem('LSS_crazycakeselectedAAOs', crazycakeselectedAAOs);
} else {
$(this).removeClass('crazycakeSelectedAAO');
$(this).prev().remove();
for (var i = 0; i < crazycakeselectedAAOs.length; i++) {
if (crazycakeselectedAAOs[i] === $(this).attr('href').split('/')[2]) {
crazycakeselectedAAOs.splice(i, 1);
}
}
sessionStorage.setItem('LSS_crazycakeselectedAAOs', crazycakeselectedAAOs);
}
}
})
}
function deleteBtnEnable() {
$('#crazycakeDeleteSelectedAAOs').removeClass('disabled');
}
function deleteBtnDisable() {
$('#crazycakeDeleteSelectedAAOs').addClass('disabled');
}
})
function deleteSelectedAAOs() {
let selectedAAOs = sessionStorage.getItem('LSS_crazycakeselectedAAOs');
var selectedAAOsArr = []
selectedAAOsArr = selectedAAOs.split(',');
var currentDeleteID = selectedAAOsArr.shift();
selectedAAOs = selectedAAOsArr.join();
sessionStorage.setItem('LSS_crazycakeselectedAAOs', selectedAAOs);
currentDeleteID = '/aaos/' + currentDeleteID;
$('a[href|="' + currentDeleteID + '"').click();
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
}());