Created
March 28, 2020 04:09
-
-
Save saicharanreddyk/d618c603d3b923365087b77a43e1e24c to your computer and use it in GitHub Desktop.
To import settings from a JSON file created using the script above
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
(async function importSEs() { | |
/* Auxiliary function to open a file selection dialog */ | |
function selectFileToRead() { | |
return new Promise((resolve) => { | |
const input = document.createElement('input'); | |
input.setAttribute('type', 'file'); | |
input.addEventListener('change', (e) => { | |
resolve(e.target.files[0]); | |
}, false); | |
input.click(); | |
}); | |
} | |
/* Auxiliary function to read data from a file */ | |
function readFile(file) { | |
return new Promise((resolve) => { | |
const reader = new FileReader(); | |
reader.addEventListener('load', (e) => { | |
resolve(e.target.result); | |
}); | |
reader.readAsText(file); | |
}); | |
} | |
const file = await selectFileToRead(); | |
const content = await readFile(file); | |
const searchEngines = JSON.parse(content); | |
searchEngines.forEach(({ name, keyword, url }) => { | |
/* Actual search engine import magic */ | |
chrome.send('searchEngineEditStarted', [-1]); | |
chrome.send('searchEngineEditCompleted', [name, keyword, url]); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment