try to take over the world!
当前为
// ==UserScript==
// @name READTHEDOCS.IO
// @namespace http://tampermonkey.net/
// @version 0.3
// @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);
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"
currentLoc = cloc;
}
}
setTimeout(function(){
$tranPElement('.copy .document p,.copy .document li');
},1000);
}
// Your code here...
})();