Skip to content

Instantly share code, notes, and snippets.

@niikoo
Created June 24, 2019 18:19
Show Gist options
  • Save niikoo/5ef128932046d294c75da8682880780a to your computer and use it in GitHub Desktop.
Save niikoo/5ef128932046d294c75da8682880780a to your computer and use it in GitHub Desktop.
WIP: Add multiple words (csv list) to google docs personal directory
((raw) => {
if(raw == null || raw === '') throw new Error('No data provided');
let data = raw.split(';');
if(data.length === 1) {
data = raw.split(',');
}
if(data.length < 1) {
throw new Error('No words to add...');
}
if(!confirm(`Are you sure you want to add '${data[0]}' and ${data.length - 1} other words?`))
return;
function triggerMouseEvent(node, eventType) {
const clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
}
const input = document.querySelector('.docs-userdictionarydialog-input');
const button = document.querySelector('.docs-userdictionarydialog-button-add');
addWord = (remaining) => {
input.value = ('' + remaining.pop()).trim();
setTimeout(() => {
triggerMouseEvent(button, 'mousedown');
triggerMouseEvent(button, 'mouseup');
addWord(remaining.splice());
}, 50);
};
setTimeout(addWord(data), 100);
})(prompt('CSV list of words to add to personal dictionary'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment