Skip to content

Instantly share code, notes, and snippets.

@nlaz
Created January 17, 2019 21:17
Show Gist options
  • Save nlaz/4ab832e442cad69a999220bd8e2d9350 to your computer and use it in GitHub Desktop.
Save nlaz/4ab832e442cad69a999220bd8e2d9350 to your computer and use it in GitHub Desktop.
Script to add emoji shortcuts to Google Docs
/**
* 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