aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials/js.html
diff options
context:
space:
mode:
authorMantas <mistermantas@users.noreply.github.com>2017-11-25 12:05:33 +0200
committerMantas <mistermantas@users.noreply.github.com>2017-11-25 12:05:33 +0200
commit3208df6352c0e05208bce95f8d9e9f16769a57ed (patch)
tree6d784f09fa6dc7d85438ca1086e32ba363d90483 /layouts/partials/js.html
parent4bc818712d9b0133dd22326052a99ef1f36f4aa0 (diff)
cState goes stable 1.0; fix #4 & fix #5
Diffstat (limited to 'layouts/partials/js.html')
-rw-r--r--layouts/partials/js.html62
1 files changed, 62 insertions, 0 deletions
diff --git a/layouts/partials/js.html b/layouts/partials/js.html
new file mode 100644
index 0000000..9ef2a23
--- /dev/null
+++ b/layouts/partials/js.html
@@ -0,0 +1,62 @@
+<script type="javascript">
+ /**
+ * Dev toolset
+ */
+
+ console.log('Welcome to cState! https://github.com/mistermantas/cstate');
+ document.querySelector('html').className = 'js';
+
+
+ /**
+ * Make theme color pretty
+ */
+
+ if (document.body.className === 'status-down') {
+ document.querySelector('meta[name=theme-color]').setAttribute('content', themeDownColor);
+ } else if (document.body.className === 'status-disrupted') {
+ document.querySelector('meta[name=theme-color]').setAttribute('content', themeDisruptedColor);
+ } else {
+ document.querySelector('meta[name=theme-color]').setAttribute('content', themeNoticeColor);
+ }
+
+
+ /**
+ * Check for internet
+ */
+
+ var lastUpdated = document.querySelector('.summary__date');
+ var lastUpdate = new Date();
+
+ function timeSince(date) {
+ var seconds = Math.floor((new Date() - date) / 1000);
+
+ var interval = Math.floor(seconds / 31536000);
+
+ if (interval > 1) {
+ return interval + ' years';
+ }
+ interval = Math.floor(seconds / 2592000);
+ if (interval > 1) {
+ return interval + ' months';
+ }
+ interval = Math.floor(seconds / 86400);
+ if (interval > 1) {
+ return interval + 'd';
+ }
+ interval = Math.floor(seconds / 3600);
+ if (interval > 1) {
+ return interval + 'h';
+ }
+ interval = Math.floor(seconds / 60);
+ if (interval > 1) {
+ return interval + 'min';
+ }
+ return Math.floor(seconds) + 's';
+ }
+ var aDay = 24*60*60*1000;
+
+ // Show second by second updates
+ window.setInterval(function() {
+ lastUpdated.innerHTML = 'Last checked ' + timeSince(lastUpdate) + ' ago';
+ }, 1000);
+</script>