mirror of
https://onedev.site.tesses.net/tytd2025
synced 2026-06-01 18:05:32 +00:00
Add pwa support
This commit is contained in:
54
Tesses.YouTubeDownloader.Server/res/offline.js
Normal file
54
Tesses.YouTubeDownloader.Server/res/offline.js
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user