// ==UserScript==
// @name READTHEDOCS.IO
// @namespace http://tampermonkey.net/
// @version 0.9
// @description try to take over the world!
// @author You
// @match https://geotrellis.readthedocs.io/*
// @match https://scala-slick.org/doc/*/*
// @match https://www.geomesa.org/documentation/tutorials/*
// @match http://www.sunibas.cn/public/geotrellis-docs/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
//const $supWindow = window;
window.onload = function() {
var content = jQuery('.wy-nav-content');
if (content.length) {
geotrellis();
return;
}
if (location.host == "scala-slick.org") {
slick();
}
}
function slick() {
jQuery('.content-wrapper').css({
padding: '0',
background: 'unset'
});
var content = jQuery('.content');
var sidebar = jQuery('.sidebar');
var newSidebar = jQuery(`<div>
<div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
<div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
<div style="display: inline;" tar="dExpandSide">收起</div>
</div></div>`);
content.css({
margin:"0 20px",
width: "auto"
});
jQuery('body').append(newSidebar);
sidebar.remove();
newSidebar.append(sidebar);
newSidebar.css({
position: "fixed",
"z-index": 100000,
background: "#82c8ff",
padding: "20px",
top: '20px',
right: '10px',
});
window.expandSide = function() {
sidebar.css({display:'block'});
};
window.dExpandSide = function() {
sidebar.css({display:'none'});
};
newSidebar.find('[tar="expandSide"]').on('click',expandSide);
newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
dExpandSide();
jQuery('.clearer').css({display:'none'});
var doc = jQuery('.document');
doc.css({padding:'0 0px 0 15px'});
jQuery('.content').append(jQuery('<iframe id="copy"></iframe>'));
copyToIframe(copy,doc[0],`<div class="document">`,`</div`);
copy.style.border = "none";
setTimeout(function() {
copy.contentDocument.body.style.padding = "0 10px";
copy.contentDocument.body.children[0].style.width = (copy.contentWindow.innerWidth - 20) + "px";
});
}
function geotrellis() {
var content = jQuery('.wy-nav-content-wrap');
var sidebar = jQuery('.wy-nav-side');
jQuery('.wy-nav-content-wrap').css({margin:0});
var newSidebar = jQuery(`<div>
<div style="cursor: pointer;user-select: none;padding: 5px;background: darkseagreen;">
<div style="display: inline;padding-right:20px" tar="expandSide">展开</div>
<div style="display: inline;" tar="dExpandSide">收起</div>
</div></div>`);
content.css({
margin:"0"
});
jQuery('body').append(newSidebar);
sidebar.remove();
newSidebar.append(sidebar);
newSidebar.css({
position: "fixed",
"z-index": 100000,
background: "#82c8ff",
padding: "20px",
top: '20px',
right: '10px',
});
sidebar.css({
position: "unset"
});
window.expandSide = function() {
sidebar.css({display:'block'});
};
window.dExpandSide = function() {
sidebar.css({display:'none'});
};
newSidebar.find('[tar="expandSide"]').on('click',expandSide);
newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
dExpandSide();
var doc = jQuery('.wy-nav-content');
doc.css({float:"left"});
content.append(jQuery('<iframe id="copyDoc"></iframe>'));
copyToIframe(copyDoc,doc[0],`<div class="wy-nav-content">`,`</div`);
copyDoc.style.border = "none";
setTimeout(function() {
copyDoc.contentDocument.body.style.padding = "0 10px";
copyDoc.contentDocument.body.children[0].style.width = (copyDoc.contentWindow.innerWidth - 20) + "px";
});
}
function wy_nav_content() {
var content = jQuery('.wy-nav-content');
var parentDiv = content.parent();
parentDiv[0].style.background = "#fff";
content[0].style.float = 'left';
content[0].style.background = 'darkkhaki';
parentDiv.append(jQuery('<iframe id="copy"></iframe>'));
copyToIframe(copy,content[0],`<div class="wy-nav-content" style="float: left;">`,`</div>`);
}
function copyToIframe(copyIfr,copyEle,outerLeft,outerRight) {
setTimeout(function() {
setTimeout(function(){
var ls = document.getElementsByTagName('head')[0].getElementsByTagName('link');
for (var i = 0;i < ls.length;i++) {
if (ls[i].getAttribute('rel') == "stylesheet") {
copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML += `<link rel="stylesheet" href="${ls[i].href}" type="text/css">`;
}
}
},500);
copyIfr.contentWindow.document.getElementsByTagName('body')[0].innerHTML = outerLeft + copyEle.innerHTML + outerRight;
copyIfr.style.height = copyEle.clientHeight + "px";
copyIfr.style.width = (copyEle.clientWidth + 50) + "px";
});
setTimeout(function() {
//var colorSet = sessionStorage.getItem('color');
var colorSet = GM_getValue("doc_color",JSON.stringify({color1: "#a7e0e7", color2: "#79c9f9"}));
if (!colorSet) {
colorSet = {color1: "#a7e0e7", color2: "#79c9f9"};
} else {
colorSet = JSON.parse(colorSet);
}
jQuery('body').append(jQuery(`
<div id="fixColor" style="position: fixed;right: 200px;top: 20px;font-size: x-large;background: #82c8ff;padding: 20px;">
<div style="display:inline;">左边<input id="color1" type="color" value="${colorSet.color1}"/></div>
<div style="display:inline;">右边<input id="color2" type="color" value="${colorSet.color2}"/></div>
</div>`));
jQuery('body').append(jQuery(`
<div id="fixLoc" style="position: fixed;right: 20px;top: 50%;font-size: xx-large;cursor: pointer;user-select: none;">
<div id="justLocUp" style="background: cadetblue;border-radius: 10px;padding: 5px;">上</div>
<div id="closeFixLoc" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">关</div>
<div id="justLocDown" style="margin-top: 5px;background: cadetblue;border-radius: 10px;padding: 5px;">下</div>
</div>`));
jQuery("#closeFixLoc").on("click",function() {
jQuery("#fixLoc")[0].style.display = "none";
});
let currentLoc = 0;
let justLoc = function(tar) {
let cloc = currentLoc + tar * 50;
if (cloc < 0) {
return;
} else {
copyEle.style.marginTop = cloc + "px"
currentLoc = cloc;
}
}
jQuery("#justLocUp").on("click",function() {
justLoc(-1);
});
jQuery("#justLocDown").on("click",function() {
justLoc(1);
});
copyEle.style.background = color1.value;
jQuery("#color1").on("change",function() {
copyEle.style.background = color1.value;
colorSet.color1 = color1.value;
GM_setValue('doc_color',JSON.stringify(colorSet));
// sessionStorage.setItem('color',JSON.stringify(colorSet));
});
copyIfr.contentDocument.body.style.background = color2.value;
(copyDoc.contentDocument.getElementsByClassName('wy-nav-content')[0] || {style:{background:''}}).style.background = color2.value;
jQuery("#color2").on("change",function() {
colorSet.color2 = color2.value;
//sessionStorage.setItem('color',JSON.stringify(colorSet));
GM_setValue('doc_color',JSON.stringify(colorSet));
copyIfr.contentDocument.body.style.background = color2.value;
(copyDoc.contentDocument.getElementsByClassName('wy-nav-content')[0] || {style:{background:''}}).style.background = color2.value;
});
});
}
// Your code here...
})();