notification update
This commit is contained in:
parent
1e575c3a7f
commit
baf0c2e887
23
index.php
23
index.php
@ -82,6 +82,8 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
var previousTextLength;
|
var previousTextLength;
|
||||||
|
var config_data;
|
||||||
|
var unread_words = 0;
|
||||||
|
|
||||||
document.getElementById("wordinput").focus();
|
document.getElementById("wordinput").focus();
|
||||||
|
|
||||||
@ -90,7 +92,9 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.text().then((text) => {
|
return response.text().then((text) => {
|
||||||
document.querySelector(".sentences").innerHTML = text;
|
document.querySelector(".sentences").innerHTML = text;
|
||||||
if (alertIfNew && text.length > previousTextLength) {
|
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 newtxt = text.substring(previousTextLength, text.length);
|
||||||
//var parser = new DOMParser();
|
//var parser = new DOMParser();
|
||||||
//var xmltxt = parser.parseFromString(newtxt, "text/xml");
|
//var xmltxt = parser.parseFromString(newtxt, "text/xml");
|
||||||
@ -105,6 +109,7 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
alert("Neues Wort: " + newword);
|
alert("Neues Wort: " + newword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
previousTextLength = text.length;
|
previousTextLength = text.length;
|
||||||
|
|
||||||
// color
|
// color
|
||||||
@ -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() {
|
function onReloadClicked() {
|
||||||
loadSentences();
|
loadSentences();
|
||||||
document.querySelector("#but-reload").style.visibility = "hidden";
|
document.querySelector("#but-reload").style.visibility = "hidden";
|
||||||
@ -128,13 +141,19 @@ $config_data = json_decode($raw_json_config, false);
|
|||||||
function displayNotification(word) {
|
function displayNotification(word) {
|
||||||
if (Notification.permission == 'granted') {
|
if (Notification.permission == 'granted') {
|
||||||
navigator.serviceWorker.getRegistration().then(function(reg) {
|
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);
|
//setTimeout(loadSentences, 500);
|
||||||
|
loadConfig();
|
||||||
loadSentences();
|
loadSentences();
|
||||||
setInterval(loadSentences, 5000, true);
|
setInterval(loadSentences, 5000, true);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user