跳到主要内容

Generate word definitions

Generates word definitions in your document using the Dictionary API offered by API Ninjas.

To use this macro, you need to obtain your own API key from API Ninjas.

(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);
},
});
})();

Methods used: GetDocument, GetRangeBySelect, GetText, CreateParagraph, AddText, InsertContent

Result

Generate word definitonsGenerate word definitons