initial commit
This commit is contained in:
commit
ef26eab330
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/data/
|
||||
.htaccess*
|
||||
BIN
OWE_Logo.png
Normal file
BIN
OWE_Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
19
archiv.php
Normal file
19
archiv.php
Normal file
@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OWE Archiv</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>One Word Each Archiv</h1>
|
||||
<p><a href="./">Startseite</a></p>
|
||||
<p class="sentences">
|
||||
<?php
|
||||
$filename = $_REQUEST["file"];
|
||||
|
||||
$content = file_get_contents("./data/".$filename) or die("ungültiger Dateiname");
|
||||
print($content);
|
||||
?>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
151
index.php
Normal file
151
index.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
function get_color_from_ip($ip) {
|
||||
$ip_elem = explode(".", $ip);
|
||||
$css = "background-color: hsl(";
|
||||
$number = abs(crc32($ip));
|
||||
$css .= ($number % 360).", ";
|
||||
$css .= (50 + (($number >> 3) % 51))."%, ";
|
||||
$css .= (50 + (($number >> 5) % 51))."%);";
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
//header("refresh: 28");
|
||||
header("Cache-Control: no-cache, no-store, must-revalidate");
|
||||
|
||||
if (array_key_exists("submitted", $_REQUEST)) {
|
||||
$word = urldecode($_REQUEST["submitted"]);
|
||||
//print("Jemand schreibt ".$word."<br>");
|
||||
$sentences = fopen("./data/sentences.txt", "a") or die("unable to open sentences file");
|
||||
$content = "<span style='";
|
||||
$content .= get_color_from_ip($_SERVER['REMOTE_ADDR'])."'>";
|
||||
|
||||
$ends_of_sentence = ['.', '!', '?'];
|
||||
if (preg_match("/\p{L}/", $word[0])) { // check if first character is letter (including ä, ê, ß stuff)
|
||||
$content .= " ";
|
||||
}
|
||||
$content .= htmlentities($word);
|
||||
|
||||
$content .= "</span>";
|
||||
|
||||
if (in_array($word[-1], $ends_of_sentence)) {
|
||||
$content .= "<br>\n";
|
||||
}
|
||||
|
||||
fwrite($sentences, $content);
|
||||
fclose($sentences);
|
||||
header("location: ".htmlentities($_SERVER['PHP_SELF']));
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>One Word Each</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td width="50%"><img src="OWE_Logo.png" width="90%"></td>
|
||||
<td><h1>One Word Each Seite</h1></td>
|
||||
</tr>
|
||||
<table>
|
||||
|
||||
<p>
|
||||
<a href="./archiv.php?file=sentences-archive-30-mar-20.txt">Archiveintrag 30. März 2020</a><br>
|
||||
<a href="./archiv.php?file=sentences-archive-31-mar-9-apr-20.txt">Archiveintrag 31. März bis 9. April 2020</a><br>
|
||||
<a href="./archiv.php?file=sentences-archive-9-28-apr-20.txt">Archiveintrag 9. bis 28. April 2020</a>
|
||||
</p>
|
||||
|
||||
<p class="sentences">
|
||||
<?php
|
||||
//print(file_get_contents("./data/sentences.txt"));
|
||||
?>
|
||||
</p>
|
||||
<button onclick="onReloadClicked()" id="but-reload">aktualisieren</button>
|
||||
<br><br>
|
||||
<form action="./#wordform" method="post" autocomplete="off" id="wordform">
|
||||
<table>
|
||||
<tr> <td>Nächstes Wort:</td> <td><input type="text" name="submitted"></td> </tr>
|
||||
<tr> <td></td> <td><input type="submit" value="senden"></td> </tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
var previousTextLength;
|
||||
|
||||
function loadSentences(alertIfNew = false) {
|
||||
fetch("./data/sentences.txt", {headers: {"Cache-Control": "no-cache, no-store"}})
|
||||
.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);
|
||||
}
|
||||
}
|
||||
previousTextLength = text.length;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onReloadClicked() {
|
||||
loadSentences();
|
||||
document.querySelector("#but-reload").style.visibility = "hidden";
|
||||
setTimeout(function(){
|
||||
document.querySelector("#but-reload").style.visibility = "initial";
|
||||
}, 100);
|
||||
}
|
||||
|
||||
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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//setTimeout(loadSentences, 500);
|
||||
loadSentences();
|
||||
setInterval(loadSentences, 5000, true);
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('./service-worker.js')
|
||||
.then(function(registration) {
|
||||
console.log('Registration successful, scope is:', registration.scope);
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log('Service worker registration failed, error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
navigator.serviceWorker.register('./service-worker.js', {
|
||||
scope: './'
|
||||
});
|
||||
|
||||
navigator.serviceWorker.register('./service-worker.js', {
|
||||
scope: '.'
|
||||
});
|
||||
|
||||
Notification.requestPermission(function(status) {
|
||||
console.log('Notification permission status:', status);
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
4
service-worker.js
Normal file
4
service-worker.js
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
self.addEventListener('install', function(event) {});
|
||||
|
||||
self.addEventListener('activate', function(event) {});
|
||||
24
style.css
Normal file
24
style.css
Normal file
@ -0,0 +1,24 @@
|
||||
body, input, button {
|
||||
width: auto;
|
||||
font-size: xx-large;
|
||||
background-color: black;
|
||||
color: white;
|
||||
font-family: "Courier New", Courier, monospace;
|
||||
}
|
||||
|
||||
input, button {
|
||||
border: 2px solid white;
|
||||
padding: 0px 5px 0px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: royalblue;
|
||||
}
|
||||
|
||||
.sentences {
|
||||
color: black;
|
||||
}
|
||||
|
||||
table {
|
||||
font-size: inherit;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user