Replace local storage usage with sync storage.
This commit is contained in:
parent
ed29853516
commit
6274e51752
|
@ -45,7 +45,7 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await browser.storage.local.get(id);
|
const data = await browser.storage.sync.get(id);
|
||||||
if (data[id] === undefined) {
|
if (data[id] === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ export class PageMain extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const localStorage = await browser.storage.local.get();
|
const storage = await browser.storage.sync.get();
|
||||||
|
|
||||||
const bangs = Object.entries(localStorage)
|
const bangs = Object.entries(storage)
|
||||||
.filter(([key, _bang]) => key.startsWith('!'))
|
.filter(([key, _bang]) => key.startsWith('!'))
|
||||||
.map(([_key, bang]) => bang as BangParameters)
|
.map(([_key, bang]) => bang as BangParameters)
|
||||||
.sort((a, b) => a.id.localeCompare(b.id));
|
.sort((a, b) => a.id.localeCompare(b.id));
|
||||||
|
@ -67,7 +67,7 @@ export class PageMain extends Component<Props, State> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await browser.storage.local.remove(id);
|
await browser.storage.sync.remove(id);
|
||||||
|
|
||||||
const bangs = this.state.bangs;
|
const bangs = this.state.bangs;
|
||||||
const existingIndex = bangs.findIndex((bang) => bang.id === id);
|
const existingIndex = bangs.findIndex((bang) => bang.id === id);
|
||||||
|
@ -88,7 +88,7 @@ export class PageMain extends Component<Props, State> {
|
||||||
if (Bang.validate(bang)) {
|
if (Bang.validate(bang)) {
|
||||||
const update: Record<string, BangParameters> = {};
|
const update: Record<string, BangParameters> = {};
|
||||||
update[bang.id] = bang;
|
update[bang.id] = bang;
|
||||||
await browser.storage.local.set(update);
|
await browser.storage.sync.set(update);
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
|
Loading…
Reference in New Issue