|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 知乎美化 |
3 | | -// @version 1.0.6 |
| 3 | +// @version 1.0.7 |
4 | 4 | // @author X.I.U |
5 | | -// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致 |
| 5 | +// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致、浏览回答向下翻时自动隐藏标题 |
6 | 6 | // @match *://www.zhihu.com/* |
7 | 7 | // @match *://zhuanlan.zhihu.com/p/* |
8 | 8 | // @icon https://static.zhihu.com/heifetz/favicon.ico |
|
18 | 18 | // ==/UserScript== |
19 | 19 |
|
20 | 20 | (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; |
23 | 24 | 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)}; |
24 | 26 | registerMenuCommand(); |
25 | 27 | addStyle(); |
26 | 28 |
|
27 | 29 | // 注册脚本菜单 |
28 | 30 | function registerMenuCommand() { |
29 | | - var menu_postimg_; |
| 31 | + let menu_postimg_, menu_hideTitle_; |
30 | 32 | if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单 |
31 | 33 | GM_unregisterMenuCommand(menu_postimg_ID); |
| 34 | + GM_unregisterMenuCommand(menu_hideTitle_ID); |
32 | 35 | GM_unregisterMenuCommand(menu_feedBack_ID); |
33 | 36 | menu_postimg = GM_getValue('xiu2_menu_postimg'); |
| 37 | + menu_hideTitle = GM_getValue('xiu2_menu_hideTitle'); |
34 | 38 | } |
35 | 39 |
|
36 | 40 | if (menu_postimg){menu_postimg_ = "√";}else{menu_postimg_ = "×";} |
| 41 | + if (menu_hideTitle){menu_hideTitle_ = "√";}else{menu_hideTitle_ = "×";} |
37 | 42 |
|
38 | 43 | 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','隐藏浏览回答标题')}); |
39 | 45 | menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});}); |
40 | 46 | } |
41 | 47 |
|
42 | 48 | // 菜单开关 |
43 | 49 | function menu_switch(menu_status, Name, Tips) { |
44 | 50 | if (menu_status){ |
45 | 51 | GM_setValue(`${Name}`, false); |
46 | | - GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500}); |
| 52 | + GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000}); |
47 | 53 | }else{ |
48 | 54 | GM_setValue(`${Name}`, true); |
49 | | - GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500}); |
| 55 | + GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000}); |
50 | 56 | } |
51 | 57 | registerMenuCommand(); // 重新注册脚本菜单 |
52 | 58 | }; |
53 | 59 |
|
54 | 60 |
|
55 | 61 | // 添加样式 |
56 | 62 | function addStyle() { |
57 | | - var style, |
| 63 | + let style, |
58 | 64 | style_1 = ` |
59 | 65 | .GlobalSideBar,.Question-sideColumn,.ContentLayout-sideColumn,.SearchSideBar,.Card.QuestionHeaderTopicMeta { |
60 | 66 | display: none !important; |
|
69 | 75 | z-index: 999 !important; |
70 | 76 | } |
71 | 77 | `, |
72 | | - style_2 = ` |
73 | | -/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */ |
| 78 | + style_2 = `/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */ |
74 | 79 | .RichContent img.ArticleItem-image { |
75 | 80 | display: none !important; |
76 | | -} |
77 | | -`, |
78 | | - style_3 = ` |
79 | | -/* 调整文章编辑页面与实际文章宽度一致 */ |
| 81 | +}`, |
| 82 | + style_3 = `/* 调整文章编辑页面与实际文章宽度一致 */ |
80 | 83 | .PostEditor .RichText { |
81 | 84 | min-width: 690px !important; |
82 | 85 | } |
83 | 86 | /* 及标题输入框内的文字大小 */ |
84 | 87 | .WriteIndex-titleInput .Input { |
85 | 88 | min-width: 690px !important; |
86 | 89 | 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 | + // 隐藏文章开头大图 |
90 | 99 | 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; |
94 | 105 | } |
| 106 | + // 文章编辑页面与实际文章宽度一致 |
95 | 107 | if(window.location.href.indexOf("zhuanlan") > -1){ |
96 | 108 | if(window.location.href.indexOf("/edit") > -1){ |
97 | 109 | style += style_3; |
|
0 commit comments