Last active
August 8, 2022 14:33
-
-
Save amoghs/613dff37e6cf0820480fd204b6655818 to your computer and use it in GitHub Desktop.
A script to upload eesel data
This file contains 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
;(() => { | |
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