Created
January 17, 2019 21:17
-
-
Save nlaz/4ab832e442cad69a999220bd8e2d9350 to your computer and use it in GitHub Desktop.
Script to add emoji shortcuts to Google Docs
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
/** | |
* This script will help you add emojis shortcuts to your Google Docs | |
* to be used as shortcuts. | |
*/ | |
/* Step 1: Open your Google Docs Preferences (Tools > Preferences) */ | |
/* Step 2: Open your Chrome Devtools ( View > Developer > Developer Tools )*/ | |
/* Step 3: Paste the following code in your Chrome Console */ | |
/** | |
* Important Disclaimer: Don't just copy-paste random code into your | |
* Chrome Console. That's how bad things happen. Only use this script | |
* if you are comfortable that nothing bad will happen. | |
*/ | |
const emojis = [ | |
{"emoji": "๐", "shortname": ":heart_eyes:" }, | |
{"emoji": "๐ญ", "shortname": ":sob:" }, | |
{"emoji": "๐", "shortname": ":blush:" }, | |
{"emoji": "๐", "shortname": ":unamused:" }, | |
{"emoji": "๐", "shortname": ":kissing_heart:" }, | |
// ... | |
// Fill out the rest of the emojis you want to use. Here's a good source: | |
// https://gist.github.com/oliveratgithub/0bf11a9aff0d6da7b46f1490f86a71eb | |
]; | |
const table = document.getElementById("docs-stringreplacementtable-body"); | |
// Used to trigger a new row for the shortcuts table | |
const dispatchKeyboardEvent = function(target, initKeyboradEvent_args) { | |
const e = document.createEvent("KeyboardEvents"); | |
e.initKeyboardEvent.apply(e, Array.prototype.slice.call(arguments, 1)); | |
target.dispatchEvent(e); | |
}; | |
emojis.forEach(item => { | |
let row = table.querySelectorAll(".docs-preferencesdialog-row")[0]; | |
let replaceInput = row.querySelector('.docs-preferencesdialog-input[title="New substitution. Replace"]'); | |
let withInput = row.querySelector('.docs-preferencesdialog-input[title="With"]'); | |
replaceInput.value = item.shortname; | |
withInput.value = item.emoji; | |
// The only way to add a new row is to trigger a fake keypress. | |
dispatchKeyboardEvent(row, "keyup", true, true, null, " ", 0, ""); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment