Compare commits

...

6 Commits
0.2.0 ... main

Author SHA1 Message Date
Bauke ccb0968b18
Version 0.3.1! 2022-12-09 17:48:28 +01:00
Bauke 2727eb51b7
Idiot. 🤦 2022-12-09 17:47:55 +01:00
Bauke 2e579f350d
Version 0.3.0! 2022-12-09 17:32:56 +01:00
Bauke 6274e51752
Replace local storage usage with sync storage. 2022-12-05 14:50:33 +01:00
Bauke ed29853516
Transfer local storage to sync storage on new installs. 2022-12-05 14:47:42 +01:00
Bauke fe06822b24
Add a check for google.com for bangs. 2022-12-05 14:39:22 +01:00
3 changed files with 18 additions and 7 deletions

View File

@ -16,11 +16,22 @@ browser.runtime.onInstalled.addListener(async () => {
if (import.meta.env.DEV) {
await browser.runtime.openOptionsPage();
}
const {dataVersion} = await browser.storage.sync.get({
dataVersion: '0',
});
if (dataVersion === '0') {
const local = await browser.storage.local.get();
local.dataVersion = '1';
await browser.storage.sync.set(local);
}
});
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
const detailsUrl = new URL(details.url);
if (detailsUrl.host !== 'duckduckgo.com') {
const supportedHosts = ['duckduckgo.com', 'google.com', 'www.google.com'];
if (!supportedHosts.includes(detailsUrl.host)) {
return;
}
@ -34,7 +45,7 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
return;
}
const data = await browser.storage.local.get(id);
const data = await browser.storage.sync.get(id);
if (data[id] === undefined) {
return;
}

View File

@ -7,7 +7,7 @@ export default function createManifest(
name: 'Fangs',
description:
'Inject custom DuckDuckGo Bangs into your browsing experience.',
version: '0.2.0',
version: '0.3.1',
permissions: ['storage', 'webNavigation'],
options_ui: {
page: 'options/index.html',

View File

@ -34,9 +34,9 @@ export class PageMain extends Component<Props, State> {
}
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('!'))
.map(([_key, bang]) => bang as BangParameters)
.sort((a, b) => a.id.localeCompare(b.id));
@ -67,7 +67,7 @@ export class PageMain extends Component<Props, State> {
return;
}
await browser.storage.local.remove(id);
await browser.storage.sync.remove(id);
const bangs = this.state.bangs;
const existingIndex = bangs.findIndex((bang) => bang.id === id);
@ -88,7 +88,7 @@ export class PageMain extends Component<Props, State> {
if (Bang.validate(bang)) {
const update: Record<string, BangParameters> = {};
update[bang.id] = bang;
await browser.storage.local.set(update);
await browser.storage.sync.set(update);
}
} catch (error: unknown) {
if (error instanceof Error) {