notification update
This commit is contained in:
parent
1e575c3a7f
commit
baf0c2e887
47
index.php
47
index.php
@ -82,6 +82,8 @@ $config_data = json_decode($raw_json_config, false);
|
||||
|
||||
<script>
|
||||
var previousTextLength;
|
||||
var config_data;
|
||||
var unread_words = 0;
|
||||
|
||||
document.getElementById("wordinput").focus();
|
||||
|
||||
@ -90,19 +92,22 @@ $config_data = json_decode($raw_json_config, false);
|
||||
.then((response) => {
|
||||
return response.text().then((text) => {
|
||||
document.querySelector(".sentences").innerHTML = text;
|
||||
if (alertIfNew && text.length > previousTextLength) {
|
||||
var newtxt = text.substring(previousTextLength, text.length);
|
||||
//var parser = new DOMParser();
|
||||
//var xmltxt = parser.parseFromString(newtxt, "text/xml");
|
||||
//var newword = xmltxt.getElementsByTagName("span")[0].innerHTML.trim();
|
||||
var htmltxt = document.createElement("html");
|
||||
htmltxt.innerHTML = newtxt;
|
||||
var newword = htmltxt.getElementsByTagName("span")[0].innerHTML.trim();
|
||||
if (Notification.permission == 'granted') {
|
||||
displayNotification(newword);
|
||||
}
|
||||
else {
|
||||
alert("Neues Wort: " + newword);
|
||||
if (text.length > previousTextLength) {
|
||||
document.getElementsByTagName("title")[0].innerText = (config_data.title ? config_data.title : "One Word Each") + " (" + ++unread_words + ")";
|
||||
if (alertIfNew) {
|
||||
var newtxt = text.substring(previousTextLength, text.length);
|
||||
//var parser = new DOMParser();
|
||||
//var xmltxt = parser.parseFromString(newtxt, "text/xml");
|
||||
//var newword = xmltxt.getElementsByTagName("span")[0].innerHTML.trim();
|
||||
var htmltxt = document.createElement("html");
|
||||
htmltxt.innerHTML = newtxt;
|
||||
var newword = htmltxt.getElementsByTagName("span")[0].innerHTML.trim();
|
||||
if (Notification.permission == 'granted') {
|
||||
displayNotification(newword);
|
||||
}
|
||||
else {
|
||||
alert("Neues Wort: " + newword);
|
||||
}
|
||||
}
|
||||
}
|
||||
previousTextLength = text.length;
|
||||
@ -117,6 +122,14 @@ $config_data = json_decode($raw_json_config, false);
|
||||
});
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
fetch("./data/config.json").then((response) => {
|
||||
return response.text().then((text) => {
|
||||
config_data = JSON.parse(text);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onReloadClicked() {
|
||||
loadSentences();
|
||||
document.querySelector("#but-reload").style.visibility = "hidden";
|
||||
@ -128,13 +141,19 @@ $config_data = json_decode($raw_json_config, false);
|
||||
function displayNotification(word) {
|
||||
if (Notification.permission == 'granted') {
|
||||
navigator.serviceWorker.getRegistration().then(function(reg) {
|
||||
reg.showNotification("Neues Wort auf OWE", { body: word, icon: "OWE_Logo.png", requireInteraction: true });
|
||||
reg.showNotification("Neues Wort auf " + (config_data.title ? config_data.title : "OWE"),
|
||||
{ body: word, icon: config_data.logo.image_path ? config_data.logo.image_path : "OWE_Logo.png", requireInteraction: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.onfocus = function() {
|
||||
unread_words = 0;
|
||||
document.getElementsByTagName("title")[0].innerText = (config_data.title ? config_data.title : "One Word Each");
|
||||
}
|
||||
|
||||
//setTimeout(loadSentences, 500);
|
||||
loadConfig();
|
||||
loadSentences();
|
||||
setInterval(loadSentences, 5000, true);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user