Skip to content
HangoverHangover
首页
项目收藏
留言板
github icon
  • 文章

      • 油猴 API
        • 免费翻译API
          • 百度翻译API

        免费翻译API

        author iconHangovercalendar icon2022年4月24日category icon
        • 油猴脚本
        tag icon
        • 油猴
        • 脚本猫
        • 翻译
        timer icon小于 1 分钟

        免费翻译API DEMO

        将剪切板内容翻译后再放入剪切板

        // ==UserScript==
        // @name         免费翻译API
        // @namespace    https://bbs.tampermonkey.net.cn/
        // @version      0.1.0
        // @description  try to take over the world!
        // @author       张仨
        // @match        *://*/*
        // @grant        unsafeWindow
        // @grant        GM_xmlhttpRequest
        // ==/UserScript==
        
        document.addEventListener("copy", () => { // 监听复制
            navigator.clipboard.readText() // 获取剪切板内容
                .then(value => {
                    GM_xmlhttpRequest({
                        method: "GET",
                        responseType: "json",
                        url: `https://api.66mz8.com/api/translation.php?info=${value}`,
                        onload: function (xhr) {
                            if (xhr.readyState === 4 && xhr.status === 200) {
                                switch (xhr.response.code) {
                                    case 200:
                                        navigator.clipboard.writeText(xhr.response.fanyi); // 将翻译后内容放入剪切板
                                        break;
                                    case 201:
                                        alert("翻译参数不能为空");
                                        break;
                                    case 202:
                                        alert("翻译参数查询异常");
                                        break;
                                    default:
                                        alert("未知错误");
                                        break;
                                }
                            } else {
                                alert("服务器无响应或请求出错")
                            }
                        }
                    })
                })
                .catch(err => {
                    console.log(err)
                })
        })
        
        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
        上一页
        油猴 API
        下一页
        百度翻译API
        鸟无声兮山寂寂,夜正长兮风淅淅。 ──李华《吊古战场文》
        Copyright © 2023 Hangover