-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.js
92 lines (83 loc) · 6.37 KB
/
alarm.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
var alarm;
var enabled = false;
var long;
var currentValue;
var headlineElement, currentValueElement;
var wkn;
var beep = new Audio("data:audio/mpeg;base64,SUQzBAAAAAAATlREUkMAAAAMAAADMjAxMy0xMC0yOABURU5DAAAACwAAA1BybyBUb29scwBUU1NFAAAADwAAA0xhdmY1OC4yOS4xMDAAAAAAAAAAAAAAAP/7UMAAAAAAAAAAAAAAAAAAAAAAAEluZm8AAAAPAAAACwAACcoAKioqKioqKioqPz8/Pz8/Pz8/VVVVVVVVVVVVampqampqampqf39/f39/f39/lZWVlZWVlZWVqqqqqqqqqqqqv7+/v7+/v7+/1dXV1dXV1dXV6urq6urq6urq////////////AAAAAExhdmM1OC41NAAAAAAAAAAAAAAAACQGWwAAAAAAAAnKLCipLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/+1DEAAAKEEcqVb0AAYSQafc3gAIBkAQDoBy75ZcwEBAQGj+XnMTGzNCgaJTIUk2l/ONkTi382tTM1DwsJG7gnDdmtPmTDlv11w/G43DkYjEYjEYpMCgYLg+fE4P5d5QEIIZ/4fsjbADbtsk1tAgAAAAAMGNjKyMiCS3DeIBzBy4yZZuFlaIaCzgm4HBxxJ+xw4wKaGc/Ao0rlcbhAhKX+XnG6WK0eEagV9X5mv/X/+/lq0nOdqX/3//+f+oZ7S0FKc+kRNDSACroQAAozYkr//tSxASCS7B3Iv3sAAFADuONr2lASS1oGAOMAkBIoASAwDRgBgHGBSCIYb4qxjOkZHHWoQaAgoI8CiMAMGB+B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wMEDCAwoYKGBggYQGDDBQQMEHCAwYIKCBhA6F6abf////9VVqaaaKqqqrf/0VVVVU0000VTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxGkDyayygiMEbwgAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVU=");
var infoHtml = `
<div style="display: inline">
Kursalarm bei: <input id="alarm" oninput="onInput()" type="number" step="any" style="margin-right: 5px; display: inline">
<button style="display: inline" id="saveAlarm" onclick="updateAlarm()">Speichern</button>
<span id="check" style="margin-left: 5px;">✓</span>
</div>
`;
function initialize() {
let wknElement = document.querySelector(".seo-info > span:nth-child(2) > span > span");
headlineElement = document.querySelector(".instrument-title");
currentValueElement = document.querySelector(".chart-view .price .instrument-value");
if (wknElement == null || headlineElement == null || currentValueElement == null) {
alert("Die Struktur der Seite hat sich geändert. Möglicherweise funktionieren Kursalarme nicht ordnungsgemäß. Bitte warten Sie auf ein Update.")
}
wkn = wknElement.innerText;
headlineElement.style.display = 'inline';
headlineElement.insertAdjacentHTML("afterend", infoHtml);
if (Notification.permission === "default") {
Notification.requestPermission().then(function(permission) {
if (permission === "denied") {
alert("Sie müssen Benachrichtungen für diese Webseite erlauben, damit Ihnen der Kursalarm angezeigt werden kann.")
}
});
}
loadAlarm();
}
function updateAlarm() {
alarm = parseFloat(document.getElementById("alarm").value.replace(",", "."));
persistAlarm();
document.getElementById("saveAlarm").style.display = "none";
document.getElementById("check").style.display = "";
long = alarm > currentValue;
if (!enabled) {
setTimeout(checkAlarm, 1000);
enabled = true;
}
}
function onInput() {
document.getElementById("saveAlarm").style.display = "inline";
document.getElementById("check").style.display = "none";
}
function loadAlarm() {
alarm = localStorage.getItem(wkn);
if (alarm != null) {
document.getElementById("alarm").value = alarm;
updateAlarm();
}
}
function persistAlarm() {
localStorage.setItem(wkn, alarm);
}
function checkAlarm() {
currentValue = parseFloat(currentValueElement.innerText.replace(".", "").replace(",","."));
if (enabled) {
if (long && currentValue >= alarm) {
triggerAlarm();
enabled = false;
} else if (!long && currentValue <= alarm) {
triggerAlarm();
enabled = false;
} else {
setTimeout(checkAlarm, 1000);
}
}
}
function triggerAlarm() {
beep.play();
if (Notification.permission === "granted") {
new Notification(`Alarm - ${headlineElement.innerText}`, {
requireInteraction: true,
body: `Kurs hat ${alarm} erreicht.`,
icon: long ? "https://rawcdn.githack.com/T3rm1/godmodetrader-alarm/fc0223bee7da5c5b123458a20c95ad69cdd8d157/icons/long.png" : "https://rawcdn.githack.com/T3rm1/godmodetrader-alarm/fc0223bee7da5c5b123458a20c95ad69cdd8d157/icons/short.png"
});
}
}
initialize();