mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
Merge branch 'main' of https://github.com/MercuryWorkshop/aerojet
This commit is contained in:
commit
f70e2a6ff4
1 changed files with 97 additions and 49 deletions
|
@ -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":
|
||||||
|
@ -61,11 +60,60 @@ function storageProxy(scope: Storage): Storage {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
const localStorageProxy = storageProxy(window.localStorage);
|
const sessionStorageProxy = new Proxy(window.sessionStorage, {
|
||||||
const sessionStorageProxy = storageProxy(window.sessionStorage);
|
get(target, prop) {
|
||||||
|
switch (prop) {
|
||||||
|
case "getItem":
|
||||||
|
return (key: string) => {
|
||||||
|
return target.getItem(locationProxy.host + "@" + key);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "setItem":
|
||||||
|
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue