Lingoes API Server Guide
Overview
Lingoes API 服务可以让开发者在浏览器或其他软件中通过发送标准的 HTTP 请求, 来调用灵格斯的屏幕取词, 词典查询及文本翻译功能,
目前 API 服务为实验性功能,
如果你有什么想法和需求, 请发邮件至 kevin-yau@msn.com 和我联络.
Development Ready
API Guide
NOTE: 在浏览器中调用本地 Lingoes API 服务会产生 AJax 跨域请求, Lingoes API
服务器已提供 Cross-Origin Resource Sharing (CORS) 自动跨域授权访问技术, 支持目前所有最新版本的浏览器,
开发者无需做任何特别的设置就可以直接发送跨域请求.
1. 在指定位置显示屏幕取词窗口:
http://127.0.0.1:11111/lingoes?cmd=mini_search&text=文字&pos_x=窗口X坐标&pos_y=窗口Y坐标
详细说明 >>
2. 查询词典, 并在指定位置显示 Lingoes 主窗口:
http://127.0.0.1:11111/lingoes?cmd=main_search&text=文字&pos_x=窗口X坐标&pos_y=窗口Y坐标
详细说明 >>
3. 翻译文字, 并在指定位置显示 Lingoes 主窗口:
http://127.0.0.1:11111/lingoes?cmd=main_translator&text=文字&pos_x=窗口X坐标&pos_y=窗口Y坐标
详细说明 >>
Code and Sample
Sample: (请确认灵格斯当前正在运行, 并且启用了 API 服务器)
Word or Text:
Window Posit X:
Window Posit Y:
Source Code:
<script type="text/javascript"> var request = new XMLHttpRequest(); function OnApiCallback() { if (request.readyState == 4) { if (request.status == 200) { var jResult = JSON.parse(request.responseText); document.getElementById("lgs_api_result").innerText = JSON.stringify(jResult); } else { document.getElementById("lgs_api_result").innerText = "Error: status code is " + request.status; } } } // Call Lingoes API function CallLingoesApi(sCmd) { var sText = document.getElementById("text").value; var sPosX = document.getElementById("pos_x").value; var sPosY = document.getElementById("pos_y").value; sText = encodeURIComponent(sText); sPosX = encodeURIComponent(sPosX); sPosY = encodeURIComponent(sPosY); var content = "cmd=" + sCmd + "&text=" + sText + "&pos_x=" + sPosX + "&pos_y=" + sPosY; var url = "http://127.0.0.1:11111/lingoes?" + content; request.open("GET", url, true); // 指定回调函数 request.onreadystatechange = OnApiCallback; // 发送请求 request.setRequestHeader("Cache-Control", "no-cache"); request.setRequestHeader("Pragma", "no-cache"); request.send(null); document.getElementById("lgs_api_result").innerText = "Wait Lingoes API Server Response..."; } </script> <div style="border:1px solid #e0e0e0; padding:10px; margin:10px 0 10px 0; background-color:#fafafa"> <div>Word or Text: <input type="text" name="text" id="text" size="60" value="How are you"></div> <div>Window X Posit: <input type="text" name="pos_x" id="pos_x" size="20"></div> <div>Window Y Posit: <input type="text" name="pos_y" id="pos_y" size="20"></div> <div style="margin: 10px 0 10px 0"> <button id="act" onclick="CallLingoesApi('mini_search')" onmouseover="">View Mini Window</button> <button id="act" onclick="CallLingoesApi('main_search')" onmouseover="">Search Word</button> <button id="act" onclick="CallLingoesApi('main_translator')" onmouseover="">Translator Text</button> </div> <div id="lgs_api_result" style="margin-top: 10px; font-weight:bold"></div> </div> |
© Lingoes Project, All Rights Reserved |