READTHEDOCS.IO

try to take over the world!

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

  1. // ==UserScript==
  2. // @name READTHEDOCS.IO
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  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. setTimeout(function(){
  71. $tranPElement('.copy .document p,.copy .document li');
  72. },1000);
  73. }
  74. // Your code here...
  75. })();

QingJ © 2025

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