Last active
April 28, 2020 19:26
-
-
Save neilio/d92614097753bd301c1a42cdf9a59437 to your computer and use it in GitHub Desktop.
Import Chrome search keywords
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
(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