Skip to content

Instantly share code, notes, and snippets.

@mugli
Last active February 27, 2021 16:31
Show Gist options
  • Save mugli/d6c6132a79e9545419cf8c6ada42e03a to your computer and use it in GitHub Desktop.
Save mugli/d6c6132a79e9545419cf8c6ada42e03a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Termin Notifier
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://service.berlin.de/terminvereinbarung/*
// @icon https://www.google.com/s2/favicons?domain=berlin.de
// @grant none
// ==/UserScript==
(function () {
"use strict";
function addElement(type, value) {
const element = document.createElement("input");
element.type = type;
element.value = value;
element.name = type;
element.style = "color: red;"
element.onclick = function () {
notifyMe();
};
const parent = document.getElementById("layout-grid__area--contentheader");
parent.appendChild(element);
}
function notifyMe() {
if (!window.Notification) {
console.log("Browser does not support notifications.");
} else {
if (Notification.permission === "granted") {
const notify = new Notification("Hi there!", {
body: "Termin available!"
});
} else {
Notification.requestPermission()
.then(function (p) {
if (p === "granted") {
const notify = new Notification("Hi there!", {
body: "Termin available!"
});
} else {
console.log("User blocked notifications.");
}
})
.catch(function (err) {
console.error(err);
});
}
}
}
const sleep = t => new Promise(s => setTimeout(s, t));
async function repeatNotification() {
for (let i = 0; i <= 15; i++) {
notifyMe();
await sleep(1500);
}
}
// Your code here...
addElement("button", "------ >>>>>>>> Click here to set notification permission! <<<<<<<<<< ------");
const nodes = document.querySelectorAll(
'a[title="An diesem Tag einen Termin buchen"]'
);
console.log(new Date(), nodes)
if (nodes.length) {
for (const node of nodes) {
const day = node.textContent * 1
if (day < 15) {
repeatNotification();
break;
} else {
console.log("Skipping notification for termin on ", day)
}
}
} else {
console.log('No termin :( :( :(. Refresh the page again sometime later.')
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment