-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConcept.js
66 lines (60 loc) · 2 KB
/
Concept.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// noinspection JSUnusedGlobalSymbols
/**
* Create the "Analyze" menu entry, and bind it to openSidebar
*/
function onOpen() {
DocumentApp.getUi()
.createAddonMenu()
.addItem("Analyze", 'showSidebar')
.addToUi();
}
/**
* Show the sidebar to the user (only works with the regular add-on, not the mobile version)
*/
function showSidebar() {
const sidebar = HtmlService.createTemplateFromFile("Sidebar").evaluate();
sidebar.setTitle("Concept");
DocumentApp.getUi().showSidebar(sidebar);
}
// noinspection JSUnusedGlobalSymbols
/**
* Used to include CSS and JS separately from HTML
*/
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
// noinspection JSUnusedGlobalSymbols
function createAnnotationRequest() {
const payload = {
document: {
type: "PLAIN_TEXT",
language: DocumentApp.getActiveDocument().getLanguage(),
content: DocumentApp.getActiveDocument().getBody().getText()
},
features: {
extractSyntax: true,
extractEntities: true,
extractDocumentSentiment: true,
extractEntitySentiment: true,
classifyText: DocumentApp.getActiveDocument().getBody().getText().length >= 20,
},
encodingType: "UTF16"
};
return [payload, {
"Authorization": `Bearer ${ScriptApp.getOAuthToken()}`,
"Content-Type": "application/json"
}];
}
/**
* Sets the user's cursor position to the specified offset relative to the entire document.
*
* @param offset the offset of the text in the document's body
* @param text the text that will be selected
*/
function setSelectionByOffset(offset, text) {
const body = DocumentApp.getActiveDocument().getBody().editAsText();
const rangeBuilder = DocumentApp.getActiveDocument().newRange();
rangeBuilder.addElement(body, offset, offset + text.length - 1);
DocumentApp.getActiveDocument().setSelection(rangeBuilder.build());
}