diff options
| author | 2025-08-29 02:02:52 +0700 | |
|---|---|---|
| committer | 2025-08-29 02:02:52 +0700 | |
| commit | 5e40ca4d314a9dc6cb7cb2c69081876f5aa446f3 (patch) | |
| tree | bb2c30830de590b34e872ff6ea671d68a476a512 /views | |
| parent | 26c77e33356a519b3caaed44fd9d7f8722f41918 (diff) | |
| download | web-5e40ca4d314a9dc6cb7cb2c69081876f5aa446f3.tar.gz web-5e40ca4d314a9dc6cb7cb2c69081876f5aa446f3.zip | |
feat: implement decor of night/ram theme on general pages
Diffstat (limited to 'views')
| -rw-r--r-- | views/layouts/general-page.html | 126 | ||||
| -rw-r--r-- | views/pages/blog-page.html | 6 |
2 files changed, 118 insertions, 14 deletions
diff --git a/views/layouts/general-page.html b/views/layouts/general-page.html index 9885d66..a7cf66e 100644 --- a/views/layouts/general-page.html +++ b/views/layouts/general-page.html @@ -15,6 +15,112 @@ <body data-theme="ram" class="font-spectral text-main-dark overflow-hidden bg-interlocked-hexagons h-screen flex flex-row ar-lt-0.8:flex-col"> <script> + function sfc32(a, b, c, d) { + return function() { + a |= 0; b |= 0; c |= 0; d |= 0; + let t = (a + b | 0) + d | 0; + d = d + 1 | 0; + a = b ^ b >>> 9; + b = c + (c << 3) | 0; + c = (c << 21 | c >>> 11); + c = c + t | 0; + return (t >>> 0) / 4294967296; + } + } + + function cyrb128(str) { + let h1 = 1779033703, h2 = 3144134277, + h3 = 1013904242, h4 = 2773480762; + for (let i = 0, k; i < str.length; i++) { + k = str.charCodeAt(i); + h1 = h2 ^ Math.imul(h1 ^ k, 597399067); + h2 = h3 ^ Math.imul(h2 ^ k, 2869860233); + h3 = h4 ^ Math.imul(h3 ^ k, 951274213); + h4 = h1 ^ Math.imul(h4 ^ k, 2716044179); + } + h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067); + h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233); + h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213); + h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179); + h1 ^= (h2 ^ h3 ^ h4), h2 ^= h1, h3 ^= h1, h4 ^= h1; + return [h1>>>0, h2>>>0, h3>>>0, h4>>>0]; + } + + var seed = cyrb128("{{ .Title }}"); + var rand = sfc32(seed[0], seed[1], seed[2], seed[3]); + + function calculateVmin(percent) { + const viewportWidth = window.innerWidth; + const viewportHeight = window.innerHeight; + + const smallerDimension = Math.min(viewportWidth, viewportHeight); + + const vminValue = (smallerDimension / 100) * percent; + + return vminValue; + } + + function switchThemeDecor(theme) { + document.querySelectorAll('.theme-decor').forEach((e) => { + e.remove(); + }); + + if (theme == "" || typeof theme == "undefined") { + theme = document.body.getAttribute('data-theme'); + } + + vmin = calculateVmin(1); + var clWidth = document.documentElement.clientWidth; + var clHeight = document.documentElement.clientHeight; + + switch (theme) { + case "olive": break; + case "lettuce": break; + case "night": + for (i = 0; i < 25; i++) { + let star = document.createElement("div"); + star.append("*"); + star.classList.add("night-star", "theme-decor", "z-0", "absolute"); + const x = Math.floor(rand() * clWidth); + const y = Math.floor(rand() * clHeight * 0.8); + const rot = rand() * 90; + const animDuration = (rand() * 10) + 3; + const sz = Math.floor(rand() * 8) + 12; + star.style.transform = `translateX(${x}px) translateY(${y}px) rotate(${rot}deg)`; + star.style.animationDuration = `${animDuration}s`; + star.style.fontSize = `${sz}px`; + document.body.append(star); + } + break; + case "ram": + const frameCenters = new Array(4); + for (i = 1; i <= 4; i++) { + let frame = document.createElement("img"); + frame.src = `https://f003.backblazeb2.com/file/sayana-static/themes/ram/ram-frame${i}.webp`; + frame.classList.add("ram-frame", "theme-decor", "z-0", "absolute"); + let x, y; + outerLoop: + while (true) { + x = Math.floor(rand() * clWidth - 20*vmin); + y = Math.floor(rand() * clHeight - 20*vmin); + for (j = 0; j < i-1; j++) { + const xd = frameCenters[j].x - x; + const yd = frameCenters[j].y - y; + if (Math.sqrt(xd*xd + yd*yd) < 30*vmin) { + continue outerLoop; + } + } + break; + } + frameCenters[i-1] = {x: x, y: y}; + const rot = rand() * 90 - 45; + frame.style.transform = `translateX(${x}px) translateY(${y}px) rotate(${rot}deg)`; + document.body.append(frame); + } + break; + } + } + function switchTheme(theme) { if (theme == "" || typeof theme == "undefined") { const currentTheme = document.body.getAttribute('data-theme'); @@ -27,6 +133,7 @@ } localStorage.setItem('theme', theme); document.body.setAttribute('data-theme', theme); + switchThemeDecor(theme); } const savedTheme = localStorage.getItem('theme') || 'ram'; @@ -100,17 +207,6 @@ } }); - function calculateVmin(percent) { - const viewportWidth = window.innerWidth; - const viewportHeight = window.innerHeight; - - const smallerDimension = Math.min(viewportWidth, viewportHeight); - - const vminValue = (smallerDimension / 100) * percent; - - return vminValue; - } - function calculateVmax(percent) { const viewportWidth = window.innerWidth; const viewportHeight = window.innerHeight; @@ -211,6 +307,14 @@ }); </script> + <script> + let decorResizeTimeout; + window.addEventListener('resize', function() { + clearTimeout(decorResizeTimeout); + decorResizeTimeout = setTimeout(switchThemeDecor, 300); + }); + </script> + {{ block "bottom-embeds" . }}{{ end }} </body> diff --git a/views/pages/blog-page.html b/views/pages/blog-page.html index d685fda..65ee31d 100644 --- a/views/pages/blog-page.html +++ b/views/pages/blog-page.html @@ -74,10 +74,10 @@ {{ .MapLocationAreaMeters }} )}); - let resizeTimeout; + let galleryResizeTimeout; window.addEventListener('resize', function() { - clearTimeout(resizeTimeout); - resizeTimeout = setTimeout(() => { + clearTimeout(galleryResizeTimeout); + galleryResizeTimeout = setTimeout(() => { map.invalidateSize(); var oldGalleryMap = new Map(galleryMap); oldGalleryMap.forEach((createFunc, g, map) => { |