Created
November 10, 2016 16:34
-
-
Save rheajt/8b0af789577bb62701c312f04f3a8c60 to your computer and use it in GitHub Desktop.
Vocabulary Sidebar for Google Documents
This file contains hidden or 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
| var MW_KEY = ''; | |
| function onOpen() { | |
| DocumentApp.getUi() | |
| .createAddonMenu() | |
| .addItem('Get vocabulary words', 'openSidebar') | |
| .addToUi(); | |
| } | |
| function openSidebar() { | |
| var html = HtmlService.createHtmlOutputFromFile('Vocabulary') | |
| .setTitle('Vocabulary'); | |
| DocumentApp.getUi().showSidebar(html); | |
| } | |
| function fetchVocabulary(vocab) { | |
| //use http://www.dictionaryapi.com/ with UrlFetch to find vocabulary words | |
| var doc = DocumentApp.getActiveDocument(); | |
| var body = doc.getBody(); | |
| for(var i = 0; i < vocab.length; i++) { | |
| body.appendParagraph(vocab[i]); | |
| } | |
| } |
This file contains hidden or 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
| <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
| <section class="sidebar"> | |
| <div class="form-group"> | |
| <textarea id="vocabulary-words" rows="10" style="width:100%"></textarea> | |
| </div> | |
| <div class="block"> | |
| <button type="button" id="vocabulary-submit" class="blue">Submit</button> | |
| <button id="sidebar-close">Cancel</button> | |
| </div> | |
| </section> | |
| <script> | |
| function vocabularySubmit() { | |
| var vocabulary = document.getElementById('vocabulary-words').value.split('\r\n'); | |
| google.script.run | |
| .withSuccessHandler(closeSidebar) | |
| .withFailureHandler(showError) | |
| .fetchVocabulary(vocabulary); | |
| } | |
| function closeSidebar() { | |
| google.script.host.close(); | |
| } | |
| function showError(err) { | |
| console.log(err); | |
| } | |
| document.getElementById('vocabulary-submit').addEventListener('click', vocabularySubmit); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment