mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
const openDB=()=>new Promise(((e,t)=>{const o=indexedDB.open("MyDatabase",1);o.onerror=()=>t(o.error),o.onsuccess=()=>e(o.result),o.onupgradeneeded=e=>{e.target.result.createObjectStore("backgrounds",{keyPath:"id"})}})),readData=async()=>{const e=localStorage.getItem("selectedBackground");if(!e)return console.log("No selected background in local storage."),null;const t=(await openDB()).transaction("backgrounds","readonly").objectStore("backgrounds").get(e);return await new Promise(((e,o)=>{t.onsuccess=()=>e(t.result),t.onerror=()=>o(t.error)}))},updateBackground=async()=>{try{const e=await readData();if(!e){console.log("No data found in IndexedDB.");const e=document.getElementById("media-container").querySelector(".current-media");return void(e&&e.remove())}const t=URL.createObjectURL(e.blob),o=document.getElementById("media-container");let a;"image"===e.type?(a=document.createElement("img"),a.src=t,a.alt="Uploaded content"):"video"===e.type&&(a=document.createElement("video"),a.src=t,a.autoplay=!0,a.loop=!0,a.muted=!0);const r=o.querySelector(".current-media");r&&(r.classList.remove("current-media"),r.classList.add("old-media")),a.classList.add("current-media"),o.appendChild(a),setTimeout((()=>{const e=o.querySelector(".old-media");e&&e.remove()}),100)}catch(e){console.error("An error occurred:",e)}},main=async()=>{await updateBackground(),window.addEventListener("storage",(async e=>{"selectedBackground"===e.key&&await updateBackground()}))};document.addEventListener("DOMContentLoaded",main); |