cdn
This commit is contained in:
@ -31,6 +31,11 @@
|
||||
<link rel="icon" href="https://ixl.com/ixl-favicon.png" id="favicon" />
|
||||
<!-- <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script> -->
|
||||
<script>
|
||||
window.addEventListener('beforeunload', function (event) {
|
||||
event.preventDefault();
|
||||
event.returnValue = '';
|
||||
return 'Are you sure you want to leave? Any unsaved changes will be lost.';
|
||||
});
|
||||
function connectToSocket() {
|
||||
let socket = new WebSocket("/socket");
|
||||
socket.addEventListener("open", () => {
|
||||
@ -107,7 +112,7 @@
|
||||
let weatherData = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${locationData.latitude}&longitude=${locationData.longitude}¤t=temperature_2m,weather_code&temperature_unit=fahrenheit`)
|
||||
.then(data => data.json());
|
||||
|
||||
document.getElementById("weather").innerText = `${Math.round(weatherData["current"]["temperature_2m"])}°C ${weatherCodeToEmoji[weatherData["current"]["weather_code"]]}`
|
||||
document.getElementById("weather").innerText = `${Math.round(weatherData["current"]["temperature_2m"])}°F ${weatherCodeToEmoji[weatherData["current"]["weather_code"]]}`
|
||||
}
|
||||
function updateTime() {
|
||||
document.getElementById("time").innerText = (new Date()).toLocaleTimeString();
|
||||
@ -255,7 +260,7 @@
|
||||
<div id="bottom-menu">
|
||||
<div class="bottom-item"><p id="online">currently online: --</p></div>
|
||||
<div class="bottom-item"><p>|</p></div>
|
||||
<div class="bottom-item"><p id="weather">--° 🌩️</p></div>
|
||||
<div class="bottom-item"><p id="weather">--°F 🌩️</p></div>
|
||||
<div class="bottom-item"><p>|</p></div>
|
||||
<div class="bottom-item"><p id="time">7:41:21 pm</p></div>
|
||||
</div>
|
||||
|
||||
12
js/all.min.js
vendored
12
js/all.min.js
vendored
@ -25,8 +25,16 @@ function antiSkid() {
|
||||
warning.style.position = "absolute";
|
||||
warning.style.width = "200px";
|
||||
warning.style.textAlign = "center";
|
||||
warning.style.bottom = "20px";
|
||||
warning.style.right = "20px";
|
||||
if(Math.random() > 0.5) {
|
||||
warning.style.bottom = "20px";
|
||||
} else {
|
||||
warning.style.top = "20px";
|
||||
}
|
||||
if(Math.random() > 0.5) {
|
||||
warning.style.right = "20px";
|
||||
} else {
|
||||
warning.style.left = "20px";
|
||||
}
|
||||
warning.style.backgroundColor = "#00000077";
|
||||
warning.style.padding = "8px";
|
||||
warning.style.cursor = "pointer";
|
||||
|
||||
49
js/main.js
49
js/main.js
@ -1,6 +1,4 @@
|
||||
let sAlert = window.parent.sAlert;
|
||||
|
||||
|
||||
function setBackground() {
|
||||
let randomNumbers = [100-Math.abs(Math.floor(Math.random() * 200) - 99), 100-Math.abs(Math.floor(Math.random() * 200) - 99)];
|
||||
document.body.style.setProperty("--gradient-x", randomNumbers[0] + "%");
|
||||
@ -54,7 +52,43 @@ function setTheme(arg) {
|
||||
--color-4: ${theme["color-4"]};
|
||||
`)
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", ()=>{
|
||||
|
||||
async function caching() {
|
||||
if(sessionStorage.getItem("cdns")) return "done";
|
||||
let cdns = JSON.parse(atob("WyJodHRwczovL2NhY2hpbmcuZnJlZXRscy5mYXN0bHkubmV0IiwiaHR0cHM6Ly9jYWNoaW5nLmdsb2JhbC5zc2wuZmFzdGx5Lm5ldCJd"));
|
||||
let goods = [];
|
||||
for(let i = 0;i<cdns.length;i++) {
|
||||
let cdn = cdns[i];
|
||||
// TODO: change to alive.txt
|
||||
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));
|
||||
return;
|
||||
}
|
||||
function sendData() {
|
||||
let data = {
|
||||
cdns: JSON.parse(sessionStorage.getItem("cdns")),
|
||||
disableCDN: localStorage.getItem("selenite.disableCDN") ? true : false,
|
||||
type: 'localStorage'
|
||||
};
|
||||
if (navigator.serviceWorker.controller) {
|
||||
navigator.serviceWorker.controller.postMessage(data);
|
||||
} else {
|
||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
navigator.serviceWorker.controller.postMessage(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async ()=>{
|
||||
if("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register("/sw.js", { scope: '/' });
|
||||
}
|
||||
@ -67,12 +101,21 @@ document.addEventListener("DOMContentLoaded", ()=>{
|
||||
document.body.setAttribute("fast", "")
|
||||
}
|
||||
themes();
|
||||
if(await caching() == "done") {
|
||||
sendData();
|
||||
}
|
||||
})
|
||||
|
||||
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 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// var interval;
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="gameFrame" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-scripts allow-same-origin" allow="cross-origin-isolated"></iframe>
|
||||
<iframe id="gameFrame"></iframe>
|
||||
<div id="infobox">
|
||||
<img id="gameImage" src="favicon.png" />
|
||||
<h2 id="gameName">Selenite</h2>
|
||||
|
||||
@ -63,6 +63,7 @@
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelector(`option[value="${localStorage.getItem("selenite.theme") || ""}"]`).setAttribute("selected", "");
|
||||
document.getElementById("toggleCDN").checked = localStorage.getItem("selenite.disableCDN") ? false : true;
|
||||
if(document.getElementById("themes").value == "custom") {
|
||||
document.getElementById("colorPicker").style.display = "block";
|
||||
document.getElementById("colorPicker").value = localStorage.getItem("selenite.customThemeMainColor");
|
||||
@ -119,6 +120,14 @@
|
||||
"key": document.getElementById("panicKey").value || "",
|
||||
"url": document.getElementById("panicURL").value || ""
|
||||
}));
|
||||
});
|
||||
document.getElementById("toggleCDN").addEventListener("change", () => {
|
||||
let toggle = document.getElementById("toggleCDN");
|
||||
if(toggle.checked) {
|
||||
localStorage.removeItem("selenite.disableCDN");
|
||||
} else {
|
||||
localStorage.setItem("selenite.disableCDN", "true")
|
||||
}
|
||||
})
|
||||
function generatePallete(color) {
|
||||
let theme = {};
|
||||
@ -239,6 +248,7 @@
|
||||
<button onclick="uploadData()">upload</button>
|
||||
<button onclick="wipeData()">wipe (erases all game data)</button>
|
||||
<button onclick="deleteAllCaches()">wipe all cache</button>
|
||||
<input id="toggleCDN" name="toggleCDN" type="checkbox"></inpuit> <label for="toggleCDN">cdn enabled</label>
|
||||
</section>
|
||||
</sections>
|
||||
</body>
|
||||
|
||||
37
sw.js
37
sw.js
@ -2,17 +2,50 @@ importScripts(
|
||||
'https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'
|
||||
);
|
||||
|
||||
let localStorageData = {
|
||||
cdns: [],
|
||||
disableCDN: true,
|
||||
};
|
||||
// yandere sim big files, cuphead, renpy, renpy, buckshot roulette, half life, undertale & deltarune, hollow knight
|
||||
let cacheable_files = ["YandereSim.data", "cuphead/Build/Build.data.unityweb.", "renpy.data", "game.zip", "buckshot-roulette.pck", "halva_en-", "game.unx", "bog.data"];
|
||||
|
||||
self.addEventListener("message", e => {
|
||||
if(e.data && e.data.type == "localStorage") {
|
||||
localStorageData = e.data;
|
||||
console.log(localStorageData);
|
||||
}
|
||||
});
|
||||
|
||||
if(workbox) {
|
||||
self.skipWaiting();
|
||||
workbox.core.clientsClaim();
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
({url}) => {
|
||||
console.log(localStorageData)
|
||||
if(localStorageData.disableCDN) return false;
|
||||
if(localStorageData.cdns.length == 0) return false;
|
||||
if(url.origin != location.origin) return false;
|
||||
if(!url.pathname.includes("/resources/")) return false;
|
||||
for (const file of cacheable_files) {
|
||||
if(url.pathname.includes(file)) return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
async ({url}) => {
|
||||
let cdn = localStorageData.cdns[0];
|
||||
console.warn(url.href);
|
||||
return Response.redirect(cdn + url.pathname, 302);
|
||||
}
|
||||
);
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
/\.(?:png|gif|jpg|jpeg|svg|webp|avif|gif)$/,
|
||||
new workbox.strategies.CacheFirst({
|
||||
cacheName: 'images-cache',
|
||||
plugins: [
|
||||
new workbox.expiration.ExpirationPlugin({
|
||||
maxEntries: 600,
|
||||
maxEntries: 1200,
|
||||
maxAgeSeconds: 365 * 24 * 60 * 60,
|
||||
}),
|
||||
],
|
||||
@ -24,7 +57,7 @@ if(workbox) {
|
||||
cacheName: 'resources-cache',
|
||||
plugins: [
|
||||
new workbox.expiration.ExpirationPlugin({
|
||||
maxEntries: 100,
|
||||
maxEntries: 500,
|
||||
maxAgeSeconds: 365 * 24 * 60 * 60,
|
||||
}),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user