forked from jxn-30/LSS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra-alarm-and-close-btn.user.js
38 lines (32 loc) · 1.63 KB
/
extra-alarm-and-close-btn.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
// ==UserScript==
// @name LSS – extra alarm & close button
// @namespace https://jxn.lss-manager.de
// @version 1.0.0
// @description adds an extra button for closing the alarm window after alarming
// @author jxn_30
// @match https://www.leitstellenspiel.de/missions/*
// @grant none
// @run-at document-start
// ==/UserScript==
const adjustCloseSetting = async (close = true) => {
const settings = await fetch('/api/settings').then(res => res.json());
const formData = new FormData();
Object.entries(settings).forEach(([key, value]) => formData.append(`user[${key}]`, key === 'mission_alarmed_successfull_close_window' ? +close : typeof value === 'boolean' ? +value : value));
formData.append('utf8', '✓');
formData.append('_method', 'put');
formData.append('authenticity_token', document.querySelector('[name="csrf-token"]')?.getAttribute('content') ?? '');
fetch('/einstellungen', {
"body": formData,
"method": "POST",
"mode": "cors"
});
}
if (document.location.pathname === '/missions/close') window.parent.eval(`(${adjustCloseSetting.toString()})(false)`);
const alarmAndCloseBtn = document.createElement('button');
alarmAndCloseBtn.classList.add('btn', 'btn-success', 'navbar-btn', 'btn-sm');
alarmAndCloseBtn.textContent = 'Alarmieren & Schließen';
alarmAndCloseBtn.addEventListener('click', async e => {
e.preventDefault();
adjustCloseSetting().then(() => document.getElementById('mission_alarm_btn')?.click());
});
document.addEventListener('DOMContentLoaded', () => document.getElementById('mission_alarm_btn')?.after(alarmAndCloseBtn));