Add pwa support

This commit is contained in:
2026-02-28 06:32:39 -06:00
parent 02b10131f9
commit 28b7138547
25 changed files with 870 additions and 48 deletions

View File

@@ -0,0 +1,54 @@
function addOffline(url,res)
{
var videos = JSON.parse(localStorage.getItem("videos") ?? "[]");
videos.push({
url: url,
res: res
});
localStorage.setItem('videos',JSON.stringify(videos));
}
async function syncOffline()
{
const json = localStorage.getItem("videos") ?? "[]";
if(json !== "[]")
{
const resp = await fetch('/api/v1/add',{
body: json,
headers: {
'Content-Type': 'application/json'
},
method: "POST"
});
if(resp.ok)
{
localStorage.removeItem('videos');
}
}
}
if(navigator.online)
{
syncOffline();
}
window.addEventListener('online',()=>{
syncOffline();
});
async function getPersonalTempLink()
{
const searchParams = new URLSearchParams(window.location.search);
const ent = searchParams.get("name");
if(ent)
{
const resp=await fetch(`./api/v1/personal_tmp_link?name=${encodeURIComponent(ent)}`);
if(resp.ok)
{
const text = await resp.text();
the_playlist_url.innerText = text;
the_playlist_url.href = text;
ui("#dialog");
}
}
}