生成单词释义
使用 API Ninjas 提供的 API 词典在文档中生成单词释义。
要使用此宏,您需要从 API Ninjas 获取您自己的 API 密钥。
(function () {
let doc = Api.GetDocument();
let range = doc.GetRangeBySelect();
let word = range.GetText();
$.ajax({
method: "GET",
url: "https://api.api-ninjas.com/v1/dictionary?word=" + word,
headers: { "X-Api-Key": "your-api-key" },
contentType: "application/json",
success: function (result) {
let text = result.definition;
let paragraph = Api.CreateParagraph();
paragraph.AddText(text);
doc.InsertContent([paragraph], { KeepTextOnly: true });
},
error: function ajaxError(jqXHR) {
console.error("Error: ", jqXHR.responseText);
},
});
})();
使用方法: GetDocument, GetRangeBySelect, GetText, CreateParagraph, AddText, InsertContent