From c29d5d0591951b871e01de5d1234dfe861020f02 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Fri, 12 Mar 2021 20:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20[=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=9B=9E=E7=AD=94=E5=90=91=E4=B8=8B=E7=BF=BB=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=9A=90=E8=97=8F=E6=A0=87=E9=A2=98]=EF=BC=88?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Beautification.user.js | 52 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/Zhihu-Beautification.user.js b/Zhihu-Beautification.user.js index bcdea3b..eedb6d2 100644 --- a/Zhihu-Beautification.user.js +++ b/Zhihu-Beautification.user.js @@ -1,8 +1,8 @@ // ==UserScript== // @name 知乎美化 -// @version 1.0.6 +// @version 1.0.7 // @author X.I.U -// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致 +// @description 宽屏显示、隐藏文章开头大图、文章编辑页面与实际文章宽度一致、浏览回答向下翻时自动隐藏标题 // @match *://www.zhihu.com/* // @match *://zhuanlan.zhihu.com/p/* // @icon https://static.zhihu.com/heifetz/favicon.ico @@ -18,24 +18,30 @@ // ==/UserScript== (function() { - var menu_postimg = GM_getValue('xiu2_menu_postimg'); - var menu_postimg_ID, menu_feedBack_ID; + var menu_postimg = GM_getValue('xiu2_menu_postimg'), + menu_hideTitle = GM_getValue('xiu2_menu_hideTitle'), + menu_postimg_ID, menu_hideTitle_ID, menu_feedBack_ID; if (menu_postimg == null){menu_postimg = false; GM_setValue('xiu2_menu_postimg', menu_postimg)}; + if (menu_hideTitle == null){menu_hideTitle = false; GM_setValue('xiu2_menu_hideTitle', menu_hideTitle)}; registerMenuCommand(); addStyle(); // 注册脚本菜单 function registerMenuCommand() { - var menu_postimg_; + let menu_postimg_, menu_hideTitle_; if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单 GM_unregisterMenuCommand(menu_postimg_ID); + GM_unregisterMenuCommand(menu_hideTitle_ID); GM_unregisterMenuCommand(menu_feedBack_ID); menu_postimg = GM_getValue('xiu2_menu_postimg'); + menu_hideTitle = GM_getValue('xiu2_menu_hideTitle'); } if (menu_postimg){menu_postimg_ = "√";}else{menu_postimg_ = "×";} + if (menu_hideTitle){menu_hideTitle_ = "√";}else{menu_hideTitle_ = "×";} menu_postimg_ID = GM_registerMenuCommand(`[ ${menu_postimg_} ] 隐藏文章开头大图`, function(){menu_switch(menu_postimg,'xiu2_menu_postimg','隐藏文章开头大图')}); + menu_hideTitle_ID = GM_registerMenuCommand(`[ ${menu_hideTitle_} ] 隐藏浏览回答标题`, function(){menu_switch(menu_hideTitle,'xiu2_menu_hideTitle','隐藏浏览回答标题')}); menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});}); } @@ -43,10 +49,10 @@ function menu_switch(menu_status, Name, Tips) { if (menu_status){ GM_setValue(`${Name}`, false); - GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500}); + GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000}); }else{ GM_setValue(`${Name}`, true); - GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500}); + GM_notification({text: `已开启 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3000}); } registerMenuCommand(); // 重新注册脚本菜单 }; @@ -54,7 +60,7 @@ // 添加样式 function addStyle() { - var style, + let style, style_1 = ` .GlobalSideBar,.Question-sideColumn,.ContentLayout-sideColumn,.SearchSideBar,.Card.QuestionHeaderTopicMeta { display: none !important; @@ -69,14 +75,11 @@ z-index: 999 !important; } `, - style_2 = ` -/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */ + style_2 = `/* 隐藏在各列表中查看文章时开头显示的大图,不影响文章、专栏页面 */ .RichContent img.ArticleItem-image { display: none !important; -} -`, - style_3 = ` -/* 调整文章编辑页面与实际文章宽度一致 */ +}`, + style_3 = `/* 调整文章编辑页面与实际文章宽度一致 */ .PostEditor .RichText { min-width: 690px !important; } @@ -84,14 +87,23 @@ .WriteIndex-titleInput .Input { min-width: 690px !important; font-size: 24px; -} -` - var style_Add = document.createElement('style'); +}`, + style_4 = `/* 浏览回答时,向下翻隐藏顶栏(问题的标题)*/ +header.is-hidden { +display: none; +}` + let style_Add = document.createElement('style'); + // 宽屏显示 + style = style_1; + // 隐藏文章开头大图 if (menu_postimg) { - style = style_1 + style_2; - }else{ - style = style_1; + style += style_2; } + // 浏览回答向下翻时自动隐藏标题 + if (menu_hideTitle) { + style += style_4; + } + // 文章编辑页面与实际文章宽度一致 if(window.location.href.indexOf("zhuanlan") > -1){ if(window.location.href.indexOf("/edit") > -1){ style += style_3;