READTHEDOCS.IO

try to take over the world!

目前為 2020-05-27 提交的版本,檢視 最新版本

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

(function() {
    'use strict';

    const requestUrl = location.protocol === "https:" ? "https://www.sunibas.cn:8890/" : "http://www.sunibas.cn:8890/";
    window.$jq = jQuery;
    window.$tran = function(text) {
        return new Promise(function(s,f) {
            GM_xmlhttpRequest({
                method: "get",
                url: requestUrl + encodeURI(text),
                onload: function(res){
                    s(res.responseText);
                }
            });
        });
    }
    window.$tran_bak = function (list) {
        return fetch(requestUrl + encodeURI(list), {
            headers: {
                "Content-Type": "application/json",
            },
            method: "post"
        }).then(_ => _.text());
    }
    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);
        jQuery('body').append(jQuery(`
<div id="fixLoc" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
<div onclick="justLoc(-1)" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
<div onclick="closeFixLoc()" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
<div onclick="justLoc(1)" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
</div>`))
        window.closeFixLoc = function() {
            jQuery("#fixLoc")[0].style.display = "none";
        }
        window.currentLoc = 0;
        window.justLoc = function(tar) {
            let cloc = currentLoc + tar * 50;
            if (cloc < 0) {
                return;
            } else {
                let cp = $('.copy');
                cp[0].style.marginTop = cloc + "px"
            }
        }

        setTimeout(function(){
            $tranPElement('.copy .document p,.copy .document li');
        },1000);
    }
    // Your code here...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址