READTHEDOCS.IO

try to take over the world!

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

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

QingJ © 2025

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