READTHEDOCS.IO

try to take over the world!

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

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