diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2023-07-30 12:47:35 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2023-07-30 12:47:35 +0000 |
commit | 9689f2daa6c34e7d24d5cf1648168c66c5678385 (patch) | |
tree | e97da04e1862373ef6643370d8bb5e6482a41a77 /static/scripts | |
parent | 278649e832bb4e61a3478f8838555529d4848934 (diff) | |
download | tagrss-9689f2daa6c34e7d24d5cf1648168c66c5678385.tar tagrss-9689f2daa6c34e7d24d5cf1648168c66c5678385.tar.gz tagrss-9689f2daa6c34e7d24d5cf1648168c66c5678385.zip |
Add auto-refresh checkbox, don't auto-refresh except on front page
Also use input type "hidden" instead of display: none where appropriate
(no observable effects, just cleaner).
Diffstat (limited to 'static/scripts')
-rw-r--r-- | static/scripts/auto_refresh.js | 24 |
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); })(); |