Skip to content

Commit c29d5d0

Browse files
committed
新增 [浏览回答向下翻时自动隐藏标题](默认关闭)
1 parent fed110e commit c29d5d0

1 file changed

Lines changed: 32 additions & 20 deletions

File tree

Zhihu-Beautification.user.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 知乎美化
3-
// @version 1.0.6
3+
// @version 1.0.7
44
// @author X.I.U
5-
// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致
5+
// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致、浏览回答向下翻时自动隐藏标题
66
// @match *://www.zhihu.com/*
77
// @match *://zhuanlan.zhihu.com/p/*
88
// @icon https://static.zhihu.com/heifetz/favicon.ico
@@ -18,43 +18,49 @@
1818
// ==/UserScript==
1919

2020
(function() {
21-
var menu_postimg = GM_getValue('xiu2_menu_postimg');
22-
var menu_postimg_ID, menu_feedBack_ID;
21+
var menu_postimg = GM_getValue('xiu2_menu_postimg'),
22+
menu_hideTitle = GM_getValue('xiu2_menu_hideTitle'),
23+
menu_postimg_ID, menu_hideTitle_ID, menu_feedBack_ID;
2324
if (menu_postimg == null){menu_postimg = false; GM_setValue('xiu2_menu_postimg', menu_postimg)};
25+
if (menu_hideTitle == null){menu_hideTitle = false; GM_setValue('xiu2_menu_hideTitle', menu_hideTitle)};
2426
registerMenuCommand();
2527
addStyle();
2628

2729
// 注册脚本菜单
2830
function registerMenuCommand() {
29-
var menu_postimg_;
31+
let menu_postimg_, menu_hideTitle_;
3032
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
3133
GM_unregisterMenuCommand(menu_postimg_ID);
34+
GM_unregisterMenuCommand(menu_hideTitle_ID);
3235
GM_unregisterMenuCommand(menu_feedBack_ID);
3336
menu_postimg = GM_getValue('xiu2_menu_postimg');
37+
menu_hideTitle = GM_getValue('xiu2_menu_hideTitle');
3438
}
3539

3640
if (menu_postimg){menu_postimg_ = "√";}else{menu_postimg_ = "×";}
41+
if (menu_hideTitle){menu_hideTitle_ = "√";}else{menu_hideTitle_ = "×";}
3742

3843
menu_postimg_ID = GM_registerMenuCommand(`[ ${menu_postimg_} ] 隐藏文章开头大图`, function(){menu_switch(menu_postimg,'xiu2_menu_postimg','隐藏文章开头大图')});
44+
menu_hideTitle_ID = GM_registerMenuCommand(`[ ${menu_hideTitle_} ] 隐藏浏览回答标题`, function(){menu_switch(menu_hideTitle,'xiu2_menu_hideTitle','隐藏浏览回答标题')});
3945
menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
4046
}
4147

4248
// 菜单开关
4349
function menu_switch(menu_status, Name, Tips) {
4450
if (menu_status){
4551
GM_setValue(`${Name}`, false);
46-
GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500});
52+
GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000});
4753
}else{
4854
GM_setValue(`${Name}`, true);
49-
GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500});
55+
GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000});
5056
}
5157
registerMenuCommand(); // 重新注册脚本菜单
5258
};
5359

5460

5561
// 添加样式
5662
function addStyle() {
57-
var style,
63+
let style,
5864
style_1 = `
5965
.GlobalSideBar,.Question-sideColumn,.ContentLayout-sideColumn,.SearchSideBar,.Card.QuestionHeaderTopicMeta {
6066
display: none !important;
@@ -69,29 +75,35 @@
6975
z-index: 999 !important;
7076
}
7177
`,
72-
style_2 = `
73-
/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */
78+
style_2 = `/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */
7479
.RichContent img.ArticleItem-image {
7580
display: none !important;
76-
}
77-
`,
78-
style_3 = `
79-
/* 调整文章编辑页面与实际文章宽度一致 */
81+
}`,
82+
style_3 = `/* 调整文章编辑页面与实际文章宽度一致 */
8083
.PostEditor .RichText {
8184
min-width: 690px !important;
8285
}
8386
/* 及标题输入框内的文字大小 */
8487
.WriteIndex-titleInput .Input {
8588
min-width: 690px !important;
8689
font-size: 24px;
87-
}
88-
`
89-
var style_Add = document.createElement('style');
90+
}`,
91+
style_4 = `/* 浏览回答时,向下翻隐藏顶栏(问题的标题)*/
92+
header.is-hidden {
93+
display: none;
94+
}`
95+
let style_Add = document.createElement('style');
96+
// 宽屏显示
97+
style = style_1;
98+
// 隐藏文章开头大图
9099
if (menu_postimg) {
91-
style = style_1 + style_2;
92-
}else{
93-
style = style_1;
100+
style += style_2;
101+
}
102+
// 浏览回答向下翻时自动隐藏标题
103+
if (menu_hideTitle) {
104+
style += style_4;
94105
}
106+
// 文章编辑页面与实际文章宽度一致
95107
if(window.location.href.indexOf("zhuanlan") > -1){
96108
if(window.location.href.indexOf("/edit") > -1){
97109
style += style_3;

0 commit comments

Comments
 (0)