aboutsummaryrefslogtreecommitdiff
path: root/static/scripts/auto_refresh.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/scripts/auto_refresh.js')
-rw-r--r--static/scripts/auto_refresh.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/static/scripts/auto_refresh.js b/static/scripts/auto_refresh.js
index 20fc5c6..48af816 100644
--- a/static/scripts/auto_refresh.js
+++ b/static/scripts/auto_refresh.js
@@ -1,6 +1,28 @@
(() => {
+ const onFrontPage = () => {
+ const searchParams = new URLSearchParams(window.location.search);
+ let pageNum = searchParams.get("page_num");
+ return (pageNum === "1") || (pageNum === null);
+ };
+
+ const refreshCheckboxLabel = document.querySelector("label#refresh_checkbox_label");
+ if (onFrontPage()) {
+ refreshCheckboxLabel.setAttribute("style", "");
+ }
+
const UPDATE_INTERVAL_MILLISECONDS = 1 * 60 * 1000; // 1 minute
setInterval(async () => {
+ if (!onFrontPage()) {
+ return;
+ }
+
+ const refreshCheckbox = document.querySelector("label#refresh_checkbox_label > input");
+ if (!refreshCheckbox.checked) {
+ return;
+ }
+
+ console.log("Refreshing entries...");
+
const response = await fetch(window.location);
if (!response.ok) {
return;
@@ -10,5 +32,7 @@
const parser = new DOMParser();
const newDoc = parser.parseFromString(responseText, "text/html");
document.querySelector("table").innerHTML = newDoc.querySelector("table").innerHTML;
+
+ console.log("Refreshed entries.");
}, UPDATE_INTERVAL_MILLISECONDS);
})();