您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
用户脚本版的百度翻译API支持,无需申请token,@require即用
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/452362/1100147/Baidu%20Translate.js
百度翻译API 用户脚本版
无需向百度申请开发者令牌,@require即可使用
用法:
baidu_translate(details): details = { text: Text you want to translate. Required argument, no default value. callback: Callback function when translation succeed, e.g. function(result) {console.log(result);}. Argument `result` will be translate result. Required argument, no default value. [src]: Source language; e.g. 'zh' for Chinese, 'en' for English, 'ja' for Japanese, .... Default: Auto detect. [dst]: Destination language, Default: 'zh'. [split]: Text spliting max length, just leave blank if you don't know what this means. What it is: Baidu has limited that up to 5000 letters can be translated each single API request, so the translate function will split text by about every ${split} letters, and translates each of them with a single API request then concatenate the translate result together again. Don't worry if any sentence to be splited, actually the translate function splits text with '\n' first, then concatenate the '\n'-splited strings as long as possible while keeping its length <= ${split}. Default: 5000 [onerror]: Callback function when translation failed, e.g. function(reason) {console.log(reason);}. Argument: `reason` may be anything that causes its failure, just for debugging and do not use it in production. Default: function() {}. [retry]: Times to retry before onerror function being called or an error being thrown, Default: 3. } Or: baidu_translate(text, src, dst, callback, onerror, split, retry) Overloads: baidu_translate(text, src, dst, callback, onerror, split) baidu_translate(text, dst, callback, onerror, split) baidu_translate(text, callback, onerror, split) baidu_translate(text, callback, onerror) baidu_translate(text, callback) Important Note: baidu_translate needs to be initialized before using. Don't worry, the initialization is automatic, just callbdTransReady(callback)
to get your callback function called while initialized. 注意: 百度翻译需要一定时间来进行初始化,请把需要用到baidu_translate的代码放在bdTransReady(callback)
的回调函数中执行。 示例代码: // ==UserScript== // @name Baidu translate API test // @name:zh-CN 百度翻译API测试 // @name:en Baidu translate API test // @namespace Baidu-API-Test // @version 0.1 // @description Baidu translate API test script // @description:zh-CN 百度翻译API测试脚本 // @description:en Baidu translate API test script // @author PY-DNG // @license WTFPL - See https://www.wtfpl.net/ // @match https://gf.qytechs.cn/zh-CN/scripts/452362-baidu-translate // @require https://gf.qytechs.cn/scripts/452362-baidu-translate/code/Baidu%20Translate.js // @grant GM_xmlhttpRequest // @connect fanyi.baidu.com // ==/UserScript== (function __MAIN__() { bdTransReady(function() { baidu_translate({ text: '欢迎来到 Greasy Fork镜像,这里是一个提供用户脚本的网站。', dst: 'en', callback: function(result_text) { console.log(result_text); }, onerror: function(reason) { console.log('something unexpected happened'); debugger; } }); }); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址