READTHEDOCS.IO

try to take over the world!

目前為 2020-07-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         READTHEDOCS.IO
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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.docExpand = "docExpand";
    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',
        });
        sidebarSetting(newSidebar,sidebar);
        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",
            "overflow-y": "scroll"
        });
        sidebarSetting(newSidebar,sidebar);
        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 sidebarSetting(newSidebar,sidebar) {
        function resize() {
            var height = window.innerHeight * 0.9;
            if (sidebar.height() <= window.innerHeight * 0.9) {
                sidebar.css({
                    height: "auto",
                    "overflow-y": "unset"
                });
            } else {
                sidebar.css({
                    height: height + "px",
                    "overflow-y": "scroll"
                });
            }
        };
        var res = window.onresize || (() => {});
        window.onresize = function() {
            res();
            resize();
        };
        resize();
        window.expandSide = function() {
            sidebar.css({display:'block'});
            setContent(docExpand,{ex:true});
        };
        window.dExpandSide = function() {
            sidebar.css({display:'none'});
            setContent(docExpand,{ex:false});
        };
        newSidebar.find('[tar="expandSide"]').on('click',expandSide);
        newSidebar.find('[tar="dExpandSide"]').on('click',dExpandSide);
        var ex = getContent(docExpand,{ex:false}).ex;
        if (ex) {
            expandSide();
        } else {
            dExpandSide();
        }
    }
    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 = getContent("doc_color",JSON.stringify({color1: "#a7e0e7", color2: "#79c9f9"}));
            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;
                setContent('doc_color',JSON.stringify(colorSet));
                // sessionStorage.setItem('color',JSON.stringify(colorSet));
            });
            copyIfr.contentDocument.body.style.background = color2.value;
            (copyIfr.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));
                setContent('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;
            });
        });
    }
    function getContent(name,defaultValue) {
        var value = GM_getValue(name,JSON.stringify(defaultValue));
        return JSON.parse(value);
    }
    function setContent(name,value) {
         GM_setValue(name,JSON.stringify(value));
    }
    // Your code here...
})();