Greasy Fork is available in English.

READTHEDOCS.IO

try to take over the world!

您查看的为 2020-05-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         READTHEDOCS.IO
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://geotrellis.readthedocs.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const requestUrl = location.protocol === "https:" ? "https://www.sunibas.cn/api" : "http://www.sunibas.cn/api";
    window.$jq = jQuery;
    window.$tran = function (list) {
        return fetch(requestUrl, {
            headers: {
                "Content-Type": "application/json",
            },
            method: "post",
            body: JSON.stringify({
                api: "GoogleTranslate",
                method: "fetchTran",
                data: {
                    list: list
                }
            })
        }).then(_ => _.text()).then(JSON.parse).then(_ => _.data.data);
    }
    let tasks = [];
    window.$tranPElement = function (tar) {
        let ps = $jq(tar || 'p');
        for (let i = 0; i < ps.length; i++) {
            tasks.push((function (node) {
                $tran(node.innerText)
                    .then(_ => {
                        $jq(node).replaceWith($jq(`<${node.nodeName} class="ibas_tran">${_}</${node.nodeName}>`));
                        if (tasks.length) {
                            tasks.shift()();
                        } else {
                            //alert("完成");
                        }
                    })
                    .catch(_ => {
                        console.log(_);
                        if (tasks.length) {
                            tasks.shift()();
                        } else {
                            //alert("完成");
                        }
                    })
            }).bind(null, ps[i]));
        }
        if (tasks.length) {
            tasks.shift()();
        } else {
            alert("完成");
        }
    }

    window.onload = function() {
        var content = jQuery('.wy-nav-content');
        var parentDiv = content.parent();
        parentDiv[0].style.background = "#fff";
        content[0].style.float = 'left';
        content[0].style.background = 'darkkhaki';
        var copyContent = jQuery(`<div class="wy-nav-content copy" style="float: left;margin-left:20px;background: beige;">` + content[0].innerHTML + `<div>`);
        parentDiv.append(copyContent);
        setTimeout(function(){
            $tranPElement('.copy .document p,.copy .document li');
        },1000);
    }
    // Your code here...
})();