This commit is contained in:
velzie 2024-07-19 13:53:01 -04:00
commit f70e2a6ff4
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -8,8 +8,7 @@ const store = new IDBMapSync(locationProxy.host, {
await store.sync(); await store.sync();
function storageProxy(scope: Storage): Storage { const localStorageProxy = new Proxy(window.localStorage, {
return new Proxy(scope, {
get(target, prop) { get(target, prop) {
switch (prop) { switch (prop) {
case "getItem": case "getItem":
@ -62,10 +61,59 @@ function storageProxy(scope: Storage): Storage {
return true; return true;
}, },
}); });
const sessionStorageProxy = new Proxy(window.sessionStorage, {
get(target, prop) {
switch (prop) {
case "getItem":
return (key: string) => {
return target.getItem(locationProxy.host + "@" + key);
} }
const localStorageProxy = storageProxy(window.localStorage); case "setItem":
const sessionStorageProxy = storageProxy(window.sessionStorage); return (key: string, value: string) => {
target.setItem(locationProxy.host + "@" + key, value);
}
case "removeItem":
return (key: string) => {
target.removeItem(locationProxy.host + "@" + key);
}
case "clear":
return () => {
for (const key in Object.keys(target)) {
if (key.startsWith(locationProxy.host)) {
target.removeItem(key);
}
}
}
case "key":
return (index: number) => {
const keys = Object.keys(target).filter((key) => key.startsWith(locationProxy.host));
return target.getItem(keys[index]);
}
case "length":
return target.length;
default:
if (prop in Object.prototype) {
return Reflect.get(target, prop);
}
return target.getItem(locationProxy.host + "@" + (prop as string));
}
},
defineProperty(target, property, attributes) {
target.setItem(locationProxy.host + "@" + (property as string), attributes.value);
return true;
},
});
delete window.localStorage; delete window.localStorage;
delete window.sessionStorage; delete window.sessionStorage;