I am trying to make a chrome extension that adds an extra custom menu to google docs. I have already figured out how to make an extension, and I also have figured out how to make an extra menu in apps script. I just can't figure out how to run the apps script code from the extension. I know that similar questions have been asked, but I am too inexperienced to understand those answers.
Here is my apps script code:
function onOpen() {
const ui = DocumentApp.getUi();
// Creates the extra insert menu
ui.createMenu('Insert Tool')
// .addItem adds a button to the new menu
.addItem('Insert Rickroll', 'insertRickroll')
.addToUi();
}
function insertRickroll() {
// Gets the cursor position
const cursor = DocumentApp.getActiveDocument().getCursor();
// Inserts link text at position
cursor.insertText('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
}
My chrome extension, as of now, just shows some text. It does not run any scripts. Can anybody help me combine the two?
I have tried directly pasting the code into a scripts as part of the extension, but it ended up not working to add the menu in docs. This could have been a result of not actually having anything happen in the extension's script and HTML code other than that copy and paste.