READTHEDOCS.IO

try to take over the world!

  1. // ==UserScript==
  2. // @name READTHEDOCS.IO
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  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/pages/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;max-width:100px;max-height:100px;
  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%;display:inline-block;" 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%;display:inline-block;"></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. function slickOld() {
  121. var content = jQuery('.content');
  122. jQuery('.content-wrapper').css({
  123. padding: '0',
  124. background: 'unset'
  125. });
  126. var sidebar = jQuery('.sidebar');
  127. sidebar.remove();
  128. content.css({
  129. margin:"0 20px",
  130. width: "auto"
  131. });
  132. sidebarSetting(sidebar);
  133. jQuery('.clearer').css({display:'none'});
  134. var doc = jQuery('.document');
  135. doc.css({padding:'0 0px 0 15px'});
  136. return {content,doc,iframeStyle:"",
  137. left:`<div class="document">`,right:`</div`};
  138. }
  139. function slickNew() {
  140. let main = jQuery('main');
  141. let content = main.parent();
  142. main.css({ "max-width": "800px",display: "inline-block",position: "absolute" });
  143. content.parent().css({ margin:0,padding:0,"max-width":"unset" });
  144. let sidebar = jQuery('[data-sticky-container]');
  145. sidebar.remove();
  146. sidebar[0].style.minWidth = "250px";
  147. sidebarSetting(jQuery(`<div>${sidebar[0].children[0].innerHTML}</div>`));
  148. return {
  149. content,doc:main,iframeStyle: `position: absolute;left: 850px;`,
  150. left: '<main class="columns large-order-2 sections">',
  151. right: '</main>'
  152. };
  153. }
  154. var content = jQuery('.content');
  155. var dom = {};
  156. if (content.length === 0) {
  157. dom = slickNew();
  158. } else {
  159. dom = slickOld();
  160. }
  161.  
  162. dom.content.append(jQuery(`<iframe id="copy" style="${dom.iframeStyle}"></iframe>`));
  163. copyToIframe(copy,dom.doc[0],dom.left,dom.right);
  164. copy.style.border = "none";
  165. setTimeout(function() {
  166. copy.contentDocument.body.style.padding = "0 10px";
  167. copy.contentDocument.body.children[0].style.width = (copy.contentWindow.innerWidth - 20) + "px";
  168. });
  169. }
  170. function geotrellis() {
  171. var content = jQuery('.wy-nav-content-wrap');
  172. var sidebar = jQuery('.wy-nav-side');
  173. jQuery('.wy-nav-content-wrap').css({margin:0});
  174. content.css({
  175. margin:"0"
  176. });
  177. sidebar.remove();
  178. sidebar.css({
  179. position: "unset",
  180. "overflow-y": "scroll"
  181. });
  182. sidebarSetting(sidebar);
  183. var doc = jQuery('.wy-nav-content');
  184. doc.css({float:"left"});
  185. content.append(jQuery('<iframe id="copyDoc"></iframe>'));
  186. copyToIframe(copyDoc,doc[0],`<div class="wy-nav-content">`,`</div`);
  187. copyDoc.style.border = "none";
  188. setTimeout(function() {
  189. copyDoc.contentDocument.body.style.padding = "0 10px";
  190. copyDoc.contentDocument.body.children[0].style.width = (copyDoc.contentWindow.innerWidth - 20) + "px";
  191. });
  192. }
  193. function sidebarSetting(sidebar) {
  194. function resize() {
  195. var height = window.innerHeight * 0.9;
  196. if (sidebar.height() <= window.innerHeight * 0.9) {
  197. sidebar.css({
  198. height: "auto",
  199. "overflow-y": "unset"
  200. });
  201. } else {
  202. sidebar.css({
  203. height: height + "px",
  204. "overflow-y": "scroll"
  205. });
  206. }
  207. };
  208. var newSidebar = jQuery(`<div id="${panel.sidebar}">
  209. <div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
  210. <div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
  211. <div style="display: inline;" tar="dExpandSide">收起</div>
  212. <div style="display: inline;" tar="dragTo">点我拖动</div>
  213. </div></div>`);
  214. jQuery('body').append(newSidebar);
  215. newSidebar.append(sidebar);
  216. var loc = getContent(docSidebarLoc,{top:20,right:10});
  217. newSidebar.css({
  218. position: "fixed",
  219. "z-index": 100000,
  220. background: "#82c8ff",
  221. padding: "20px",
  222. top: loc.top + 'px',
  223. right: loc.right + 'px',
  224. });
  225.  
  226. var res = window.onresize || (() => {});
  227. window.onresize = function() {
  228. res();
  229. resize();
  230. };
  231. resize();
  232. window.expandSide = function() {
  233. sidebar.css({display:'block'});
  234. setContent(docExpand,{ex:true});
  235. };
  236. window.dExpandSide = function() {
  237. sidebar.css({display:'none'});
  238. setContent(docExpand,{ex:false});
  239. };
  240. newSidebar.find('[tar="expandSide"]').on('click',expandSide);
  241. newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
  242. var ex = getContent(docExpand,{ex:false}).ex;
  243. if (ex) {
  244. expandSide();
  245. } else {
  246. dExpandSide();
  247. }
  248. // 处理拖动
  249. newSidebar.find('[tar="dragTo"]').hover(function(){
  250. $(this).css({"background": "#82c8ff",
  251. padding: "5px",
  252. "line-height": "16px",
  253. "box-sizing": "border-box"
  254. });//hover时效果
  255. },function(){
  256. $(this).css({"background": "unset",
  257. padding: "0",
  258. "line-height": "unset",
  259. "box-sizing": "unset"
  260. });//hover时效果
  261. });
  262. let dragObj = {
  263. drag: false,
  264. fromX: 0,
  265. fromY: 0,
  266. top: loc.top,
  267. right: loc.right
  268. };
  269. newSidebar.find('[tar="dragTo"]').on("mousedown",function(e) {
  270. dragObj.drag = true;
  271. dragObj.fromX = e.clientX;
  272. dragObj.fromY = e.clientY;
  273. }).on("mousemove",function(e) {
  274. if (!dragObj.drag) return;
  275. var detaX = dragObj.fromX - e.clientX; // 左 正
  276. var detaY = dragObj.fromY - e.clientY; // 下 负
  277. // 改变 坐标位置
  278. dragObj.right += detaX;
  279. dragObj.top -= detaY;
  280. newSidebar.css({
  281. right: dragObj.right + "px",
  282. top: dragObj.top + "px",
  283. });
  284. dragObj.fromX = e.clientX;
  285. dragObj.fromY = e.clientY;
  286. }).on("mouseup",function() {
  287. dragObj.drag = false;
  288. setContent(docSidebarLoc,{top:dragObj.top,right:dragObj.right});
  289. });
  290. }
  291. function wy_nav_content() {
  292. var content = jQuery('.wy-nav-content');
  293. var parentDiv = content.parent();
  294. parentDiv[0].style.background = "#fff";
  295. content[0].style.float = 'left';
  296. content[0].style.background = 'darkkhaki';
  297. parentDiv.append(jQuery('<iframe id="copy"></iframe>'));
  298. copyToIframe(copy,content[0],`<div class="wy-nav-content" style="float: left;">`,`</div>`);
  299. }
  300. function copyToIframe(copyIfr,copyEle,outerLeft,outerRight) {
  301. setTimeout(function() {
  302. setTimeout(function(){
  303. var ls = document.getElementsByTagName('head')[0].getElementsByTagName('link');
  304. for (var i = 0;i < ls.length;i++) {
  305. if (ls[i].getAttribute('rel') == "stylesheet") {
  306. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML += `<link rel="stylesheet" href="${ls[i].href}" type="text/css">`;
  307. }
  308. }
  309. },500);
  310. copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML = outerLeft + copyEle.innerHTML + outerRight;
  311. copyIfr.style.height = copyEle.clientHeight + "px";
  312. copyIfr.style.width = (copyEle.clientWidth + 50) + "px";
  313. });
  314. setLeftContentColor = function(color) {
  315. copyEle.style.background = color;
  316. };
  317. setRightContentColor = function(color) {
  318. copyIfr.contentDocument.body.style.background = color;
  319. };
  320. getLeftContentDom = function() {
  321. return copyEle;
  322. }
  323. getRightContentDom = function() {
  324. return copyIfr;
  325. }
  326. // 上下运动
  327. setTimeout(function() {
  328. jQuery('body').append(jQuery(`
  329. <div id="${panel.loc}" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
  330. <div id="justLocUp" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
  331. <div id="closeFixLoc" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
  332. <div id="justLocDown" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
  333. </div>`));
  334. jQuery("#closeFixLoc").on("click",function() {
  335. jQuery("#fixLoc")[0].style.display = "none";
  336. });
  337. let currentLoc = 0;
  338. let justLoc = function(tar) {
  339. let cloc = currentLoc + tar * 50;
  340. if (cloc < 0) {
  341. return;
  342. } else {
  343. copyEle.style.marginTop = cloc + "px"
  344. currentLoc = cloc;
  345. }
  346. }
  347. jQuery("#justLocUp").on("click",function() {
  348. justLoc(-1);
  349. });
  350. jQuery("#justLocDown").on("click",function() {
  351. justLoc(1);
  352. });
  353. });
  354. }
  355. function getContent(name,defaultValue) {
  356. var value = GM_getValue(name,JSON.stringify(defaultValue));
  357. return JSON.parse(value);
  358. }
  359. function setContent(name,value) {
  360. GM_setValue(name,JSON.stringify(value));
  361. }
  362. // Your code here...
  363. })();

QingJ © 2025

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