-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessage-templates.user.js
97 lines (94 loc) · 4.58 KB
/
message-templates.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
// ==UserScript==
// @name LSS-Message-Templates
// @version 1.0.3
// @description Add multiple Templates for private messages
// @author Jan (jxn_30)
// @match https://www.operacni-stredisko.cz/messages/new
// @match https://policie.operacni-stredisko.cz/messages/new
// @match https://www.alarmcentral-spil.dk/messages/new
// @match https://politi.alarmcentral-spil.dk/messages/new
// @match https://www.leitstellenspiel.de/messages/new
// @match https://polizei.leitstellenspiel.de/messages/new
// @match https://www.missionchief-australia.com/messages/new
// @match https://police.missionchief-australia.com/messages/new
// @match https://www.missionchief.co.uk/messages/new
// @match https://police.missionchief.co.uk/messages/new
// @match https://www.missionchief.com/messages/new
// @match https://police.missionchief.com/messages/new
// @match https://www.centro-de-mando.es/messages/new
// @match https://www.centro-de-mando.mx/messages/new
// @match https://www.hatakeskuspeli.com/messages/new
// @match https://poliisi.hatakeskuspeli.com/messages/new
// @match https://www.operateur112.fr/messages/new
// @match https://police.operateur112.fr/messages/new
// @match https://www.operatore112.it/messages/new
// @match https://polizia.operatore112.it/messages/new
// @match https://www.missionchief-japan.com/messages/new
// @match https://www.missionchief-korea.com/messages/new
// @match https://www.nodsentralspillet.com/messages/new
// @match https://politiet.nodsentralspillet.com/messages/new
// @match https://www.meldkamerspel.com/messages/new
// @match https://politie.meldkamerspel.com/messages/new
// @match https://www.operatorratunkowy.pl/messages/new
// @match https://policja.operatorratunkowy.pl/messages/new
// @match https://www.operador193.com/messages/new
// @match https://www.jogo-operador112.com/messages/new
// @match https://policia.jogo-operador112.com/messages/new
// @match https://www.jocdispecerat112.com/messages/new
// @match https://www.dispetcher112.ru/messages/new
// @match https://www.dispecerske-centrum.com/messages/new
// @match https://www.larmcentralen-spelet.se/messages/new
// @match https://polis.larmcentralen-spelet.se/messages/new
// @match https://www.112-merkez.com/messages/new
// @match https://www.dyspetcher101-game.com/messages/new
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
const messages = [
{
title: "Das ist ein Beispiel-Template",
body:
`Diese Nachricht wurde mit einem automatischen Template eingefügt!
Auch Zeilenumbrüche funktionieren natürlich reibungslos!
=> Selbstverständlich werden auch Einrückungen berücksichtigt ;)`,
},
{
title: "Noch ein zweites Template",
body:
`Das dient einfach nur der Demonstration!`,
},
];
const group = document.createElement('div');
group.classList.add('btn-group', 'pull-right');
const insert = document.createElement('button');
insert.classList.add('btn', 'btn-default', 'dropdown-toggle');
insert.setAttribute('data-toggle', 'dropdown');
insert.innerHTML = 'Template einfügen <span class="caret"></span>';
const optionList = document.createElement('ul');
optionList.classList.add('dropdown-menu');
messages.forEach(({title, body}) => {
const liEl = document.createElement('li');
const aEl = document.createElement('a');
aEl.textContent = title;
aEl.onclick = () => {
const titleEl = document.getElementById('message_subject');
if (titleEl) titleEl.value = title;
const bodyEl = document.getElementById('message_body');
if (bodyEl) bodyEl.value = body.replace(
/{{username}}/g,
document
.querySelector('#message_recipients')
?.value?.trim() ?? '{{username}}'
).replace(
/{{today(?<offset>[+-]\d+)?}}/g,
(_, offsetString) =>
new Date(Date.now() + parseInt(offsetString ?? '0') * 1000 * 60 * 60 * 24).toLocaleDateString('de-DE', {dateStyle: "short"})
);
};
liEl.append(aEl);
optionList.append(liEl);
});
group.append(insert, optionList);
document.querySelector('.page-header').append(group);
})();