Last active
January 20, 2025 20:08
-
-
Save sergiitk/4b099ef3378f088c75566710be0342d7 to your computer and use it in GitHub Desktop.
ext-export-import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run in chrome -> sources -> snippets at | |
// chrome-extension://[extension-id]/window.html | |
async function storageGet(storageType, space = 2) { | |
let storage_fn; | |
if (storageType === 'local') { | |
storage_fn = chrome.storage.local; | |
} else if (storageType === 'sync') { | |
storage_fn = chrome.storage.sync; | |
} else { | |
throw new Error('Wrong storage type'); | |
} | |
// https://developer.chrome.com/docs/extensions/reference/api/storage#method-StorageArea-get | |
const items = await storage_fn.get(null); | |
const result_json = JSON.stringify(items, null, space); | |
console.log(result_json); | |
} | |
await storageGet('sync', space=0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// no guarantees things won't break, use at your discretion | |
// run in chrome -> sources -> snippets at | |
// chrome-extension://[extension-id]/window.html | |
async function storageSet(storageType, json) { | |
let storage_fn; | |
if (storageType === 'local') { | |
storage_fn = chrome.storage.local; | |
} else if (storageType === 'sync') { | |
storage_fn = chrome.storage.sync; | |
} else { | |
throw new Error('Wrong storage type'); | |
} | |
if (!json || !Object.keys(json).length) { | |
throw new Error('Empty json input'); | |
} | |
// https://developer.chrome.com/docs/extensions/reference/api/storage#method-StorageArea-set | |
// uncomment when reaady | |
// await storage_fn.set(json); | |
console.log("Done") | |
} | |
// paste json from the storageGet | |
const json = {}; | |
await storageSet('sync', json); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment