forked from diogocampos/year-progress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
progress.html
71 lines (62 loc) · 2.19 KB
/
progress.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes">
<script>
const UPDATES_PER_SECOND = 30;
document.addEventListener('DOMContentLoaded', function () {
"use strict";
var $title = $('#title');
var $bar = $('#progress-bar');
var $percentage = $('#progress-percentage');
setInterval(function () {
"use strict";
var percentage = getProgress('startdate','enddate');
$title.innerText = GetURLParameter('title');
document.title = GetURLParameter('title');
$bar.style.setProperty('width', "".concat(percentage, "%"));
$percentage.innerText = percentage.toFixed(10);
}, 1000 / UPDATES_PER_SECOND);
});
// Helpers
var $ = function $(selector) {
"use strict";
return document.querySelector(selector);
};
function getProgress(startdateparam, enddateparam) {
"use strict";
var startdate = parsedate(GetURLParameter(startdateparam));
var enddate = parsedate(GetURLParameter(enddateparam));
var percentage = 100 * ((Date.now() - startdate) / (enddate - startdate));
return percentage;
};
function parsedate(yyyydashmmdashdd) {
"use strict";
var parseddate = new Date(yyyydashmmdashdd);
return parseddate;
};
function GetURLParameter(sParam) {
"use strict";
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1].replace("%20"," ");
};
};
};
</script>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h1 id="title"></h1>
<div class="progress-bar-container">
<div id="progress-bar"></div>
</div>
<h2><span id="progress-percentage"></span>%</h2>
</body>
</html>