initial commit

This commit is contained in:
Bence Pőcze 2020-07-12 19:07:42 +02:00
commit d1d384bce8
Signed by: bence
GPG Key ID: AA52B11A3269D1C1
6 changed files with 200 additions and 0 deletions

5
getTime.php Normal file
View File

@ -0,0 +1,5 @@
<?php
header('Content-Type: text/plain');
echo round(microtime(true) * 1000);

47
index.php Normal file
View File

@ -0,0 +1,47 @@
<?php
if (!isset($_SERVER['STATIC_ROOT'])) {
$_SERVER['STATIC_ROOT'] = '/static/';
}
?>
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="utf-8" />
<meta name="description" content="A pontos idő megjelenítése." />
<meta name="author" content="&copy; Pőcze Bence. 2015" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pontos idő</title>
<?php if (preg_match('/^(http(s)?:)?\/\//', $_SERVER['STATIC_ROOT']) === 1): ?>
<link href="<?= $_SERVER['STATIC_ROOT'] ?>" rel="preconnect">
<?php endif; ?>
<link href="https://fonts.gstatic.com" rel="preconnect">
<?php if (!empty($_SERVER['GOOGLE_ANALITICS_ID'])): ?>
<link href="https://www.googletagmanager.com" rel="preconnect">
<link href="https://www.google-analytics.com" rel="preconnect">
<?php endif; ?>
<link href="https://fonts.googleapis.com/css2?family=Cousine:wght@400;700&amp;family=Oxygen:wght@400;700&amp;display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= $_SERVER['STATIC_ROOT'] ?>time.css" />
<link rel="icon" href="<?= $_SERVER['STATIC_ROOT'] ?>time.png" />
</head>
<body>
<main>
<h1>Pontos idő</h1>
<p class="date"><span id="year">...</span>. <span id="month">...</span> <span id="date">...</span>., <span id="day">...</span></p>
<p class="time"><span id="time">..:..:..</span></p>
<p id="correct">Az eszköz órájának eltérése: <span class="correct"><span id="correct_seconds">...</span> másodperc</span></p>
</main>
<script async src="<?= $_SERVER['STATIC_ROOT'] ?>time.js"></script>
<?php if (!empty($_SERVER['GOOGLE_ANALITICS_ID'])): ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= $_SERVER['GOOGLE_ANALITICS_ID'] ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '<?= $_SERVER['GOOGLE_ANALITICS_ID'] ?>');
</script>
<?php endif; ?>
</body>
</html>

2
robots.txt Normal file
View File

@ -0,0 +1,2 @@
User-agent: *
Allow: /

71
static/time.css Normal file
View File

@ -0,0 +1,71 @@
* {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
vertical-align: baseline;
}
body {
background-color: #eee;
font-family: 'Oxygen', sans-serif;
}
main {
display: block;
background-color: #fff;
border-radius: 15px;
width: 600px;
margin: 50px auto;
padding: 25px 25px 25px;
text-align: center;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
h1 {
font-size: 35px;
font-weight: normal;
}
p {
margin-top: 12px;
font-size: 15px;
line-height: 125%;
}
p.date {
font-size: 30px;
font-weight: bold;
}
p.time {
font-family: 'Cousine', monospace;;
font-size: 50px;
font-weight: bold;
}
span.correct {
font-weight: bold;
}
hr {
background-color: #ccc;
height: 3px;
margin: 20px 0;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
main {
border-radius: 0;
width: auto;
margin: 0 auto;
padding: 10px 10px 10px;
}
}

75
static/time.js Normal file
View File

@ -0,0 +1,75 @@
(function () {
var _MONTHS_ = ['január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december'];
var _DAYS_ = ['vasárnap', 'hétfő', 'kedd', 'szerda', 'csütörtök', 'péntek', 'szombat'];
var syncTimeout;
var clockTimeout;
var correct = 0;
function getSyncedDateTime() {
return new Date(new Date().getTime() - correct);
}
function fillZero(param) {
return param < 10 ? '0' + String(param) : String(param);
}
function sync() {
clearTimeout(syncTimeout);
var started;
var latency;
var syncRequest = new XMLHttpRequest();
syncRequest.onreadystatechange = function () {
switch (syncRequest.readyState) {
case XMLHttpRequest.OPENED:
started = new Date().getTime();
break;
case XMLHttpRequest.HEADERS_RECEIVED:
latency = (new Date().getTime() - started) / 2;
break;
case XMLHttpRequest.DONE:
correct = new Date().getTime() - (parseInt(syncRequest.responseText) + latency);
syncTimeout = setTimeout(sync, 10000);
break;
}
}
syncRequest.open('GET', 'getTime.php', true);
syncRequest.send();
}
function clock() {
var dateTime = getSyncedDateTime();
document.getElementById('year').innerHTML = dateTime.getFullYear();
document.getElementById('month').innerHTML = _MONTHS_[dateTime.getMonth()];
document.getElementById('date').innerHTML = dateTime.getDate();
document.getElementById('day').innerHTML = _DAYS_[dateTime.getDay()];
document.getElementById('time').innerHTML = fillZero(dateTime.getHours()) + ':' + fillZero(dateTime.getMinutes()) + ':' + fillZero(dateTime.getSeconds());
if (Math.abs(correct) < 100) {
document.getElementById('correct').style.display = 'none';
} else {
document.getElementById('correct').style.display = 'block';
document.getElementById('correct_seconds').innerHTML = (correct > 0 ? '+' : '') + (correct / 1000).toFixed(1);
}
clockTimeout = setTimeout(clock, 100);
}
document.getElementsByTagName('main')[0].ondblclick = function () {
sync();
}
clock();
sync();
})();

BIN
static/time.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B