Files
WaifuBoard/desktop/src/scripts/utils/url-utils.js
itsskaiya 28ff6ccc68 Organized the differences between server and docker versions.
We are launching a docker version (server version) today so we want to just organize the repo
so its easier to navigate.
2025-12-16 21:50:22 -05:00

51 lines
1.3 KiB
JavaScript

const URLUtils = {
parseEntityPath(basePath = 'anime') {
const path = window.location.pathname;
const parts = path.split("/").filter(Boolean);
if (parts[0] !== basePath) {
return null;
}
if (parts.length === 3) {
return {
extensionName: parts[1],
entityId: parts[2],
slug: parts[2]
};
} else if (parts.length === 2) {
return {
extensionName: null,
entityId: parts[1],
slug: null
};
}
return null;
},
buildWatchUrl(animeId, episode, extensionName = null) {
const base = `/watch/${animeId}/${episode}`;
return extensionName ? `${base}?${extensionName}` : base;
},
buildReadUrl(bookId, chapterId, provider, extensionName = null) {
const c = encodeURIComponent(chapterId);
const p = encodeURIComponent(provider);
const extension = extensionName ? `?source=${extensionName}` : "?source=anilist";
return `/read/${p}/${c}/${bookId}${extension}`;
},
getQueryParams() {
return new URLSearchParams(window.location.search);
},
getQueryParam(key) {
return this.getQueryParams().get(key);
}
};
window.URLUtils = URLUtils;