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.2
  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.docSidebarLoc = "docSidebarLoc";
  21. var panelDefaultSetting = {
  22. name: "panelDefaultSetting",
  23. panelOpacity: 80,
  24. sidebarOpacity: 80,
  25. leftColor: "#a7e0e7",
  26. rightColor: "#79c9f9",
  27. docScala: 100,
  28. };
  29. var setLeftContentColor = function() {};
  30. var setRightContentColor = function() {};
  31. var getLeftContentDom = function() {};
  32. var getRightContentDom = function() {};
  33. window.panel = {
  34. color: 'fixColor',
  35. loc: 'fixLoc',
  36. sidebar: 'mySidebar',
  37. };
  38. window.onload = function() {
  39. var content = jQuery('.wy-nav-content');
  40. if (content.length) {
  41. geotrellis();
  42. return;
  43. }
  44. if (location.host == "scala-slick.org") {
  45. slick();
  46. }
  47. addSetting();
  48. }
  49. function addSetting() {
  50. var settingBtn = jQuery(`<div style="position: fixed;top: 0;left: 0;
  51. z-index: 1000;border: 50px solid;border-top-color: #3F51B5;
  52. border-bottom-color: #ffff0000;border-left-color: #9C27B0;cursor: pointer;
  53. border-right-color: #0000ff00;"></div>`);
  54. jQuery('body').append(settingBtn);
  55. var settingPanel = jQuery(`<div style="position: fixed;display:none;
  56. top: 20%;padding:20px;left: 20%;color:white;
  57. width: 60%;height: 60%;z-index: 1000;background: black;
  58. "><div style="width: 100%;line-height: 20px;cursor: pointer;" tar="close">关闭</div></div>`);
  59. function updateValue(name,value) {
  60. panelDefaultSetting[name] = value;
  61. setContent(panelDefaultSetting.name,panelDefaultSetting);
  62. }
  63. function addRange(label,defaultValue,name,onchange,max,min,step) {
  64. var range = jQuery(`<div style="width: 100%;line-height: 20px;">
  65. <lable style="display: inline-block;width: 20%;text-align: center;">${label}</lable>
  66. <input type="range" style="width: 70%;" min="${min || 30}" max="${max || 100}" step="${step || 1}"></div>`);
  67. var inp = range.find('input');
  68. inp.val(defaultValue || 100);
  69. inp.on('change',function(e) {
  70. onchange(e.target.value);
  71. updateValue(name,e.target.value);
  72. });
  73. onchange(defaultValue || 100);
  74. return range;
  75. }
  76. function addColor(label,defaultValue,name,onchange) {
  77. var range = jQuery(`<div style="width: 100%;line-height: 20px;">
  78. <lable style="display: inline-block;width: 20%;text-align: center;">${label}</lable>
  79. <input type="color" style="width: 70%;"></div>`);
  80. var inp = range.find('input');
  81. inp.val(defaultValue);
  82. inp.on('change',function(e) {
  83. onchange(e.target.value);
  84. updateValue(name,e.target.value);
  85. });
  86. onchange(defaultValue);
  87. return range;
  88. }
  89. jQuery('body').append(settingPanel);
  90.  
  91. panelDefaultSetting = getContent(panelDefaultSetting.name,panelDefaultSetting);
  92. settingPanel.append(addRange("面板透明度",panelDefaultSetting.panelOpacity,"panelOpacity",function (val) {
  93. settingPanel.css({opacity: val / 100});
  94. }));
  95. settingPanel.append(addRange("菜单透明度",panelDefaultSetting.sidebarOpacity,"sidebarOpacity",function (val) {
  96. jQuery(`#${panel.sidebar}`).css({opacity: val / 100});
  97. }));
  98. settingPanel.append(addColor("左边文档颜色",panelDefaultSetting.leftColor,"leftColor",function (val) {
  99. setLeftContentColor(val);
  100. }));
  101. settingPanel.append(addColor("右边文档颜色",panelDefaultSetting.rightColor,"rightColor",function (val) {
  102. setRightContentColor(val);
  103. }));
  104. settingPanel.append(addRange("缩放文档",panelDefaultSetting.docScala,"docScala",function (val) {
  105. getLeftContentDom().style.transformOrigin = "0 0";
  106. getLeftContentDom().style.transform = `scale(${val / 100})`;
  107. getRightContentDom().style.transformOrigin = "0 0";
  108. var offsetX = - getLeftContentDom().offsetWidth * (100 - val) / 100;
  109. getRightContentDom().style.transform = `scale(${val / 100}) translate(${offsetX}px, 0px)`;
  110. console.log(val);
  111. },150,50,10));
  112. settingPanel.find('[tar="close"]').on("click",function () {
  113. settingPanel.css({display: 'none'});
  114. });
  115. settingBtn.on('click',function() {
  116. settingPanel.css({display:'block'});
  117. });
  118. }
  119. function slick() {
  120. jQuery('.content-wrapper').css({
  121. padding: '0',
  122. background: 'unset'
  123. });
  124. var content = jQuery('.content');
  125. var sidebar = jQuery('.sidebar');
  126. sidebar.remove();
  127. content.css({
  128. margin:"0 20px",
  129. width: "auto"
  130. });
  131. sidebarSetting(sidebar);
  132. jQuery('.clearer').css({display:'none'});
  133. var doc = jQuery('.document');
  134. doc.css({padding:'0 0px 0 15px'});
  135. jQuery('.content').append(jQuery('<iframe id="copy"></iframe>'));
  136. copyToIframe(copy,doc[0],`<div class="document">`,`</div`);
  137. copy.style.border = "none";
  138. setTimeout(function() {
  139. copy.contentDocument.body.style.padding = "0 10px";
  140. copy.contentDocument.body.children[0].style.width = (copy.contentWindow.innerWidth - 20) + "px";
  141. });
  142. }
  143. function geotrellis() {
  144. var content = jQuery('.wy-nav-content-wrap');
  145. var sidebar = jQuery('.wy-nav-side');
  146. jQuery('.wy-nav-content-wrap').css({margin:0});
  147. content.css({
  148. margin:"0"
  149. });
  150. sidebar.remove();
  151. sidebar.css({
  152. position: "unset",
  153. "overflow-y": "scroll"
  154. });
  155. sidebarSetting(sidebar);
  156. var doc = jQuery('.wy-nav-content');
  157. doc.css({float:"left"});
  158. content.append(jQuery('<iframe id="copyDoc"></iframe>'));
  159. copyToIframe(copyDoc,doc[0],`<div class="wy-nav-content">`,`</div`);
  160. copyDoc.style.border = "none";
  161. setTimeout(function() {
  162. copyDoc.contentDocument.body.style.padding = "0 10px";
  163. copyDoc.contentDocument.body.children[0].style.width = (copyDoc.contentWindow.innerWidth - 20) + "px";
  164. });
  165. }
  166. function sidebarSetting(sidebar) {
  167. function resize() {
  168. var height = window.innerHeight * 0.9;
  169. if (sidebar.height() <= window.innerHeight * 0.9) {
  170. sidebar.css({
  171. height: "auto",
  172. "overflow-y": "unset"
  173. });
  174. } else {
  175. sidebar.css({
  176. height: height + "px",
  177. "overflow-y": "scroll"
  178. });
  179. }
  180. };
  181. var newSidebar = jQuery(`<div id="${panel.sidebar}">
  182. <div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
  183. <div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
  184. <div style="display: inline;" tar="dExpandSide">收起</div>
  185. <div style="display: inline;" tar="dragTo">点我拖动</div>
  186. </div></div>`);
  187. jQuery('body').append(newSidebar);
  188. newSidebar.append(sidebar);
  189. var loc = getContent(docSidebarLoc,{top:20,right:10});
  190. newSidebar.css({
  191. position: "fixed",
  192. "z-index": 100000,
  193. background: "#82c8ff",
  194. padding: "20px",
  195. top: loc.top + 'px',
  196. right: loc.right + 'px',
  197. });
  198.  
  199. var res = window.onresize || (() => {});
  200. window.onresize = function() {
  201. res();
  202. resize();
  203. };
  204. resize();
  205. window.expandSide = function() {
  206. sidebar.css({display:'block'});
  207. setContent(docExpand,{ex:true});
  208. };
  209. window.dExpandSide = function() {
  210. sidebar.css({display:'none'});
  211. setContent(docExpand,{ex:false});
  212. };
  213. newSidebar.find('[tar="expandSide"]').on('click',expandSide);
  214. newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
  215. var ex = getContent(docExpand,{ex:false}).ex;
  216. if (ex) {
  217. expandSide();
  218. } else {
  219. dExpandSide();
  220. }
  221. // 处理拖动
  222. newSidebar.find('[tar="dragTo"]').hover(function(){
  223. $(this).css({"background": "#82c8ff",
  224. padding: "5px",
  225. "line-height": "16px",
  226. "box-sizing": "border-box"
  227. });//hover时效果
  228. },function(){
  229. $(this).css({"background": "unset",
  230. padding: "0",
  231. "line-height": "unset",
  232. "box-sizing": "unset"
  233. });//hover时效果
  234. });
  235. let dragObj = {
  236. drag: false,
  237. fromX: 0,
  238. fromY: 0,
  239. top: loc.top,
  240. right: loc.right
  241. };
  242. newSidebar.find('[tar="dragTo"]').on("mousedown",function(e) {
  243. dragObj.drag = true;
  244. dragObj.fromX = e.clientX;
  245. dragObj.fromY = e.clientY;
  246. }).on("mousemove",function(e) {
  247. if (!dragObj.drag) return;
  248. var detaX = dragObj.fromX - e.clientX; // 左 正
  249. var detaY = dragObj.fromY - e.clientY; // 下 负
  250. // 改变 坐标位置
  251. dragObj.right += detaX;
  252. dragObj.top -= detaY;
  253. newSidebar.css({
  254. right: dragObj.right + "px",
  255. top: dragObj.top + "px",
  256. });
  257. dragObj.fromX = e.clientX;
  258. dragObj.fromY = e.clientY;
  259. }).on("mouseup",function() {
  260. dragObj.drag = false;
  261. setContent(docSidebarLoc,{top:dragObj.top,right:dragObj.right});
  262. });
  263. }
  264. function wy_nav_content() {
  265. var content = jQuery('.wy-nav-content');
  266. var parentDiv = content.parent();
  267. parentDiv[0].style.background = "#fff";
  268. content[0].style.float = 'left';
  269. content[0].style.background = 'darkkhaki';
  270. parentDiv.append(jQuery('<iframe id="copy"></iframe>'));
  271. copyToIframe(copy,content[0],`<div class="wy-nav-content" style="float: left;">`,`</div>`);
  272. }
  273. function copyToIframe(copyIfr,copyEle,outerLeft,outerRight) {
  274. setTimeout(function() {
  275. setTimeout(function(){
  276. var ls = document.getElementsByTagName('head')[0].getElementsByTagName('link');
  277. for (var i = 0;i < ls.length;i++) {
  278. if (ls[i].getAttribute('rel') == "stylesheet") {
  279. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML += `<link rel="stylesheet" href="${ls[i].href}" type="text/css">`;
  280. }
  281. }
  282. },500);
  283. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML = outerLeft + copyEle.innerHTML + outerRight;
  284. copyIfr.style.height = copyEle.clientHeight + "px";
  285. copyIfr.style.width = (copyEle.clientWidth + 50) + "px";
  286. });
  287. setLeftContentColor = function(color) {
  288. copyEle.style.background = color;
  289. };
  290. setRightContentColor = function(color) {
  291. copyIfr.contentDocument.body.style.background = color;
  292. };
  293. getLeftContentDom = function() {
  294. return copyEle;
  295. }
  296. getRightContentDom = function() {
  297. return copyIfr;
  298. }
  299. // 上下运动
  300. setTimeout(function() {
  301. jQuery('body').append(jQuery(`
  302. <div id="${panel.loc}" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
  303. <div id="justLocUp" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
  304. <div id="closeFixLoc" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
  305. <div id="justLocDown" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
  306. </div>`));
  307. jQuery("#closeFixLoc").on("click",function() {
  308. jQuery("#fixLoc")[0].style.display = "none";
  309. });
  310. let currentLoc = 0;
  311. let justLoc = function(tar) {
  312. let cloc = currentLoc + tar * 50;
  313. if (cloc < 0) {
  314. return;
  315. } else {
  316. copyEle.style.marginTop = cloc + "px"
  317. currentLoc = cloc;
  318. }
  319. }
  320. jQuery("#justLocUp").on("click",function() {
  321. justLoc(-1);
  322. });
  323. jQuery("#justLocDown").on("click",function() {
  324. justLoc(1);
  325. });
  326. });
  327. }
  328. function getContent(name,defaultValue) {
  329. var value = GM_getValue(name,JSON.stringify(defaultValue));
  330. return JSON.parse(value);
  331. }
  332. function setContent(name,value) {
  333. GM_setValue(name,JSON.stringify(value));
  334. }
  335. // Your code here...
  336. })();

QingJ © 2025

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