READTHEDOCS.IO

try to take over the world!

当前为 2020-05-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name READTHEDOCS.IO
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://geotrellis.readthedocs.io/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const requestUrl = location.protocol === "https:" ? "https://www.sunibas.cn/api" : "http://www.sunibas.cn/api";
  15. window.$jq = jQuery;
  16. window.$tran = function (list) {
  17. return fetch(requestUrl, {
  18. headers: {
  19. "Content-Type": "application/json",
  20. },
  21. method: "post",
  22. body: JSON.stringify({
  23. api: "GoogleTranslate",
  24. method: "fetchTran",
  25. data: {
  26. list: list
  27. }
  28. })
  29. }).then(_ => _.text()).then(JSON.parse).then(_ => _.data.data);
  30. }
  31. let tasks = [];
  32. window.$tranPElement = function (tar) {
  33. let ps = $jq(tar || 'p');
  34. for (let i = 0; i < ps.length; i++) {
  35. tasks.push((function (node) {
  36. $tran(node.innerText)
  37. .then(_ => {
  38. $jq(node).replaceWith($jq(`<${node.nodeName} class="ibas_tran">${_}</${node.nodeName}>`));
  39. if (tasks.length) {
  40. tasks.shift()();
  41. } else {
  42. //alert("完成");
  43. }
  44. })
  45. .catch(_ => {
  46. console.log(_);
  47. if (tasks.length) {
  48. tasks.shift()();
  49. } else {
  50. //alert("完成");
  51. }
  52. })
  53. }).bind(null, ps[i]));
  54. }
  55. if (tasks.length) {
  56. tasks.shift()();
  57. } else {
  58. alert("完成");
  59. }
  60. }
  61.  
  62. window.onload = function() {
  63. var content = jQuery('.wy-nav-content');
  64. var parentDiv = content.parent();
  65. parentDiv[0].style.background = "#fff";
  66. content[0].style.float = 'left';
  67. content[0].style.background = 'darkkhaki';
  68. var copyContent = jQuery(`<div class="wy-nav-content copy" style="float: left;margin-left:20px;background: beige;">` + content[0].innerHTML + `<div>`);
  69. parentDiv.append(copyContent);
  70. jQuery('body').append(jQuery(`
  71. <div id="fixLoc" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
  72. <div onclick="justLoc(-1)" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
  73. <div onclick="closeFixLoc()" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
  74. <div onclick="justLoc(1)" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
  75. </div>`))
  76. window.closeFixLoc = function() {
  77. jQuery("#fixLoc")[0].style.display = "none";
  78. }
  79. window.currentLoc = 0;
  80. window.justLoc = function(tar) {
  81. let cloc = currentLoc + tar * 50;
  82. if (cloc < 0) {
  83. return;
  84. } else {
  85. let cp = $('.copy');
  86. cp[0].style.marginTop = cloc + "px"
  87. }
  88. }
  89.  
  90. setTimeout(function(){
  91. $tranPElement('.copy .document p,.copy .document li');
  92. },1000);
  93. }
  94. // Your code here...
  95. })();

QingJ © 2025

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