Skip to content

Instantly share code, notes, and snippets.

@amoghs
Last active August 8, 2022 14:33
Show Gist options
  • Save amoghs/613dff37e6cf0820480fd204b6655818 to your computer and use it in GitHub Desktop.
Save amoghs/613dff37e6cf0820480fd204b6655818 to your computer and use it in GitHub Desktop.
A script to upload eesel data
;(() => {
const input = document.createElement('input')
input.type = 'file'
input.addEventListener(
'change',
() => {
const [file] = input.files
const reader = new FileReader()
reader.readAsText(file)
reader.onloadend = () => {
const result = JSON.parse(reader.result)
;(function openTransaction(databaseVersion) {
const request = indexedDB.open('main', databaseVersion)
request.onsuccess = async (event) => {
const db = event.target.result
const objectStoreNameList = Object.keys(result)
const transaction = db.transaction(objectStoreNameList, 'readwrite')
objectStoreNameList.forEach((objectStoreName) => {
const objectStore = transaction.objectStore(objectStoreName)
objectStore.clear().onsuccess = () => {
result[objectStoreName].forEach((value) => {
objectStore.add(value)
})
}
})
transaction.oncomplete = () => {
window.alert('Import complete. The extension will be reloaded')
chrome.runtime.reload()
}
}
request.onerror = async (event) => {
if (databaseVersion < 300) {
openTransaction(databaseVersion + 1)
}
}
})(122)
}
},
false
)
input.click()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment