test window.location object use

This commit is contained in:
2025-08-18 13:28:14 +02:00
committed by GitHub
parent 6076b5f6f2
commit 6b04b75314
2 changed files with 16 additions and 19 deletions

View File

@@ -1 +1 @@
2.8.3 2.8.4

View File

@@ -1,9 +1,6 @@
class PhotoGallery { class PhotoGallery {
constructor() { constructor() {
this.pswpElement = document.querySelector(".pswp"); this.pswpElement = document.querySelector(".pswp");
this.re = /pid=(\d+)/;
this.filterRe = /#(.*)/;
this.recursiveRe = /\?recursive/;
this.items = []; this.items = [];
this.shown = []; this.shown = [];
this.subfolders = []; this.subfolders = [];
@@ -71,7 +68,6 @@ class PhotoGallery {
} }
reset() { reset() {
const curr = window.location.href.split("#");
const content = document.documentElement.innerHTML; const content = document.documentElement.innerHTML;
const title = document.title; const title = document.title;
const folders = document.querySelector(".folders"); const folders = document.querySelector(".folders");
@@ -83,13 +79,13 @@ class PhotoGallery {
window.history.replaceState( window.history.replaceState(
{ html: content, pageTitle: title }, { html: content, pageTitle: title },
"", "",
curr[0].split("?")[0] + "#" window.location.origin + window.location.pathname
); );
this.requestMetadata(); this.requestMetadata();
} }
async recursive() { async recursive() {
const curr = window.location.href.split("#"); const loc = window.location;
const content = document.documentElement.innerHTML; const content = document.documentElement.innerHTML;
const title = document.title; const title = document.title;
const isChecked = document.getElementById("recursive")?.checked; const isChecked = document.getElementById("recursive")?.checked;
@@ -97,20 +93,22 @@ class PhotoGallery {
if (!isChecked) { if (!isChecked) {
if (folders) folders.style.display = ""; if (folders) folders.style.display = "";
loc.searchParams.delete("recursive");
window.history.replaceState( window.history.replaceState(
{ html: content, pageTitle: title }, { html: content, pageTitle: title },
"", "",
curr[0].split("?")[0] + "#" + (curr[1] || "") loc
); );
this.requestMetadata(); this.requestMetadata();
return; return;
} }
if (folders) folders.style.display = "none"; if (folders) folders.style.display = "none";
loc.searchParams.append("recursive", true)
window.history.replaceState( window.history.replaceState(
{ html: content, pageTitle: title }, { html: content, pageTitle: title },
"", "",
curr[0].split("?")[0] + "?recursive#" + (curr[1] || "") loc
); );
const visited = new Set(); const visited = new Set();
@@ -164,6 +162,8 @@ class PhotoGallery {
} }
requestMetadata() { requestMetadata() {
const hash = window.location.hash;
const searchParams = new URLSearchParams(window.location.search);
fetch(".metadata.json") fetch(".metadata.json")
.then((response) => { .then((response) => {
if (!response.ok) throw new Error("Failed to fetch metadata"); if (!response.ok) throw new Error("Failed to fetch metadata");
@@ -173,21 +173,19 @@ class PhotoGallery {
this.items = Object.values(data.images || {}); this.items = Object.values(data.images || {});
this.subfolders = data.subfolders || []; this.subfolders = data.subfolders || [];
if (this.filterRe.test(window.location.href)) { if (hash != "") {
const selected = window.location.href const selected = hash.replace("#", "").split(",");
.match(this.filterRe)[1]
.split(",");
this.setFilter(selected); this.setFilter(selected);
} }
if (this.recursiveRe.test(window.location.href)) { if (searchParams.get("recursive") != null) {
const recChk = document.getElementById("recursive"); const recChk = document.getElementById("recursive");
if (recChk) recChk.checked = true; if (recChk) recChk.checked = true;
this.recursive(); this.recursive();
} else { } else {
this.filter(); this.filter();
} }
if (this.re.test(window.location.href)) { const pid = searchParams.get("pid");
const pid = window.location.href.match(this.re)[1]; if (pid != null) {
this.openSwipe(parseInt(pid)); this.openSwipe(parseInt(pid));
} }
}) })
@@ -196,9 +194,8 @@ class PhotoGallery {
filter() { filter() {
this.shown = []; this.shown = [];
const curr = window.location.href.split("#")[0] + "#";
const path = decodeURIComponent( const path = decodeURIComponent(
window.location.href.split("#")[0].replace("index.html", "") window.location.origin.replace("index.html", "")
); );
const selectedTags = []; const selectedTags = [];
@@ -239,7 +236,7 @@ class PhotoGallery {
} }
} }
this.updateImageList(); this.updateImageList();
window.location.href = curr + urltags; window.location.hash = urltags;
} }
updateImageList() { updateImageList() {