mirror of
https://github.com/wah-su/mstickers.git
synced 2025-05-22 20:59:39 +05:00
REFACTOR: Generate Static Pages instead of ?id query param for sticker pack
This commit is contained in:
parent
5cb32a8681
commit
dfcddfc0cd
21 changed files with 2074 additions and 473 deletions
13
static/OpenPopUp.js
Normal file
13
static/OpenPopUp.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const ElementInstructionOV = document.getElementById(
|
||||
"preview_sticker_pack_add_to_element_overlay"
|
||||
);
|
||||
const ElementInstruction = document.getElementById(
|
||||
"preview_sticker_pack_add_to_element"
|
||||
);
|
||||
|
||||
function toggleElementInstruction() {
|
||||
ElementInstructionOV.classList.toggle("hidden");
|
||||
ElementInstruction.classList.toggle("hidden");
|
||||
|
||||
ElementInstruction.classList.toggle("flex");
|
||||
}
|
22
static/RenderImages.js
Normal file
22
static/RenderImages.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const images = document.querySelectorAll("[data-image-id]");
|
||||
|
||||
images.forEach((image) => {
|
||||
|
||||
const spinner = document.querySelector(`[data-spinner-id="${image.getAttribute("data-image-id")}"]`)
|
||||
console.log(image)
|
||||
console.log(spinner)
|
||||
|
||||
if (image.height > 0) {
|
||||
image.classList.remove("hidden");
|
||||
spinner.classList.add("hidden");
|
||||
return
|
||||
}
|
||||
|
||||
image.addEventListener("load", () => {
|
||||
console.log("image " + image.getAttribute("data-image-id") + " loaded");
|
||||
image.classList.remove("hidden");
|
||||
spinner.classList.add("hidden");
|
||||
image.removeEventListener("load", this);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,233 +0,0 @@
|
|||
const packPreview = document.getElementById("preview_sticker_pack");
|
||||
const packName = document.getElementById("preview_sticker_pack_name");
|
||||
const packAuthor_by = document.getElementById("preview_sticker_pack_author_by");
|
||||
const packAuthor = document.getElementById("preview_sticker_pack_author");
|
||||
const packImage = document.getElementById("preview_sticker_pack_image");
|
||||
const packStickersC = document.getElementById(
|
||||
"preview_sticker_pack_stickers_container"
|
||||
);
|
||||
const packStickersCount = document.getElementById(
|
||||
"preview_sticker_pack_stickers_count"
|
||||
);
|
||||
const packStickers = document.getElementById("preview_sticker_pack_stickers");
|
||||
const packLinkTG = document.getElementById("preview_sticker_pack_add_tg");
|
||||
const packLinkFC = document.getElementById("preview_sticker_pack_add_fc");
|
||||
const packLinkCI = document.getElementById("preview_sticker_pack_add_ci");
|
||||
const ElementInstructionOV = document.getElementById(
|
||||
"preview_sticker_pack_add_to_element_overlay"
|
||||
);
|
||||
const ElementInstruction = document.getElementById(
|
||||
"preview_sticker_pack_add_to_element"
|
||||
);
|
||||
|
||||
const stickerpacksIndexContainer =
|
||||
document.getElementById("stickerpacks_index");
|
||||
|
||||
let index = null;
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const pack_id = searchParams.get("id");
|
||||
|
||||
async function loadIndex() {
|
||||
index = await fetch(`${window.location.origin}/stickerpacks/index.json`)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error("not found");
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then((json) => {
|
||||
return json;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!pack_id) {
|
||||
loadStickerpacks();
|
||||
} else if (!index) {
|
||||
stickerpacksIndexContainer.classList.remove("hidden");
|
||||
stickerpacksIndexContainer.innerHTML = "no index.json found";
|
||||
} else {
|
||||
loadPack(pack_id);
|
||||
}
|
||||
}
|
||||
|
||||
function imageIsLoaded(img_id, img_placeholder) {
|
||||
const __img = document.getElementById(img_id);
|
||||
const __img_placeholder = document.getElementById(img_placeholder);
|
||||
if (__img.complete) {
|
||||
__img_placeholder.classList.add("hidden");
|
||||
__img.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStickerpacks() {
|
||||
stickerpacksIndexContainer.classList.remove("hidden");
|
||||
stickerpacksIndexContainer.classList.add("grid");
|
||||
for (let i = 0; i < index.packs.length; i++) {
|
||||
const data = await fetch(
|
||||
`${window.location.origin}/stickerpacks/${index.packs[i]}`
|
||||
)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error("not found");
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then((json) => {
|
||||
return json;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
return null;
|
||||
});
|
||||
if (!data) {
|
||||
continue;
|
||||
}
|
||||
const _tmp_id = data.stickers[0].id;
|
||||
stickerpacksIndexContainer.innerHTML += `
|
||||
<a href="index.html?id=${index.packs[i].split(".json")[0]}">
|
||||
<div class="flex gap-4 items-center bg-stone-800 text-slate-200 p-4 rounded-lg">
|
||||
<img src="${getStickerImage(data.stickers[0].id)}" alt="${
|
||||
data.stickers[0].body
|
||||
}" class="hidden object-contain w-24" id="${_tmp_id}"/>
|
||||
<img src="static/images/sticker.png" alt="${
|
||||
data.stickers[0].body
|
||||
}" class="object-contain w-24" id="${_tmp_id}-placeholder"/>
|
||||
<div>
|
||||
<p class="text-2xl">${data.title}</p>
|
||||
${
|
||||
data.hasOwnProperty("author") && data.author.name
|
||||
? `<p class="text-xl">${data.author.name}</p>`
|
||||
: ""
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
`;
|
||||
const __img = document.getElementById(_tmp_id);
|
||||
__img.addEventListener("load", () => {
|
||||
imageIsLoaded(_tmp_id, `${_tmp_id}-placeholder`);
|
||||
__img.removeEventListener("load", this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPack(pack) {
|
||||
const data = await fetch(
|
||||
`${window.location.origin}/stickerpacks/${pack}.json`
|
||||
)
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error("not found");
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then((json) => {
|
||||
return json;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
return null;
|
||||
});
|
||||
packPreview.classList.remove("hidden");
|
||||
packPreview.classList.add("flex");
|
||||
if (!data) {
|
||||
packName.innerHTML = "sticker pack not found";
|
||||
return;
|
||||
}
|
||||
updatePackInfo(data);
|
||||
}
|
||||
|
||||
function getStickerImage(stickerID) {
|
||||
const _image_path = `${stickerID.slice(0, 2)}/${stickerID.slice(
|
||||
2,
|
||||
4
|
||||
)}/${stickerID.slice(4)}`;
|
||||
|
||||
return `${index.homeserver_url}/__thumbnail/${_image_path}`;
|
||||
}
|
||||
|
||||
function updatePackInfo(data) {
|
||||
packName.innerHTML = data.title;
|
||||
|
||||
if (data.hasOwnProperty("author") && data.author) {
|
||||
packAuthor_by.classList.remove("hidden");
|
||||
packAuthor.classList.remove("hidden");
|
||||
packAuthor.innerHTML = data.author.name;
|
||||
|
||||
if (data.author.url) {
|
||||
packAuthor.href = data.author.url;
|
||||
}
|
||||
}
|
||||
|
||||
packImage.src = getStickerImage(data.stickers[0].id);
|
||||
|
||||
if (data.hasOwnProperty("rating") && data.rating) {
|
||||
switch (data.rating.toLowerCase()) {
|
||||
case "safe":
|
||||
document
|
||||
.getElementById("preview_sticker_pack_rating_safe")
|
||||
.classList.remove("hidden");
|
||||
break;
|
||||
case "questionable":
|
||||
document
|
||||
.getElementById("preview_sticker_pack_rating_ques")
|
||||
.classList.remove("hidden");
|
||||
break;
|
||||
case "explicit":
|
||||
document
|
||||
.getElementById("preview_sticker_pack_rating_expl")
|
||||
.classList.remove("hidden");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packLinkTG.href = `https://t.me/addstickers/${data.id}`;
|
||||
packLinkTG.classList.remove("hidden");
|
||||
packLinkTG.classList.add("flex");
|
||||
|
||||
if (data.hasOwnProperty("room_id") && data.room_id) {
|
||||
packLinkFC.href = `https://matrix.to/#/${data.room_id}`;
|
||||
packLinkCI.href = `https://matrix.to/#/${data.room_id}`;
|
||||
packLinkFC.classList.remove("hidden");
|
||||
packLinkFC.classList.add("flex");
|
||||
packLinkCI.classList.remove("hidden");
|
||||
packLinkCI.classList.add("flex");
|
||||
}
|
||||
|
||||
packStickersC.classList.remove("hidden");
|
||||
packStickersCount.innerHTML = `(${data.stickers.length})`;
|
||||
for (let i = 0; i < data.stickers.length; i++) {
|
||||
const sticker = data.stickers[i];
|
||||
const stickerImage = document.createElement("img");
|
||||
const stickerImagePlaceholder = document.createElement("img");
|
||||
stickerImagePlaceholder.src = `static/images/sticker.png`;
|
||||
stickerImagePlaceholder.id = `${sticker.id}-placeholder`;
|
||||
stickerImagePlaceholder.alt = sticker.body;
|
||||
stickerImagePlaceholder.classList.add("object-contain", "md:w-20", "w-24");
|
||||
packStickers.appendChild(stickerImagePlaceholder);
|
||||
stickerImage.src = getStickerImage(sticker.id);
|
||||
stickerImage.id = sticker.id;
|
||||
stickerImage.alt = sticker.body;
|
||||
stickerImage.classList.add("object-contain", "md:w-20", "w-24", "hidden");
|
||||
packStickers.appendChild(stickerImage);
|
||||
|
||||
stickerImage.addEventListener("load", () => {
|
||||
imageIsLoaded(sticker.id, `${sticker.id}-placeholder`);
|
||||
stickerImage.removeEventListener("load", this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function toggleElementInstruction() {
|
||||
ElementInstructionOV.classList.toggle("hidden");
|
||||
ElementInstruction.classList.toggle("hidden");
|
||||
|
||||
ElementInstruction.classList.toggle("flex");
|
||||
}
|
||||
|
||||
loadIndex();
|
|
@ -588,30 +588,34 @@ video {
|
|||
}
|
||||
}
|
||||
|
||||
.fixed {
|
||||
position: fixed;
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border-width: 0;
|
||||
}
|
||||
|
||||
.absolute {
|
||||
position: absolute;
|
||||
.fixed {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.inset-0 {
|
||||
inset: 0px;
|
||||
}
|
||||
|
||||
.top-0 {
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
.top-16 {
|
||||
top: 4rem;
|
||||
}
|
||||
|
||||
.top-8 {
|
||||
top: 2rem;
|
||||
}
|
||||
|
||||
.left-1\/2 {
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
.-z-10 {
|
||||
z-index: -10;
|
||||
}
|
||||
|
@ -633,18 +637,14 @@ video {
|
|||
margin-right: auto;
|
||||
}
|
||||
|
||||
.mt-4 {
|
||||
margin-top: 1rem;
|
||||
.inline {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
@ -653,6 +653,10 @@ video {
|
|||
height: 4rem;
|
||||
}
|
||||
|
||||
.h-48 {
|
||||
height: 12rem;
|
||||
}
|
||||
|
||||
.min-h-screen {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
@ -661,47 +665,41 @@ video {
|
|||
width: 2.5rem;
|
||||
}
|
||||
|
||||
.w-20 {
|
||||
width: 5rem;
|
||||
.w-16 {
|
||||
width: 4rem;
|
||||
}
|
||||
|
||||
.w-64 {
|
||||
width: 16rem;
|
||||
.w-48 {
|
||||
width: 12rem;
|
||||
}
|
||||
|
||||
.w-full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.w-24 {
|
||||
width: 6rem;
|
||||
}
|
||||
|
||||
.w-32 {
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
.w-fit {
|
||||
width: -moz-fit-content;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.max-w-\[90\%\] {
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
.flex-grow {
|
||||
flex-grow: 1;
|
||||
.-translate-x-1\/2 {
|
||||
--tw-translate-x: -50%;
|
||||
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.flex-col {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.flex-wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.items-center {
|
||||
align-items: center;
|
||||
}
|
||||
|
@ -710,18 +708,6 @@ video {
|
|||
justify-content: center;
|
||||
}
|
||||
|
||||
.justify-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.justify-around {
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.justify-evenly {
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
|
||||
.gap-2 {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
@ -730,27 +716,14 @@ video {
|
|||
gap: 1rem;
|
||||
}
|
||||
|
||||
.gap-1 {
|
||||
gap: 0.25rem;
|
||||
.overflow-x-hidden {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.rounded-lg {
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.border-2 {
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.border-solid {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.border-black {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(0 0 0 / var(--tw-border-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-\[\#259d7b\] {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(37 157 123 / var(--tw-bg-opacity, 1));
|
||||
|
@ -805,6 +778,10 @@ video {
|
|||
--tw-gradient-to: #000 var(--tw-gradient-to-position);
|
||||
}
|
||||
|
||||
.fill-green-500 {
|
||||
fill: #22c55e;
|
||||
}
|
||||
|
||||
.object-contain {
|
||||
-o-object-fit: contain;
|
||||
object-fit: contain;
|
||||
|
@ -819,11 +796,26 @@ video {
|
|||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.px-8 {
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
||||
.py-2 {
|
||||
padding-top: 0.5rem;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.py-4 {
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.py-8 {
|
||||
padding-top: 2rem;
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.text-2xl {
|
||||
font-size: 1.5rem;
|
||||
line-height: 2rem;
|
||||
|
@ -834,9 +826,9 @@ video {
|
|||
line-height: 2.5rem;
|
||||
}
|
||||
|
||||
.text-xl {
|
||||
font-size: 1.25rem;
|
||||
line-height: 1.75rem;
|
||||
.text-gray-200 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(229 231 235 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.text-green-400 {
|
||||
|
@ -849,11 +841,6 @@ video {
|
|||
color: rgb(239 68 68 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.text-slate-200 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(226 232 240 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.text-slate-50 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(248 250 252 / var(--tw-text-opacity, 1));
|
||||
|
@ -869,6 +856,11 @@ video {
|
|||
color: rgb(234 179 8 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.text-zinc-100 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(244 244 245 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.underline {
|
||||
text-decoration-line: underline;
|
||||
}
|
||||
|
@ -889,30 +881,6 @@ video {
|
|||
transition-duration: 150ms;
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(1\2c minmax\(0\2c 1fr\)\)\] {
|
||||
grid-template-columns: repeat(1,minmax(0,1fr));
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(auto-fill\2c minmax\(128px\2c 256px\)\)\] {
|
||||
grid-template-columns: repeat(auto-fill,minmax(128px,256px));
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(auto-fill\2c minmax\(128px\2c 372px\)\)\] {
|
||||
grid-template-columns: repeat(auto-fill,minmax(128px,372px));
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(auto-fill\2c minmax\(128px\2c 512px\)\)\] {
|
||||
grid-template-columns: repeat(auto-fill,minmax(128px,512px));
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(auto-fill\2c minmax\(128px\2c 512pxpx\)\)\] {
|
||||
grid-template-columns: repeat(auto-fill,minmax(128px,512pxpx));
|
||||
}
|
||||
|
||||
.\[grid-template-columns\:repeat\(auto-fill\2c minmax\(128px\2c 512x\)\)\] {
|
||||
grid-template-columns: repeat(auto-fill,minmax(128px,512x));
|
||||
}
|
||||
|
||||
.tiledBackground {
|
||||
background-image: url('images/background-white.png');
|
||||
background-repeat: repeat;
|
||||
|
@ -923,39 +891,19 @@ video {
|
|||
margin-top: -16px;
|
||||
}
|
||||
|
||||
.hover\:scale-110:hover {
|
||||
--tw-scale-x: 1.1;
|
||||
--tw-scale-y: 1.1;
|
||||
.hover\:scale-105:hover {
|
||||
--tw-scale-x: 1.05;
|
||||
--tw-scale-y: 1.05;
|
||||
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.md\:top-\[25\%\] {
|
||||
top: 25%;
|
||||
}
|
||||
|
||||
.md\:top-64 {
|
||||
top: 16rem;
|
||||
}
|
||||
|
||||
.md\:top-32 {
|
||||
top: 8rem;
|
||||
}
|
||||
|
||||
.md\:w-\[600px\] {
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
.md\:w-24 {
|
||||
width: 6rem;
|
||||
}
|
||||
|
||||
.md\:w-20 {
|
||||
width: 5rem;
|
||||
}
|
||||
|
||||
.md\:w-64 {
|
||||
width: 16rem;
|
||||
.md\:w-\[768px\] {
|
||||
width: 768px;
|
||||
}
|
||||
|
||||
.md\:max-w-\[768px\] {
|
||||
|
@ -966,11 +914,14 @@ video {
|
|||
flex-direction: row;
|
||||
}
|
||||
|
||||
.md\:items-center {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.md\:whitespace-pre {
|
||||
white-space: pre;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.dark\:text-gray-600 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(75 85 99 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue