Skip to content

Commit af33cc8

Browse files
committed
新增 脚本菜单[屏蔽文章开头大图]
1 parent a4045dc commit af33cc8

1 file changed

Lines changed: 75 additions & 13 deletions

File tree

Zhihu-Beautification.user.js

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,64 @@
11
// ==UserScript==
22
// @name 知乎美化
3-
// @version 1.0.2
3+
// @version 1.0.3
44
// @author X.I.U
5-
// @description 宽屏显示
6-
// @include *://www.zhihu.com/*
5+
// @description 宽屏显示、屏蔽文章开头大图、文章编辑页面与实际文章宽度一致
6+
// @match *://www.zhihu.com/*
7+
// @match *://zhuanlan.zhihu.com/p/*/edit
78
// @icon https://static.zhihu.com/static/favicon.ico
9+
// @grant GM_registerMenuCommand
10+
// @grant GM_unregisterMenuCommand
11+
// @grant GM_openInTab
12+
// @grant GM_getValue
13+
// @grant GM_setValue
14+
// @grant GM_notification
815
// @license GPL-3.0 License
916
// @run-at document-start
1017
// @namespace https://greasyfork.org/scripts/412212
1118
// ==/UserScript==
1219

1320
(function() {
14-
var style_Add = document.createElement('style');
15-
style_Add.innerHTML = `
16-
.GlobalSideBar,.Question-sideColumn,.ContentLayout-sideColumn,.SearchSideBar,.RichContent img.ArticleItem-image {
17-
display: none !important;
18-
}
19-
/* 屏蔽在各列表中查看文章时开头显示的大图,不影响文章/专栏页面
20-
.RichContent img.ArticleItem-image {
21+
var menu_postimg = GM_getValue('xiu2_menu_postimg');
22+
var menu_postimg_ID, menu_feedBack_ID;
23+
if (menu_postimg == null){menu_postimg = false; GM_setValue('xiu2_menu_postimg', menu_postimg)};
24+
registerMenuCommand();
25+
addStyle();
26+
27+
// 注册脚本菜单
28+
function registerMenuCommand() {
29+
var menu_postimg_;
30+
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
31+
GM_unregisterMenuCommand(menu_postimg_ID);
32+
GM_unregisterMenuCommand(menu_feedBack_ID);
33+
menu_postimg = GM_getValue('xiu2_menu_postimg');
34+
}
35+
36+
if (menu_postimg){menu_postimg_ = "√";}else{menu_postimg_ = "×";}
37+
38+
menu_postimg_ID = GM_registerMenuCommand(`[ ${menu_postimg_} ] 屏蔽文章开头大图`, function(){menu_switch(menu_postimg,'xiu2_menu_postimg','屏蔽文章开头大图')});
39+
menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
40+
}
41+
42+
// 菜单开关
43+
function menu_switch(menu_status, Name, Tips) {
44+
if (menu_status){
45+
GM_setValue(`${Name}`, false);
46+
GM_notification(`已关闭 [${Tips}] 功能\n(刷新网页后生效)`);
47+
}else{
48+
GM_setValue(`${Name}`, true);
49+
GM_notification(`已开启 [${Tips}] 功能\n(刷新网页后生效)`);
50+
}
51+
registerMenuCommand(); // 重新注册脚本菜单
52+
};
53+
54+
55+
// 添加样式
56+
function addStyle() {
57+
var style,
58+
style_1 = `
59+
.GlobalSideBar,.Question-sideColumn,.ContentLayout-sideColumn,.SearchSideBar,.Card.QuestionHeaderTopicMeta {
2160
display: none !important;
2261
}
23-
*/
2462
.Topstory-mainColumn,.Question-mainColumn,.ContentLayout-mainColumn,.SearchMain,.QuestionWaiting-mainColumn {
2563
width: 1000px !important;
2664
}
@@ -29,6 +67,30 @@
2967
}
3068
.ImageMessage-ImageView {
3169
z-index: 999 !important;
32-
}`;
33-
document.head.appendChild(style_Add);
70+
}
71+
`,
72+
style_2 = `
73+
/* 屏蔽在各列表中查看文章时开头显示的大图,不影响文章/专栏页面 */
74+
.RichContent img.ArticleItem-image {
75+
display: none !important;
76+
}
77+
`,
78+
style_3 = `
79+
/* 调整文章编辑页面与实际文章宽度一致 */
80+
.PostEditor .RichText {
81+
min-width: 690px !important;
82+
}
83+
`
84+
var style_Add = document.createElement('style');
85+
if (menu_postimg) {
86+
style = style_1 + style_2;
87+
}else{
88+
style = style_1;
89+
}
90+
if(window.location.href.indexOf("zhuanlan") > -1){
91+
style += style_3;
92+
}
93+
style_Add.innerHTML = style;
94+
document.head.appendChild(style_Add);
95+
}
3496
})();

0 commit comments

Comments
 (0)