READTHEDOCS.IO

try to take over the world!

当前为 2020-07-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name READTHEDOCS.IO
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://geotrellis.readthedocs.io/*
  8. // @match https://scala-slick.org/doc/*/*
  9. // @match https://www.geomesa.org/documentation/tutorials/*
  10. // @match http://www.sunibas.cn/public/geotrellis-docs/*
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. //const $supWindow = window;
  19. window.docExpand = "docExpand";
  20. window.onload = function() {
  21. var content = jQuery('.wy-nav-content');
  22. if (content.length) {
  23. geotrellis();
  24. return;
  25. }
  26. if (location.host == "scala-slick.org") {
  27. slick();
  28. }
  29. }
  30. function slick() {
  31. jQuery('.content-wrapper').css({
  32. padding: '0',
  33. background: 'unset'
  34. });
  35. var content = jQuery('.content');
  36. var sidebar = jQuery('.sidebar');
  37. var newSidebar = jQuery(`<div>
  38. <div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
  39. <div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
  40. <div style="display: inline;" tar="dExpandSide">收起</div>
  41. </div></div>`);
  42. content.css({
  43. margin:"0 20px",
  44. width: "auto"
  45. });
  46. jQuery('body').append(newSidebar);
  47. sidebar.remove();
  48. newSidebar.append(sidebar);
  49. newSidebar.css({
  50. position: "fixed",
  51. "z-index": 100000,
  52. background: "#82c8ff",
  53. padding: "20px",
  54. top: '20px',
  55. right: '10px',
  56. });
  57. sidebarSetting(newSidebar,sidebar);
  58. jQuery('.clearer').css({display:'none'});
  59. var doc = jQuery('.document');
  60. doc.css({padding:'0 0px 0 15px'});
  61. jQuery('.content').append(jQuery('<iframe id="copy"></iframe>'));
  62. copyToIframe(copy,doc[0],`<div class="document">`,`</div`);
  63. copy.style.border = "none";
  64. setTimeout(function() {
  65. copy.contentDocument.body.style.padding = "0 10px";
  66. copy.contentDocument.body.children[0].style.width = (copy.contentWindow.innerWidth - 20) + "px";
  67. });
  68. }
  69. function geotrellis() {
  70. var content = jQuery('.wy-nav-content-wrap');
  71. var sidebar = jQuery('.wy-nav-side');
  72. jQuery('.wy-nav-content-wrap').css({margin:0});
  73. var newSidebar = jQuery(`<div>
  74. <div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
  75. <div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
  76. <div style="display: inline;" tar="dExpandSide">收起</div>
  77. </div></div>`);
  78. content.css({
  79. margin:"0"
  80. });
  81. jQuery('body').append(newSidebar);
  82. sidebar.remove();
  83. newSidebar.append(sidebar);
  84. newSidebar.css({
  85. position: "fixed",
  86. "z-index": 100000,
  87. background: "#82c8ff",
  88. padding: "20px",
  89. top: '20px',
  90. right: '10px',
  91. });
  92. sidebar.css({
  93. position: "unset",
  94. "overflow-y": "scroll"
  95. });
  96. sidebarSetting(newSidebar,sidebar);
  97. var doc = jQuery('.wy-nav-content');
  98. doc.css({float:"left"});
  99. content.append(jQuery('<iframe id="copyDoc"></iframe>'));
  100. copyToIframe(copyDoc,doc[0],`<div class="wy-nav-content">`,`</div`);
  101. copyDoc.style.border = "none";
  102. setTimeout(function() {
  103. copyDoc.contentDocument.body.style.padding = "0 10px";
  104. copyDoc.contentDocument.body.children[0].style.width = (copyDoc.contentWindow.innerWidth - 20) + "px";
  105. });
  106. }
  107. function sidebarSetting(newSidebar,sidebar) {
  108. function resize() {
  109. var height = window.innerHeight * 0.9;
  110. if (sidebar.height() <= window.innerHeight * 0.9) {
  111. sidebar.css({
  112. height: "auto",
  113. "overflow-y": "unset"
  114. });
  115. } else {
  116. sidebar.css({
  117. height: height + "px",
  118. "overflow-y": "scroll"
  119. });
  120. }
  121. };
  122. var res = window.onresize || (() => {});
  123. window.onresize = function() {
  124. res();
  125. resize();
  126. };
  127. resize();
  128. window.expandSide = function() {
  129. sidebar.css({display:'block'});
  130. setContent(docExpand,{ex:true});
  131. };
  132. window.dExpandSide = function() {
  133. sidebar.css({display:'none'});
  134. setContent(docExpand,{ex:false});
  135. };
  136. newSidebar.find('[tar="expandSide"]').on('click',expandSide);
  137. newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
  138. var ex = getContent(docExpand,{ex:false}).ex;
  139. if (ex) {
  140. expandSide();
  141. } else {
  142. dExpandSide();
  143. }
  144. }
  145. function wy_nav_content() {
  146. var content = jQuery('.wy-nav-content');
  147. var parentDiv = content.parent();
  148. parentDiv[0].style.background = "#fff";
  149. content[0].style.float = 'left';
  150. content[0].style.background = 'darkkhaki';
  151. parentDiv.append(jQuery('<iframe id="copy"></iframe>'));
  152. copyToIframe(copy,content[0],`<div class="wy-nav-content" style="float: left;">`,`</div>`);
  153. }
  154. function copyToIframe(copyIfr,copyEle,outerLeft,outerRight) {
  155. setTimeout(function() {
  156. setTimeout(function(){
  157. var ls = document.getElementsByTagName('head')[0].getElementsByTagName('link');
  158. for (var i = 0;i < ls.length;i++) {
  159. if (ls[i].getAttribute('rel') == "stylesheet") {
  160. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML += `<link rel="stylesheet" href="${ls[i].href}" type="text/css">`;
  161. }
  162. }
  163. },500);
  164. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML = outerLeft + copyEle.innerHTML + outerRight;
  165. copyIfr.style.height = copyEle.clientHeight + "px";
  166. copyIfr.style.width = (copyEle.clientWidth + 50) + "px";
  167. });
  168. setTimeout(function() {
  169. //var colorSet = sessionStorage.getItem('color');
  170. var colorSet = getContent("doc_color",JSON.stringify({color1: "#a7e0e7", color2: "#79c9f9"}));
  171. jQuery('body').append(jQuery(`
  172. <div id="fixColor" style="position: fixed;right: 200px;top: 20px;font-size: x-large;background: #82c8ff;padding: 20px;">
  173. <div style="display:inline;">左边<input id="color1" type="color" value="${colorSet.color1}"/></div>
  174. <div style="display:inline;">右边<input id="color2" type="color" value="${colorSet.color2}"/></div>
  175. </div>`));
  176. jQuery('body').append(jQuery(`
  177. <div id="fixLoc" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
  178. <div id="justLocUp" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
  179. <div id="closeFixLoc" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
  180. <div id="justLocDown" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
  181. </div>`));
  182. jQuery("#closeFixLoc").on("click",function() {
  183. jQuery("#fixLoc")[0].style.display = "none";
  184. });
  185. let currentLoc = 0;
  186. let justLoc = function(tar) {
  187. let cloc = currentLoc + tar * 50;
  188. if (cloc < 0) {
  189. return;
  190. } else {
  191. copyEle.style.marginTop = cloc + "px"
  192. currentLoc = cloc;
  193. }
  194. }
  195. jQuery("#justLocUp").on("click",function() {
  196. justLoc(-1);
  197. });
  198. jQuery("#justLocDown").on("click",function() {
  199. justLoc(1);
  200. });
  201. copyEle.style.background = color1.value;
  202. jQuery("#color1").on("change",function() {
  203. copyEle.style.background = color1.value;
  204. colorSet.color1 = color1.value;
  205. setContent('doc_color',JSON.stringify(colorSet));
  206. // sessionStorage.setItem('color',JSON.stringify(colorSet));
  207. });
  208. copyIfr.contentDocument.body.style.background = color2.value;
  209. (copyIfr.contentDocument.getElementsByClassName('wy-nav-content')[0] || {style:{background:''}}).style.background = color2.value;
  210. jQuery("#color2").on("change",function() {
  211. colorSet.color2 = color2.value;
  212. //sessionStorage.setItem('color',JSON.stringify(colorSet));
  213. setContent('doc_color',JSON.stringify(colorSet));
  214. copyIfr.contentDocument.body.style.background = color2.value;
  215. (copyDoc.contentDocument.getElementsByClassName('wy-nav-content')[0] || {style:{background:''}}).style.background = color2.value;
  216. });
  217. });
  218. }
  219. function getContent(name,defaultValue) {
  220. var value = GM_getValue(name,JSON.stringify(defaultValue));
  221. return JSON.parse(value);
  222. }
  223. function setContent(name,value) {
  224. GM_setValue(name,JSON.stringify(value));
  225. }
  226. // Your code here...
  227. })();

QingJ © 2025

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