Compare commits

...

2 Commits

2 changed files with 17 additions and 5 deletions

View File

@ -95,7 +95,10 @@ $config_data = json_decode($raw_json_config, false);
<div class="header"> <div class="header">
<img src="<?php print($config_data->logo->image_path ?? "OWE_Logo.png"); ?>" style="width: 10%; float: left;"> <img src="<?php print($config_data->logo->image_path ?? "OWE_Logo.png"); ?>" style="width: 10%; float: left;">
<h3 style="padding: 30px;"><?php print($config_data->headline ?? "One Word Each Seite"); ?></h3> <h3 style="padding: 30px;"><?php print($config_data->headline ?? "One Word Each Seite"); ?></h3>
<button onclick="toggleArchives();" id="sidebar_button"><i class="fas fa-bars"></i></button> <button onclick="toggleArchives();" id="sidebar_button">
<?php
print(isset($config_data->archive) ? ("<img id='archive_image' src='".$config_data->archive->logo_path_closed."' width='64'>") : "<i class='fas fa-bars'></i>");
?></button>
</div> </div>
<div class="content"> <div class="content">

17
owe.js
View File

@ -2,13 +2,15 @@ var previousTextLength;
var config_data; var config_data;
var unread_words = 0; var unread_words = 0;
function loadSentences(alertIfNew = false) { function loadSentences(alertIfNew = false, increaseUnread = true) {
fetch("./data/sentences.txt", {headers: {"Cache-Control": "no-cache, no-store"}}) fetch("./data/sentences.txt", {headers: {"Cache-Control": "no-cache, no-store"}})
.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 (text.length > previousTextLength) { if (text.length > previousTextLength) {
document.getElementsByTagName("title")[0].innerText = (config_data.title ? config_data.title : "One Word Each") + " (" + ++unread_words + ")"; if (increaseUnread) {
document.getElementsByTagName("title")[0].innerText = "(" + ++unread_words + ") " + (config_data.title ? config_data.title : "One Word Each") ;
}
if (alertIfNew) { if (alertIfNew) {
var newtxt = text.substring(previousTextLength, text.length); var newtxt = text.substring(previousTextLength, text.length);
//var parser = new DOMParser(); //var parser = new DOMParser();
@ -41,6 +43,7 @@ function loadConfig() {
fetch("./data/config.json").then((response) => { fetch("./data/config.json").then((response) => {
return response.text().then((text) => { return response.text().then((text) => {
config_data = JSON.parse(text); config_data = JSON.parse(text);
setInterval(loadSentences, 5000, ((typeof config_data.notifications !== "undefined") ? config_data.notifications : true));
}); });
}).catch(() => { }).catch(() => {
config_data = Object(); // leave empty config_data = Object(); // leave empty
@ -62,7 +65,8 @@ function sendWord() {
Http.open('POST', '.'); Http.open('POST', '.');
Http.onreadystatechange=(e)=>{ Http.onreadystatechange=(e)=>{
document.getElementById("wordinput").value = ""; document.getElementById("wordinput").value = "";
loadSentences(); loadSentences(false, false);
resetUnread();
} }
Http.send(data); Http.send(data);
} }
@ -81,9 +85,15 @@ function toggleArchives() {
if (archives.style.display == "none") { if (archives.style.display == "none") {
archives.style.display = "flex"; archives.style.display = "flex";
if (config_data.archive) {
document.getElementById("archive_image").src = config_data.archive.logo_path_open
}
return; return;
} }
archives.style.display = "none"; archives.style.display = "none";
if (config_data.archive) {
document.getElementById("archive_image").src = config_data.archive.logo_path_closed
}
} }
function resetUnread() { function resetUnread() {
@ -96,7 +106,6 @@ window.onfocus = resetUnread;
//setTimeout(loadSentences, 500); //setTimeout(loadSentences, 500);
loadConfig(); loadConfig();
loadSentences(); loadSentences();
setInterval(loadSentences, 5000, true);
var input = document.getElementById("wordinput"); var input = document.getElementById("wordinput");
input.focus(); input.focus();