request persistence for the iframe indexDB (#19105)

* request persistence for the iframe indexDB

* new  min js

* also format this

* .
This commit is contained in:
Kashargul
2026-02-01 21:22:20 +01:00
committed by GitHub
parent 4132c25f0b
commit fb673e1be2
5 changed files with 50 additions and 54 deletions
+9 -9
View File
@@ -55,24 +55,24 @@ function filterchanges(type){
}
*/
function dropdowns() {
var drops = $("div.drop");
var indrops = $("div.indrop");
if (drops.length != indrops.length) {
alert("Some coder fucked up with dropdowns");
const drops = $('div.drop');
const indrops = $('div.indrop');
if (drops.length !== indrops.length) {
alert('Some coder fucked up with dropdowns');
}
drops.each(function (index) {
$(this).toggleClass("closed");
$(this).toggleClass('closed');
$(indrops[index]).hide();
$(this).click(function () {
$(this).toggleClass("closed");
$(this).toggleClass("open");
$(this).toggleClass('closed');
$(this).toggleClass('open');
$(indrops[index]).toggle();
});
});
}
function filterchanges(type) {
$("ul.changes li").each(function () {
$('ul.changes li').each(function () {
if (!type || $(this).hasClass(type)) {
$(this).show();
} else {
@@ -81,6 +81,6 @@ function filterchanges(type) {
});
}
$(document).ready(function () {
$(document).ready(() => {
dropdowns();
});
+17 -17
View File
@@ -2,21 +2,21 @@ let webSocket;
let authKey;
let lastCall;
const reactRoot = document.getElementById("react-root");
const reactRoot = document.getElementById('react-root');
if (reactRoot) {
reactRoot.innerHTML =
"<h1>You shouldn't see this window, update your skin.</h1>";
}
Byond.subscribeTo("estop", function () {
Byond.subscribeTo('estop', () => {
if (webSocket) {
webSocket.close();
} else {
Byond.sendMessage("disconnected");
Byond.sendMessage('disconnected');
}
});
Byond.subscribeTo("connect", function (data) {
Byond.subscribeTo('connect', (data) => {
if (webSocket) {
webSocket.close();
}
@@ -24,29 +24,29 @@ Byond.subscribeTo("connect", function (data) {
webSocket.sendJson = (data) => {
webSocket.send(JSON.stringify(data));
};
authKey = JSON.parse(window.hubStorage.getItem("virgo-shocker-authkey"));
authKey = JSON.parse(window.hubStorage.getItem('virgo-shocker-authkey'));
webSocket.onopen = (ev) => {
Byond.sendMessage("connected");
Byond.sendMessage('connected');
};
webSocket.onerror = (ev) => {
Byond.sendMessage("error", ev);
Byond.sendMessage('error', ev);
};
webSocket.onclose = (ev) => {
Byond.sendMessage("disconnected");
Byond.sendMessage('disconnected');
};
webSocket.onmessage = (ev) => {
Byond.sendMessage("incomingMessage", { data: ev.data, lastCall });
Byond.sendMessage('incomingMessage', { data: ev.data, lastCall });
};
});
Byond.subscribeTo("enumerateShockers", function () {
Byond.subscribeTo('enumerateShockers', () => {
if (!webSocket) {
return;
}
lastCall = "get_devices";
lastCall = 'get_devices';
webSocket.sendJson({
cmd: "get_devices",
cmd: 'get_devices',
auth_key: authKey,
});
});
@@ -57,19 +57,19 @@ Byond.subscribeTo("enumerateShockers", function () {
// "shocker_ids": [], // [] - List of shocker ids
// "warning": false, // true, false - will send a vibrate with the same intensity and duration
// },
Byond.subscribeTo("shock", function (data) {
Byond.subscribeTo('shock', (data) => {
if (!webSocket) {
return;
}
lastCall = "operate";
lastCall = 'operate';
webSocket.sendJson({
cmd: "operate",
cmd: 'operate',
value: {
intensity: data.intensity, // 1 - 100 - int
duration: data.duration, // 0.1 - 15 - float
shocker_option: "all", // all, random
action: "shock", // shock, vibrate, beep, end
shocker_option: 'all', // all, random
action: 'shock', // shock, vibrate, beep, end
shocker_ids: data.shocker_ids, // [] - List of shocker ids
device_ids: [], // [] - list of pishock client ids, if one of these is provided it will activate all shockers associated with it
warning: data.warning, // true, false - will send a vibrate with the same intensity and duration
+13 -25
View File
@@ -16,7 +16,7 @@
};
const parseMetaTag = function (name) {
const content = document.getElementById(name).getAttribute('content');
if (content === '[' + name + ']') {
if (content === `[${name}]`) {
return null;
}
return content;
@@ -81,7 +81,7 @@
return;
}
// Build the URL
let url = (path || '') + '?';
let url = `${path || ''}?`;
let i = 0;
if (params) {
for (const key in params) {
@@ -93,20 +93,20 @@
if (value === null || value === undefined) {
value = '';
}
url += encodeURIComponent(key) + '=' + encodeURIComponent(value);
url += `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
}
}
}
// If we're a Chromium client, just use the fancy method
if (window.cef_to_byond) {
cef_to_byond('byond://' + url);
cef_to_byond(`byond://${url}`);
return;
}
// Perform a standard call via location.href
if (url.length < 2048) {
location.href = 'byond://' + url;
location.href = `byond://${url}`;
return;
}
// Send an HTTP request to DreamSeeker's HTTP server.
@@ -127,7 +127,7 @@
Byond.call(
path,
assign({}, params, {
callback: 'Byond.__callbacks__[' + index + ']',
callback: `Byond.__callbacks__[${index}]`,
})
);
return promise;
@@ -181,7 +181,7 @@
try {
return JSON.parse(json, byondJsonReviver);
} catch (err) {
throw new Error('JSON parsing error: ' + (err && err.message));
throw new Error(`JSON parsing error: ${err?.message}`);
}
};
@@ -293,16 +293,9 @@
// Generic retry function
const retry = function () {
if (attempt >= RETRY_ATTEMPTS) {
let errorMessage =
'Error: Failed to load the asset ' +
"'" +
url +
"' after several attempts.";
let errorMessage = `Error: Failed to load the asset '${url}' after several attempts.`;
if (type === 'css') {
errorMessage +=
+'\nStylesheet was either not found, ' +
"or you're trying to load an empty stylesheet " +
'that has no CSS rules in it.';
errorMessage += `\nStylesheet was either not found, or you're trying to load an empty stylesheet that has no CSS rules in it.`;
}
throw new Error(errorMessage);
}
@@ -425,10 +418,7 @@ window.onerror = function (msg, url, line, col, error) {
let stack = error && error.stack;
// Ghetto stacktrace
if (!stack) {
stack = msg + '\n at ' + url + ':' + line;
if (col) {
stack += ':' + col;
}
stack = `${msg}\n at ${url}:${line}${col ? `:${col}` : ''}`;
}
// Augment the stack
stack = window.__augmentStack__(stack, error);
@@ -486,7 +476,7 @@ window.onunhandledrejection = function (e) {
if (e.reason) {
msg += ': ' + (e.reason.message || e.reason.description || e.reason);
if (e.reason.stack) {
e.reason.stack = 'UnhandledRejection: ' + e.reason.stack;
e.reason.stack = `UnhandledRejection: ${e.reason.stack}`;
}
}
window.onerror(msg, null, null, null, e.reason);
@@ -494,7 +484,7 @@ window.onunhandledrejection = function (e) {
// Helper for augmenting stack traces on fatal errors
window.__augmentStack__ = function (stack, error) {
return stack + '\nUser Agent: ' + navigator.userAgent;
return `${stack}\nUser Agent: ${navigator.userAgent}`;
};
// Incoming message handling
@@ -552,8 +542,6 @@ window.replaceHtml = function (inline_html) {
document.body.insertAdjacentHTML(
'afterbegin',
'<!-- tgui:inline-html-start -->' +
inline_html +
'<!-- tgui:inline-html-end -->'
`<!-- tgui:inline-html-start -->${inline_html}<!-- tgui:inline-html-end -->`
);
};
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -2
View File
@@ -17,6 +17,14 @@
const urlParams = new URLSearchParams(window.location.search);
const storeValue = `${urlParams.get('store')}-${INDEXED_DB_NAME}`;
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persist().then((persistent) => {
console.log(
`Indexed DB state: ${persistent ? 'Persistent' : 'Not persistent'}`,
);
});
}
const dbPromise = new Promise((resolve, reject) => {
const indexedDB = window.indexedDB;
const req = indexedDB.open(storeValue, INDEXED_DB_VERSION);
@@ -26,14 +34,14 @@
req.result.createObjectStore(INDEXED_DB_STORE_NAME);
}
} catch (err) {
reject(new Error('Failed to upgrade IDB: ' + req.error));
reject(new Error(`Failed to upgrade IDB: ${req.error}`));
}
};
req.onsuccess = () => resolve(req.result);
req.onerror = () => {
reject(new Error('Failed to open IDB: ' + req.error));
reject(new Error(`Failed to open IDB: ${req.error}`));
};
});