aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-07-30 12:47:35 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-07-30 12:47:35 +0000
commit9689f2daa6c34e7d24d5cf1648168c66c5678385 (patch)
treee97da04e1862373ef6643370d8bb5e6482a41a77
parent278649e832bb4e61a3478f8838555529d4848934 (diff)
downloadtagrss-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).
-rw-r--r--static/scripts/auto_refresh.js24
-rw-r--r--views/index.tpl23
2 files changed, 39 insertions, 8 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);
})();
diff --git a/views/index.tpl b/views/index.tpl
index b00b7d0..67eb413 100644
--- a/views/index.tpl
+++ b/views/index.tpl
@@ -41,6 +41,10 @@
overflow: auto;
white-space: nowrap;
}
+
+ label#refresh_checkbox_label {
+ float: right;
+ }
</style>
<script src="/static/scripts/auto_refresh.js" defer></script>
</head>
@@ -52,6 +56,9 @@
<a href="/list_feeds" class="no-visited-indication">List feeds</a>
</p>
</nav>
+ <label id="refresh_checkbox_label" style="display: none;">Refresh entries periodically
+ <input type="checkbox" checked>
+ </label>
<details {{"open" if (included_feeds or included_tags) else ""}}>
<summary>Filter</summary>
<form>
@@ -68,15 +75,15 @@
% input_value=included_tags_str if included_tags_str else ""
% )
<input type="submit" value="Filter">
- <input type="number" value="{{page_num}}" min="1" max="{{total_pages}}" name="page_num" style="display: none;">
- <input type="number" value="{{per_page}}" min="1" max="{{max_per_page}}" name="per_page" style="display: none;">
+ <input type="hidden" value="{{page_num}}" min="1" max="{{total_pages}}" name="page_num">
+ <input type="hidden" value="{{per_page}}" min="1" max="{{max_per_page}}" name="per_page">
</form>
<form>
- <input type="text" name="included_feeds" value="" style="display: none;">
- <input type="text" name="included_tags" value="" style="display: none;">
+ <input type="hidden" name="included_feeds" value="">
+ <input type="hidden" name="included_tags" value="">
<input type="submit" value="Clear filters">
- <input type="number" value="{{page_num}}" min="1" max="{{total_pages}}" name="page_num" style="display: none;">
- <input type="number" value="{{per_page}}" min="1" max="{{max_per_page}}" name="per_page" style="display: none;">
+ <input type="hidden" value="{{page_num}}" min="1" max="{{total_pages}}" name="page_num">
+ <input type="hidden" value="{{per_page}}" min="1" max="{{max_per_page}}" name="per_page">
</form>
</details>
<table>
@@ -136,10 +143,10 @@
</label>
<input type="submit" value="Go">
% if included_feeds:
- <input type="text" name="included_feeds" value="{{included_feeds_str}}" style="display: none;">
+ <input type="hidden" name="included_feeds" value="{{included_feeds_str}}">
% end
% if included_tags:
- <input type="text" name="included_tags" value="{{included_tags_str}}" style="display: none;">
+ <input type="hidden" name="included_tags" value="{{included_tags_str}}">
% end
</form>
% include("footer.tpl")