-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskpane.html
57 lines (52 loc) · 2.49 KB
/
taskpane.html
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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js?v=70"></script>
</head>
<body>
<p>Displays suggestion answers for selected text.</p><br>
<button id="suggestionButton">Get Suggestion</button><br><br>
<div id="selectedText"></div>
</body>
<script>
Office.onReady((info) => {
if (info.host === Office.HostType.Word) {
document.getElementById("suggestionButton").onclick = getSuggestionAnswerForAPI;
}
});
function getSuggestionAnswerForAPI() {
return Word.run((context) => {
const range = context.document.getSelection();
range.load('text');
return context.sync()
.then(() => {
const selectedTextElement = document.getElementById("selectedText");
selectedTextElement.innerHTML = "Wait! Looking for suggestions answers...";
var apiURL = 'https://feasibility-api-dev.fhcplayground.com/api/v1/questionnaires/similar-questions?questionnarie=' + range.text;
var requestOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
};
fetch(apiURL, requestOptions)
.then(response => response.json())
.then(data => {
if (data.length === 0) {
selectedTextElement.innerHTML = 'No suggestions for the selected text.';
return;
}
const messages = [];
for (let index = 0; index < data.length; index++) {
messages.push('<b>Question #'+ index+1 +' ('+ data[index].score + '):</b>'+ data[index].questionText +'<br>');
for (let x = 0; x < data[index].answers.length; x++) {
messages.push('<b>Answer #'+ x+1 +':</b> '+ data[index].answers[x].answerText + '<br>');
}
messages.push('<br>');
}
selectedTextElement.innerHTML = messages.join('\n');
})
});
});
}
</script>
</html>