Skip to content

Commit

Permalink
Add feature to disable live updates.
Browse files Browse the repository at this point in the history
Fixes #31.
  • Loading branch information
roncli committed Feb 20, 2020
1 parent 28b585d commit e30c456
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
6 changes: 6 additions & 0 deletions public/css/game.css
Expand Up @@ -138,3 +138,9 @@
text-align: right;
font-variant-numeric: tabular-nums;
}

.live-updates {
float: right;
color: #ff6600;
padding-right: 10px;
}
6 changes: 6 additions & 0 deletions public/css/home.css
Expand Up @@ -61,3 +61,9 @@
#browser .old {
color: #999999;
}

.live-updates {
float: right;
color: #ff6600;
padding-right: 10px;
}
9 changes: 8 additions & 1 deletion public/js/common/common.js
Expand Up @@ -171,7 +171,14 @@ class Common {
const els = document.querySelectorAll(".timeago");

if (els.length > 0) {
timeago.render(els);
if (window.live) {
timeago.render(els);
} else {
els.forEach((el) => {
el.innerText = timeago.format(el.attributes.datetime.value);
el.classList.remove("timeago");
});
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions public/js/game.js
Expand Up @@ -24,9 +24,18 @@ class GameJs {
static DOMContentLoaded() {
Common.loadTimeAgo();

GameJs.ws = new WebSocketClient();
GameJs.ws.onmessage = GameJs.onmessage;
GameJs.ws.open((window.location.protocol === "http:" ? "ws:" : window.location.protocol === "https:" ? "wss:" : window.location.protocol) + "//" + window.location.host + "/game/" + GameJs.game.ip);
const el = document.getElementById("live-updates");

if (window.live) {
el.innerText = "Disable Live Updates";
el.href = `${window.location.href}${window.location.href.indexOf("?") === -1 ? "?" : "&"}live=off`;
} else {
GameJs.ws = new WebSocketClient();
GameJs.ws.onmessage = GameJs.onmessage;
GameJs.ws.open((window.location.protocol === "http:" ? "ws:" : window.location.protocol === "https:" ? "wss:" : window.location.protocol) + "//" + window.location.host + "/game/" + GameJs.game.ip);
el.innerText = "Enable Live Updates";
el.href = `${window.location.href.replace(/[?&]live=off/, "")}${window.location.href.replace(/[?&]live=off/, "").indexOf("?") === -1 ? "?" : "&"}live=on`;
}
}

// ## ### # # ## ### ### ### ### ##
Expand Down
15 changes: 12 additions & 3 deletions public/js/home.js
Expand Up @@ -24,9 +24,18 @@ class Home {
static DOMContentLoaded() {
Common.loadTimeAgo();

Home.ws = new WebSocketClient();
Home.ws.onmessage = Home.onmessage;
Home.ws.open((window.location.protocol === "http:" ? "ws:" : window.location.protocol === "https:" ? "wss:" : window.location.protocol) + "//" + window.location.host);
const el = document.getElementById("live-updates");

if (window.live) {
el.innerText = "Disable Live Updates";
el.href = `${window.location.href}${window.location.href.indexOf("?") === -1 ? "?" : "&"}live=off`;
} else {
Home.ws = new WebSocketClient();
Home.ws.onmessage = Home.onmessage;
Home.ws.open((window.location.protocol === "http:" ? "ws:" : window.location.protocol === "https:" ? "wss:" : window.location.protocol) + "//" + window.location.host);
el.innerText = "Enable Live Updates";
el.href = `${window.location.href.replace(/[?&]live=off/, "")}${window.location.href.replace(/[?&]live=off/, "").indexOf("?") === -1 ? "?" : "&"}live=on`;
}
}

// ## ### # # ## ### ### ### ### ##
Expand Down

0 comments on commit e30c456

Please sign in to comment.