// ==UserScript==
// @name 简书清爽界面
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 简书侧边栏目录,点击收起目录按钮切换显示和隐藏目录列表,支持滚动。
// @author 朴炯文
// @match http://www.jianshu.com/p/*
// @match https://www.jianshu.com/p/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function () {
'use strict';
$('body').append(
'<div class="sxzy shang" style="width:20px;height:20px;background-color:lightblue;font-size:16px;position: fixed;left: 0;top: 70px;">上</div>'
+
'<div class="sxzy xia" style="width:20px;height:20px;background-color:lightblue;font-size:16px;position: fixed;left: 0;top: 91px;">下</div>'
+
'<div class="sxzy zuo" style="width:20px;height:20px;background-color:lightgray;font-size:16px;position: fixed;left: 0;top: 112px;">导</div>'
);
$("#__next > header + div").css("background-color", "#fcfaf2");
$("#__next > header + div > div > div > .ouvJEz").css("background-color", "#fcfaf2");
$(".sxzy").css("display", "flex");
$(".sxzy").css("justify-content", "center");
$(".sxzy").css("align-items", "center");
$(".shang").css("background-color", "lightgray");
$(".xia").css("background-color", "lightgray");
$(".sxzy").hover(function () {
$(".sxzy").css("cursor", "pointer");
});
$("footer").css("display", "none");
$("header").css("display", "none");
$(".shang").click(function () {
var v1 = ($("header").css("display"));
if (v1 == "block") {
$("header").css("display", "none");
$(".shang").css("background-color", "lightgray");
} else {
$("header").css("display", "block");
$(".shang").css("background-color", "lightblue");
}
});
$(".xia").click(function () {
var v1 = ($("footer").css("display"));
if (v1 == "block") {
$("footer").css("display", "none");
$(".xia").css("background-color", "lightgray");
} else {
$("footer").css("display", "block");
$(".xia").css("background-color", "lightblue");
}
});
$(".zuo").click(function () {
var v3 = ($(".my-space").css("visibility"));
if (v3 == "hidden") {
$(".my-space").css("visibility", "visible");
$(".zuo").css("background-color", "lightblue");
} else {
$(".my-space").css("visibility", "hidden");
$(".zuo").css("background-color", "lightgray");
}
});
$('body').append(
'<div class="my-space" style="visibility:hidden;z-index:999;;width: 96%;height: 80vh;position: fixed;left: 2%;top: 10vh;background-color:lightblue;overflow-x:auto;overflow-y:auto;"></div>'
);
var titles = $('body').find('h1,h2,h3,h4,h5,h6').slice(1);
console.log(titles);
var i = 0;
//var a = new Array();
var last = '';
var now = '';
var temp = '';
var res = '';
var removeList = [];
titles.each(function (index, el) {
var classLen;
var myClassName;
try {
myClassName = el.attributes.class.nodeValue;
classLen = myClassName.length;
} catch (err) {
classLen = 0;
}
if (classLen != 0) {
if (myClassName != "_1RuRku") {
removeList.push(index);
}
}
var myTitle = el.textContent;
var nodeName = parseInt(el.nodeName.split("")[1]);
$('.my-space').append(
'<div class="myNodeClass" id="myNode'
+
index
+
'" style="padding-left:'
+
(nodeName - 1) * 20
+
'px">'
+
myTitle
+
'</div>'
);
$("#" + "myNode" + index).click(function () {
$(".my-space").css("visibility", "hidden");
$(".zuo").css("background-color", "lightgray");
$("html,body").animate({scrollTop: $("#" + "mwrz" + index).offset().top}, 500);
});
});
for (var j = 0; j <removeList.length ; j++) {
$('.my-space #myNode'+removeList[j]).remove();
}
$(".myNodeClass").hover(function () {
$(".myNodeClass").css("cursor", "pointer");
});
titles.each(function (index, el) {
now = el.tagName.slice(-1);
$(this).attr('id', 'mwrz' + i);
i += 1;
var t = '<li><a href="#'
+ $(this).attr('id')
+ '">'
+ $(this).text()
+ '</a>';
var head = '';
var tail = '';
if (last == '') {
res += t;
} else if (last < now) { // 层级更深
temp += ('<ul class="nav nav-stacked">' + t + '</li>');
} else if (last > now) {
res += (temp + '</ul></li>');
temp = t;
} else {
temp += (t + '</li>');
}
last = now;
}); // 构造ul,li列表
$('._3Pnjry').css("widht", "0");
$('._3Pnjry').css("height", "0");
$('._3Pnjry').css("overflow", "hidden");
$('._2OwGUo').css("display", "none");
$('._3VRLsv').css("width", "96%");
$('._gp-ck').css("width", "100%");
$('._gp-ck').css("word-wrap", "break-word");
$('.my-space').css("padding", "5px 10px 5px 10px");
$('.my-space .QxT4hD').remove();
})();
网友评论