optimize a lot of stuff
This commit is contained in:
61
js/main.js
61
js/main.js
@ -19,20 +19,16 @@ function loadPJS() {
|
||||
|
||||
function cursor() {
|
||||
let cursor = document.createElement("div");
|
||||
cursor.style.width = "30px";
|
||||
cursor.style.height = "30px";
|
||||
cursor.style.backgroundColor = "var(--color-1)";
|
||||
cursor.style.position = "absolute";
|
||||
cursor.style.borderRadius = "100%";
|
||||
cursor.style.filter = "blur(50px)";
|
||||
cursor.style.transitionDuration = "0s";
|
||||
cursor.style.opacity = "1";
|
||||
cursor.style.pointerEvents = "none";
|
||||
cursor.style.cssText = "width:30px;height:30px;background-color:var(--color-1);position:fixed;border-radius:100%;filter:blur(50px);opacity:1;pointer-events:none;top:0;left:0;";
|
||||
document.body.appendChild(cursor);
|
||||
let rafId = null;
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
cursor.style.top = `${e.pageY - 15}px`;
|
||||
cursor.style.left = `${e.pageX - 15}px`;
|
||||
})
|
||||
if (rafId) return;
|
||||
rafId = requestAnimationFrame(() => {
|
||||
cursor.style.transform = `translate(${e.clientX - 15}px, ${e.clientY - 15}px)`;
|
||||
rafId = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
function themes() {
|
||||
document.body.setAttribute("theme", localStorage.getItem("selenite.theme") || "")
|
||||
@ -56,23 +52,15 @@ function setTheme(arg) {
|
||||
async function caching() {
|
||||
if(sessionStorage.getItem("cdns")) return "done";
|
||||
let cdns = JSON.parse(atob("WyJodHRwczovL2NhY2hpbmcuZnJlZXRscy5mYXN0bHkubmV0IiwiaHR0cHM6Ly9jYWNoaW5nLmdsb2JhbC5zc2wuZmFzdGx5Lm5ldCJd"));
|
||||
let goods = [];
|
||||
let cfStatus = (await fetch("/alive.txt")).headers.get("Cf-Ray") != null;
|
||||
if(cfStatus) {
|
||||
localStorage.setItem("selenite.disableCDN", "true");
|
||||
return;
|
||||
}
|
||||
for(let i = 0;i<cdns.length;i++) {
|
||||
let cdn = cdns[i];
|
||||
await fetch(cdn + "/alive.txt")
|
||||
.then(data => data.text())
|
||||
.then(data => {
|
||||
if(data.startsWith("yeah true")) {
|
||||
goods.push(cdn);
|
||||
}
|
||||
})
|
||||
}
|
||||
sessionStorage.setItem("cdns", JSON.stringify(goods));
|
||||
const results = await Promise.all(cdns.map(cdn =>
|
||||
fetch(cdn + "/alive.txt").then(r => r.text()).then(t => t.startsWith("yeah true") ? cdn : null).catch(() => null)
|
||||
));
|
||||
sessionStorage.setItem("cdns", JSON.stringify(results.filter(Boolean)));
|
||||
return;
|
||||
}
|
||||
function sendData() {
|
||||
@ -110,17 +98,26 @@ document.addEventListener("DOMContentLoaded", async ()=>{
|
||||
}
|
||||
})
|
||||
|
||||
document.addEventListener("scroll", ()=>{
|
||||
document.getElementById("pjs").style.top = window.scrollY + "px";
|
||||
})
|
||||
|
||||
navigator.serviceWorker.addEventListener('message', (event) => {
|
||||
if (event.data.command === 'localStorage') {
|
||||
const data = localStorage.getItem(event.data.key);
|
||||
event.ports[0].postMessage({ data: data });
|
||||
}
|
||||
let scrollRaf = null;
|
||||
document.addEventListener("scroll", () => {
|
||||
if (scrollRaf) return;
|
||||
scrollRaf = requestAnimationFrame(() => {
|
||||
const pjs = document.getElementById("pjs");
|
||||
if (pjs) pjs.style.top = window.scrollY + "px";
|
||||
scrollRaf = null;
|
||||
});
|
||||
});
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.addEventListener('message', (event) => {
|
||||
if (event.data.command === 'localStorage') {
|
||||
const data = localStorage.getItem(event.data.key);
|
||||
event.ports[0].postMessage({ data: data });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// var interval;
|
||||
// document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
Reference in New Issue
Block a user