// ==UserScript== // @name 知乎去除广告、阅读增强、隔离跳转中间层 // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description 知乎去除广告、阅读增强、隔离跳转中间层 // @author CHuilin // @match *://*.zhihu.com/* // @match https://v.vzuu.com/video/* // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js // @require https://lib.baomitu.com/jquery-cookie/1.4.1/jquery.cookie.min.js // @resource zhihu-beautify https://update.greasyfork.org/scripts/523346/zhihu-beautify.user.css // @connect zhihu.com // @connect vzuu.com // @grant GM_info // @grant GM_download // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_addStyle // @grant GM_getResourceText // @grant GM_setClipboard // @run-at document-end // ==/UserScript== /* var hideIndexSidebar; //隐藏首页侧边栏 var hideQuestionSidebar; //隐藏回答侧边栏 var hideSearchSideBar; //隐藏搜索侧边栏 var hideTopicSideBar; //隐藏话题侧边栏 var hideCollectionSideBar; //隐藏收藏侧边栏 //var hideClubSideBar; //隐藏圈子侧边栏(X) //var hideDraftSideBar; //隐藏草稿侧边栏(X) //var hideLaterSideBar; //隐藏稍后答侧边栏(X) var hideRingSideBar; //隐藏圈子侧边栏 var hideProfileSidebar; //隐藏用户主页侧边栏 var hideColumnSideBar; //隐藏专栏文章侧边栏 var hideRecommendedReading; //隐藏专栏推荐阅读 var publishTop; //置顶回答时间 var GIFAutoPlay; //GIF自动播放 var hoverShadow; //悬停时显示浅蓝色边框 var blockingPictureVideo; //隐藏图片/视频 var flowTag; //显示信息流标签 var prefersColorScheme; //跟随系统夜间模式 var hideFeedSource; //隐藏动态来源 */ class ZhihuConfig { constructor() { // 设置界面的分类(顺序即页签顺序;key 需与下方 configItems 的 group 对应) this.groups = [ { key: 'nav', label: 'AI/广告' }, { key: 'sidebar', label: '侧边栏' }, { key: 'content', label: '内容' }, { key: 'appearance', label: '外观与交互' } ]; // 定义配置项(group 决定它出现在哪个分类页签下) this.configItems = [ // ---- AI/广告 ----(顶栏的 AI 入口、推广入口,以及页面右下角的「看山」AI) { name: 'hideNavAiWorks', label: '隐藏「AI Works」', type: 'checkbox', default: '1', group: 'nav'}, { name: 'hideNavStory', label: '隐藏「故事」', type: 'checkbox', default: '1', group: 'nav'}, { name: 'hideNavZhida', label: '隐藏「直答」', type: 'checkbox', default: '1', group: 'nav'}, { name: 'hideKanshan', label: '隐藏「看山」AI', type: 'checkbox', default: '1', group: 'nav'}, // ---- 侧边栏 ----(标题不带「隐藏」二字:右侧下拉框已经说明是「隐藏 / 不隐藏」) { name: 'hideIndexSidebar', label: '首页侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideQuestionSidebar', label: '回答侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideSearchSideBar', label: '搜索侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideTopicSideBar', label: '话题侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideCollectionSideBar', label: '收藏侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideRingSideBar', label: '圈子侧边栏', type: 'select', default: '0', group: 'sidebar'}, { name: 'hideRecentSideBar', label: '最近浏览侧边栏', type: 'select', default: '1', group: 'sidebar'}, { name: 'hideProfileSidebar', label: '用户主页侧边栏', type: 'select', default: '0', group: 'sidebar'}, { name: 'hideColumnSideBar', label: '专栏文章侧边栏', type: 'select', default: '1', group: 'sidebar'}, // ---- 内容 ---- { name: 'hideRecommendedReading', label: '隐藏专栏推荐', type: 'checkbox', default: '1', group: 'content'}, { name: 'publishTop', label: '置顶回答时间', type: 'checkbox', default: '1', group: 'content'}, { name: 'blockingPictureVideo', label: '隐藏图片/视频', type: 'checkbox', default: '0', group: 'content'}, { name: 'hideUnderlineAnnotation', label: '隐藏下划线标注', type: 'checkbox', default: '1', group: 'content'}, { name: 'flowTag', label: '显示信息流标签', type: 'checkbox', default: '0', group: 'content'}, { name: 'hideFeedSource', label: '隐藏动态来源', type: 'checkbox', default: '1', group: 'content'}, { name: 'hideColumnPageHeader', label: '隐藏专栏吸顶标题栏', type: 'checkbox', default: '1', group: 'content'}, // ---- 外观与交互 ---- { name: 'hoverShadow', label: '悬停时显示浅蓝色边框', type: 'checkbox', default: '1', group: 'appearance'}, { name: 'prefersColorScheme', label: '跟随系统夜间模式', type: 'checkbox', default: '0', group: 'appearance'}, { name: 'GIFAutoPlay', label: 'GIF自动播放', type: 'checkbox', default: '0', group: 'appearance'}, { name: 'hideNotifications', label: '隐藏通知消息', type: 'checkbox', default: '1', group: 'appearance'} ]; this.currentValues = {}; this.initConfig(); } // 初始化配置 initConfig() { this.configItems.forEach(item => { const value = GM_getValue(item.name); if (value === undefined) { GM_setValue(item.name, item.default); this.currentValues[item.name] = item.default; } else { this.currentValues[item.name] = value; } }); } // 打印当前配置值 printValue() { console.log('当前值\n'); this.configItems.forEach(item => { console.log(`${item.name}=${this.currentValues[item.name]}`); }); console.log('\n'); } // 打印保存配置值 printStorageValue() { console.log('保存值\n'); this.configItems.forEach(item => { console.log(`${item.name}=${GM_getValue(item.name)}`); }); console.log('\n'); } // 生成设置界面 HTML(顶部页签 + 按 group 分组的选项面板,全部由 configItems 驱动) generateSettingsHTML() { let tabsHTML = ''; let groupsHTML = ''; let isFirst = true; this.groups.forEach(group => { const items = this.configItems.filter(item => item.group === group.key); if (items.length === 0) return; // 该分类下没有配置项就不生成页签 tabsHTML += ` ${group.label}`; let itemsHTML = ''; items.forEach(item => { if (item.type === 'select') { itemsHTML += `
${item.label}
`; } else if (item.type === 'checkbox') { itemsHTML += `
${item.label}
`; } }); groupsHTML += `
${itemsHTML}
`; isFirst = false; }); return `
${tabsHTML}
${groupsHTML}
保存并刷新
`; } // 保存设置 saveSettings() { this.configItems.forEach(item => { if (item.type === 'select') { this.currentValues[item.name] = $(`#${item.name}`).val(); } else if (item.type === 'checkbox') { this.currentValues[item.name] = $(`#${item.name}`).val(); } GM_setValue(item.name, this.currentValues[item.name]); }); $('#settingLayerMask').hide(); window.location.reload(); } // 清空所有设置值 clearValue() { this.configItems.forEach(item => { GM_deleteValue(item.name); }); } } const Config = new ZhihuConfig(); //日间模式图标(base64) var light = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDIC' + 'ItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTkxNjA2NzI5MzM4IiB' + 'jbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjkxNSIgd2lk' + 'dGg9IjMyIiBoZWlnaHQ9IjMyIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PGRlZnM+PHN0eWxlIHR5cGU9InRleHQvY3NzIj5AZm9udC1mY' + 'WNlIHsgZm9udC1mYW1pbHk6IGVsZW1lbnQtaWNvbnM7IHNyYzogdXJsKCJjaHJvbWUtZXh0ZW5zaW9uOi8vYmJha2hubWZramVuZmJoamRkZGlwY2VmbmhwaWtqYmovZm9udH' + 'MvZWxlbWVudC1pY29ucy53b2ZmIikgZm9ybWF0KCJ3b2ZmIiksIHVybCgiY2hyb21lLWV4dGVuc2lvbjovL2JiYWtobm1ma2plbmZiaGpkZGRpcGNlZm5ocGlramJqL2ZvbnR' + 'zL2VsZW1lbnQtaWNvbnMudHRmICIpIGZvcm1hdCgidHJ1ZXR5cGUiKTsgfQo8L3N0eWxlPjwvZGVmcz48cGF0aCBkPSJNNTEyLjEgNzQzLjVjLTEyNy42IDAtMjMxLjQtMTAz' + 'LjgtMjMxLjQtMjMxLjRzMTAzLjgtMjMxLjQgMjMxLjQtMjMxLjQgMjMxLjQgMTAzLjggMjMxLjQgMjMxLjQtMTAzLjggMjMxLjQtMjMxLjQgMjMxLjR6IG0wLTM5My40Yy04O' + 'S4zIDAtMTYyIDcyLjctMTYyIDE2MnM3Mi43IDE2MiAxNjIgMTYyIDE2Mi03Mi43IDE2Mi0xNjItNzIuNy0xNjItMTYyLTE2MnpNNTEyLjEgMjI3LjFjLTE5LjIgMC0zNC43LT' + 'E1LjUtMzQuNy0zNC43Vjk4LjdjMC0xOS4yIDE1LjUtMzQuNyAzNC43LTM0LjcgMTkuMiAwIDM0LjcgMTUuNSAzNC43IDM0Ljd2OTMuN2MwIDE5LjEtMTUuNSAzNC43LTM0Ljc' + 'gMzQuN3pNMjg2IDMyMC43Yy04LjkgMC0xNy44LTMuNC0yNC41LTEwLjJsLTY2LjMtNjYuM2MtMTMuNi0xMy42LTEzLjYtMzUuNSAwLTQ5LjEgMTMuNS0xMy42IDM1LjUtMTMu' + 'NiA0OS4xIDBsNjYuMyA2Ni4zYzEzLjYgMTMuNiAxMy42IDM1LjUgMCA0OS4xYTM0LjY4IDM0LjY4IDAgMCAxLTI0LjYgMTAuMnpNMTkyLjQgNTQ2LjhIOTguN2MtMTkuMiAwL' + 'TM0LjctMTUuNS0zNC43LTM0LjcgMC0xOS4yIDE1LjUtMzQuNyAzNC43LTM0LjdoOTMuN2MxOS4yIDAgMzQuNyAxNS41IDM0LjcgMzQuNyAwIDE5LjEtMTUuNSAzNC43LTM0Lj' + 'cgMzQuN3pNMjE5LjggODM5LjFjLTguOSAwLTE3LjgtMy40LTI0LjUtMTAuMi0xMy42LTEzLjYtMTMuNi0zNS41IDAtNDkuMWw2Ni4zLTY2LjNjMTMuNS0xMy42IDM1LjUtMTM' + 'uNiA0OS4xIDAgMTMuNiAxMy42IDEzLjYgMzUuNSAwIDQ5LjFsLTY2LjMgNjYuM2MtNi45IDYuOC0xNS43IDEwLjItMjQuNiAxMC4yek01MTIuMSA5NjAuMmMtMTkuMiAwLTM0' + 'LjctMTUuNS0zNC43LTM0Ljd2LTkzLjdjMC0xOS4yIDE1LjUtMzQuNyAzNC43LTM0LjcgMTkuMiAwIDM0LjcgMTUuNSAzNC43IDM0Ljd2OTMuN2MwIDE5LjItMTUuNSAzNC43L' + 'TM0LjcgMzQuN3pNODA0LjQgODM5LjFjLTguOSAwLTE3LjgtMy40LTI0LjUtMTAuMmwtNjYuMy02Ni4zYy0xMy42LTEzLjYtMTMuNi0zNS41IDAtNDkuMSAxMy41LTEzLjYgMz' + 'UuNS0xMy42IDQ5LjEgMGw2Ni4zIDY2LjNjMTMuNiAxMy42IDEzLjYgMzUuNSAwIDQ5LjFhMzQuNjggMzQuNjggMCAwIDEtMjQuNiAxMC4yek05MjUuNSA1NDYuOGgtOTMuN2M' + 'tMTkuMiAwLTM0LjctMTUuNS0zNC43LTM0LjcgMC0xOS4yIDE1LjUtMzQuNyAzNC43LTM0LjdoOTMuN2MxOS4yIDAgMzQuNyAxNS41IDM0LjcgMzQuNyAwIDE5LjEtMTUuNSAz' + 'NC43LTM0LjcgMzQuN3pNNzM4LjIgMzIwLjdjLTguOSAwLTE3LjgtMy40LTI0LjUtMTAuMi0xMy42LTEzLjYtMTMuNi0zNS41IDAtNDkuMWw2Ni4zLTY2LjNjMTMuNS0xMy42I' + 'DM1LjUtMTMuNiA0OS4xIDAgMTMuNiAxMy42IDEzLjYgMzUuNSAwIDQ5LjFsLTY2LjMgNjYuM2MtNi45IDYuOC0xNS44IDEwLjItMjQuNiAxMC4yeiIgZmlsbD0iI2Y0ZWEyYS' + 'IgcC1pZD0iOTE2Ij48L3BhdGg+PC9zdmc+'; //夜间模式图标(base64) var dark = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDI' + 'CItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTkxNjAzODE3ODAwI' + 'iBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjExMDEiI' + 'HhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+QGZvb' + 'nQtZmFjZSB7IGZvbnQtZmFtaWx5OiBlbGVtZW50LWljb25zOyBzcmM6IHVybCgiY2hyb21lLWV4dGVuc2lvbjovL2JiYWtobm1ma2plbmZiaGpkZGRpcGNlZm5ocGlramJqL' + '2ZvbnRzL2VsZW1lbnQtaWNvbnMud29mZiIpIGZvcm1hdCgid29mZiIpLCB1cmwoImNocm9tZS1leHRlbnNpb246Ly9iYmFraG5tZmtqZW5mYmhqZGRkaXBjZWZuaHBpa2pia' + 'i9mb250cy9lbGVtZW50LWljb25zLnR0ZiAiKSBmb3JtYXQoInRydWV0eXBlIik7IH0KPC9zdHlsZT48L2RlZnM+PHBhdGggZD0iTTUwMy40IDk1OS4yYy0xNTYuMSAwLTMwM' + 'y4xLTgzLjItMzgzLjUtMjE3LjNsLTQ1LjgtNzYuMyA4Ny4yIDE3LjNjNDQgOC44IDg4LjkgOC42IDEzMy4yLTAuNkMzODIuNiA2NjQuNCA0NTguMyA2MTMgNTA3LjggNTM4Y' + 'zQ5LjUtNzUuMSA2Ni44LTE2NC45IDQ4LjctMjUzLTExLjgtNTcuMy0zOC40LTExMC43LTc2LjktMTU0LjRsLTU4LjctNjYuNyA4OC44IDEuMmMyNDMuMSAzLjQgNDQwLjggM' + 'jAzLjkgNDQwLjggNDQ3IDAgMjQ2LjUtMjAwLjYgNDQ3LjEtNDQ3LjEgNDQ3LjF6TTIzOC4zIDc2OC4xYzY4LjUgNzEuNCAxNjMgMTEyLjMgMjY1LjEgMTEyLjMgMjAzLjEgM' + 'CAzNjguMy0xNjUuMiAzNjguMy0zNjguMyAwLTE3MS42LTExOS42LTMxNy40LTI3OS44LTM1Ny40IDE5LjQgMzUuNyAzMy41IDc0LjMgNDEuOCAxMTQuNCA0Ni4xIDIyNC40L' + 'Tk4LjkgNDQ0LjQtMzIzLjMgNDkwLjUtMjQgNS00OCA3LjgtNzIuMSA4LjV6IiBmaWxsPSIjMDAwMDAwIiBwLWlkPSIxMTAyIj48L3BhdGg+PC9zdmc+'; //显示快捷键窗口 var $hint = $(`
; `); /* //添加"匿名"按钮 function addAnonymous($QuestionHeaderActions, $more) { var a = ''; var $anonymous = $(a); $anonymous.bind("click", function() { $more.find("button").click(); $(".Menu.QuestionHeader-menu").children().eq(0).click(); }); $QuestionHeaderActions.append($anonymous); } */ //添加"问题日志"按钮 function addLog($QuestionHeaderActions) { var url = window.location.href; var end, href; if (url.indexOf("?") > -1) { end = url.indexOf("?"); url = url.substring(0, end); } if (url.indexOf("answer") > -1) { end = url.indexOf("answer"); href = url.substring(0, end); } else { href = url + "/"; } var L = ''; var $log = $(L); $QuestionHeaderActions.append($log); } //添加"快捷键"按钮 function addShortCut($QuestionHeaderActions) { var s = ''; var $shortcut = $(s); $shortcut.css({ "margin-left": "10px" }); $shortcut.click(function() { $(".Modal-wrapper").show(); }); $QuestionHeaderActions.append($shortcut); } //UTC标准时转UTC+8北京时间 function getUTC8(datetime) { let month = (datetime.getMonth() + 1) < 10 ? "0" + (datetime.getMonth() + 1) : (datetime.getMonth() + 1); let date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate(); let hours = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours(); let minutes = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes(); let seconds = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds(); return (datetime.getFullYear() + "-" + month + "-" + date + "\xa0\xa0" + hours + ":" + minutes + ":" + seconds); } //回答页 function question() { //回答隐藏侧边栏 if (Config.currentValues.hideQuestionSidebar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $('.css-bkewaf').hide(); $(".Question-sideColumn").hide(); $(".Question-sideColumn--sticky").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 if ($(".ListShortcut").length > 0) { $(".ListShortcut").width($(".css-6b8m40").width()); $(".Question-mainColumn").width($(".ListShortcut").width()); $(".ContentItem-actions").width($(".Question-mainColumn").width() - 40); //每个回答的margin-left + margin-right=40px,减去才能正好居中 } else { $(".Question-mainColumn").width($(".css-6b8m40").width()); $(".ContentItem-actions").width($(".Question-mainColumn").width() - 40); //每个回答的margin-left + margin-right=40px,减去才能正好居中 } } else if (Config.currentValues.hideQuestionSidebar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $('.css-bkewaf').hide(); $(".Question-sideColumn").hide(); $(".Question-sideColumn--sticky").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".css-6b8m40").attr("style", "display:flex;justify-content:center;"); $(".ContentItem-actions").width($(".Question-mainColumn").width() - 40); //每个回答的margin-left + margin-right=40px,减去才能正好居中 } //"等你来答"隐藏侧边栏 if (window.location.href.indexOf("waiting") > -1) { if (Config.currentValues.hideIndexSidebar == 1) //隐藏侧边栏并拉宽内容 { //不在首页导航栏,所在页面已无侧边栏 //拉宽内容 $(".QuestionWaiting-mainColumn").width($(".QuestionWaiting").width()); } else if (Config.currentValues.hideIndexSidebar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //不在首页导航栏,所在页面已无侧边栏 //居中内容 $(".QuestionWaiting").attr("style", "display:flex;justify-content:center;"); } } /* //"稍后答"隐藏侧边栏 if (Config.currentValues.hideLaterSideBar == 1) //隐藏侧边栏并拉宽内容 { $('.css-1qyytj7').hide(); $(".GlobalSideBar").hide(); $(".QuestionLater-mainColumn").width($(".QuestionLater").width()); } else if (Config.currentValues.hideLaterSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { $('.css-1qyytj7').hide(); $(".GlobalSideBar").hide(); $(".QuestionLater").attr("style", "display:flex;justify-content:center;"); } */ //问题编辑时间参考:https://greasyfork.org/zh-CN/scripts/398195 if ($(".QuestionPage .QuestionHeader-side p").length == 0 && window.location.href.indexOf("log") == -1) //非问题日志页 { let createtime = $(".QuestionPage>[itemprop~=dateCreated]").attr("content"); let modifiedtime = $(".QuestionPage>[itemprop~=dateModified]").attr("content"); createtime = getUTC8(new Date(createtime)); modifiedtime = getUTC8(new Date(modifiedtime)); $(".QuestionPage .QuestionHeader-side").append('

创建时间:  ' + createtime + '

最后编辑:  ' + modifiedtime + '

'); } //快捷键提示框 if ($(".Modal-wrapper").length == 0) { $(document.body).append($hint); $(".Modal-wrapper").hide(); $(".Modal-closeButton").click(function() { $(".Modal-wrapper").hide(); }); } //问题标题 var $QuestionHeaderActions = $("div.QuestionHeaderActions"); var $titlemore = $QuestionHeaderActions.find(".Zi--Dots").parent().parent().parent(); //更多 var $titlereport = $QuestionHeaderActions.find(".Title.Zi--Report"); //举报 /*var $anonymous = $(".Zi--Anonymous"); //匿名*/ var $log = $(".Zi--Log"); //日志 var $shortcut = $(".Zi--ShortCut"); //快捷键 if ($(".AppHeader-profileAvatar").length > 0) //已登录 { if ($titlereport.length == 0) //题目未添加举报 { $titlemore.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $titlemore.find("button").click(); $(".Menu.QuestionHeader-menu").children().eq(2).click(); }); $titlemore.after($report); } /* if ($anonymous.length == 0) //未添加匿名 { addAnonymous($QuestionHeaderActions, $titlemore); } */ if ($log.length == 0) //未添加查看问题日志 { addLog($QuestionHeaderActions); } if ($shortcut.length == 0) //未添加快捷键帮助 { addShortCut($QuestionHeaderActions); } /* //回答举报按钮 $(".ContentItem-actions").each(function() { if ($(this).find(".Zi--Report").length == 0 && $(this).find(".Zi--Settings").length == 0) //未添加举报 且 不是自己的回答 { let $question_dot = $(this).find(".Zi--Dots").closest(".ContentItem-action"); $question_dot.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $question_dot.find("button").click(); $(".Menu.AnswerItem-selfMenu").find("button").each(function() { if ($(this).text().indexOf("举报") > -1) $(this).click(); }); }); $question_dot.before($report); } else { $(this).find(".Zi--Dots").closest(".ContentItem-action").hide(); } }); */ //不感兴趣按钮 $(".Zi--Disinterested").parent().parent().hover(function() { $(this).find(".Zi--Disinterested").attr("fill", "rgb(252,96,123)"); $(this).attr("style", "color:rgb(252,96,123)"); }, function() { $(this).find(".Zi--Disinterested").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //问题回答举报按钮、不感兴趣按钮 $(".ContentItem-actions").each(function() { if (window.location.href.indexOf('/follow') == -1 && $(this).find(".Zi--Disinterested").length == 0 && $(this).find(".Zi--Settings").length == 0) //未添加不感兴趣 且 不是自己的回答 { let $question_dot = $(this).find(".Zi--Dots").closest(".ContentItem-action"); $question_dot.hide(); let button_text = ''; let $disinterested = $(button_text); $disinterested.bind("click", function() { let $disinterestedBtn = $(this); let buttonPos = $disinterestedBtn.offset(); let buttonWidth = $disinterestedBtn.outerWidth(); // 创建一个观察器来监听DOM变化 let observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { mutation.addedNodes.forEach(function(node) { if (node.nodeType === 1) { // 元素节点 if ($(node).hasClass('Popover-content') || $(node).find('.Popover-content').length) { let $popover = $(node).hasClass('Popover-content') ? $(node) : $(node).find('.Popover-content'); // 立即计算并设置位置 let popoverWidth = $popover.outerWidth(); let left = buttonPos.left + (buttonWidth / 2) - (popoverWidth / 2); let top = buttonPos.top + $disinterestedBtn.outerHeight(); // 在元素插入DOM后立即设置位置,避免重绘 requestAnimationFrame(function() { $popover.css({ 'left': left + 'px', 'top': top + 'px', 'opacity': '1' }); // 设置箭头位置 $popover.find('.Popover-arrow--bottom').css({ 'left': (popoverWidth / 2) + 'px' }); // 查找举报按钮并隐藏 let $lastButton = $popover.find('button:last-child'); if ($lastButton.length && $lastButton.text().indexOf('举报') !== -1) { $lastButton.hide(); } }); } } }); } }); }); // 开始观察文档变化 observer.observe(document.body, { childList: true, subtree: true }); // 触发原始按钮点击 $question_dot.find("button").click(); // 3秒后停止观察 setTimeout(() => { observer.disconnect(); }, 3000); }); $question_dot.before($disinterested); } else { $(this).find(".Zi--Dots").closest(".ContentItem-action").hide(); } if ($(this).find(".Zi--Report").length == 0 && $(this).find(".Zi--Settings").length == 0) //未添加举报 且 不是自己的回答 { let $question_dot = $(this).find(".Zi--Dots").closest(".ContentItem-action"); $question_dot.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $question_dot.find("button").click(); $(".Menu.AnswerItem-selfMenu").find("button").each(function() { if ($(this).text().indexOf("举报") > -1) { $(this).click(); $('.Popover-content').hide(); } }); }); $question_dot.before($report); } else { $(this).find(".Zi--Dots").closest(".ContentItem-action").hide(); } }); } else //未登录 { $(".Zi--Dots").parent().parent().parent().hide(); $log = $(".Zi--Log"); //日志 $shortcut = $(".Zi--ShortCut"); //快捷键 if ($log.length == 0) //未添加查看问题日志 { addLog($QuestionHeaderActions); } if ($shortcut.length == 0) //未添加快捷键帮助 { addShortCut($QuestionHeaderActions); } } //调整问题的按钮间距 $(".QuestionHeaderActions .QuestionHeader-Comment").css({ "margin": "0px 0px 0px 0px" }); $(".QuestionHeaderActions .Popover.ShareMenu").css({ "margin": "0px 0px 0px 0px" }); $(".QuestionHeaderActions .Button.Button--plain.Button--withIcon.Button--withLabel").css({ "margin": "0px 0px 0px 9px" }); var $QuestionButtonGroup = $(".QuestionHeader-footer-main").find(".QuestionButtonGroup"); $QuestionButtonGroup.children().eq(0).css({ "margin": "0px 0px 0px 8px" }); $QuestionButtonGroup.children().eq(1).css({ "margin": "0px 0px 0px 8px" }); $(".QuestionHeaderActions").children().eq(0).css({ "margin": "0px 8px 0px 0px" }); $(".GoodQuestionAction-commonBtn").css("margin", "0px 0px 0px 0px"); $('.css-8pep6o').width($('.AnswerForm.css-1ot8pew').width()); $('.css-29tdoj').width($('.css-8pep6o').width()); $('.InputLike.AnswerForm-editor').width($('.css-29tdoj').width()); $('.css-arjme8').width($('.toolbarV3.css-10r8x72').width()); $('.css-jis2as').width($('.css-arjme8').width()); $('.css-29tdoj').width($('.css-arjme8').width()); $('.css-1pfsia3').width($('.css-arjme8').width()); //回答的发布时间 $(".ContentItem.AnswerItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); console.log(data_tooltip) var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); if ($(this).find(".RichContent").length > 0) { $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); } else //没有RichContent { $(this).find(".ContentItem-time:not(.css-18wtfyc):nth-of-type(2)").hide(); } $(this).find(".ContentItem-meta").append(temp_time); } } } /* //移动关注按钮到用户名旁边 if($(this).find('.FollowButton').length>0 && !$(this).find('.FollowButton').hasClass('left')) { let width=$(this).find('.AuthorInfo:not(.AnswerItem-authorInfo)').width()+10; $(this).find('.FollowButton').css({'position':'absolute', 'left': width}); $(this).find('.FollowButton').addClass('left'); } */ }); //关怀版回答的发布时间 $(".List-item.aria-answer-item").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); $(this).find(".aria-content").prepend(temp_time); } } }); $(".Pc-card.Card").attr("style", "display:none"); //查看全部回答按钮变色 $(".QuestionMainAction").attr("style", "color:white;background-color:#0084FF"); //将问题描述中的转义字符进行转义 if (!$('.QuestionRichText--expandable.QuestionRichText--collapsed').hasClass('done')) { let description = $('.QuestionRichText--expandable.QuestionRichText--collapsed>div>span').text(); description = description.replace(/"/g, '"'); description = description.replace(/&/g, '&'); description = description.replace(/</g, '<'); description = description.replace(/>/g, '>'); description = description.replace(/ /g, ' '); $('.QuestionRichText--expandable.QuestionRichText--collapsed>div>span').text(description); $('.QuestionRichText--expandable.QuestionRichText--collapsed').addClass('done'); } } //知乎跳转链接转为直链 function directLink() { // ---- 内部工具函数:解析知乎跳转链接 ---- function resolveZhihuLink($el, fallbackText) { var href = $el.attr('href') || ''; var result = ''; // 1. 优先处理 link.zhihu.com 跳转参数 var targetIdx = href.indexOf('link.zhihu.com/?target='); if (targetIdx > -1) { var target = href.substring(targetIdx + 'link.zhihu.com/?target='.length); try { result = decodeURIComponent(target); // 直接解码,无需替换 % } catch (e) { result = target; // 如果解码失败(极少见),保留原字符串 } } // 2. 如果提供了备选文本且包含 "http",直接使用 else if (fallbackText && fallbackText.indexOf('http') > -1) { result = fallbackText.trim(); } // 3. 处理 href 中直接编码的 URL(你原有的兜底逻辑) else { var ext = href; if (ext.lastIndexOf('https%3A%2F%2F') > -1) { result = ext.substring(ext.lastIndexOf('https%3A%2F%2F')); } else if (ext.lastIndexOf('http%3A%2F%2F') > -1) { result = ext.substring(ext.lastIndexOf('http%3A%2F%2F')); } else { result = href; } try { result = decodeURIComponent(result); // 同样直接解码 } catch (e) { // 保持原样 } } // 4. 如果结果不是以 http:// 或 https:// 开头,补上 http://(防止相对路径) if (result && !/^https?:\/\//i.test(result)) { result = 'http://' + result; } return result; } // ---- 文字链接 ---- $("a.external").each(function() { var new_href = resolveZhihuLink($(this)); $(this).attr("href", new_href); }); // ---- 卡片链接 ---- $("a.LinkCard:not(.MCNLinkCard):not(.ZVideoLinkCard):not(.ADLinkCardContainer)").each(function() { var $this = $(this); var title = $this.find(".LinkCard-title").text(); var desc = $this.find(".LinkCard-desc").text(); var fallback = (title.indexOf('http') > -1) ? title : desc; var new_href = resolveZhihuLink($this, fallback); $this.attr("href", new_href); }); // ---- 旧版视频卡片链接 ---- $("a.VideoCard-link").each(function() { var new_href = resolveZhihuLink($(this)); $(this).attr("href", new_href); }); // ---- 古早视频卡片链接 ---- $("a.video-box").each(function() { var new_href = resolveZhihuLink($(this)); $(this).attr("href", new_href); }); // ---- 隐藏广告卡片 ---- $(".TopstoryItem--advertCard").hide(); $('.RichText-Ecommerce').hide(); $('.RichText-EduCardContainer').hide(); } //专栏文章 function zhuanlan() { //隐藏推荐文章 if (Config.currentValues.hideRecommendedReading == 1) { $(".Recommendations-Main").hide(); } //专栏文章隐藏侧边栏 if (Config.currentValues.hideColumnSideBar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $(".css-1ni4jcm").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".css-c0fani").width($(".css-kjzwqj").width()); $(".ContentItem-actions").width($(".css-c0fani").width() - 32); //每个回答的padding-left + padding-right=32px,减去才能正好居中 //预览文章拉宽内容 if($('.PreviewPost-content').length > 0) { GM_addStyle(` .css-78p1r9{ max-width: 1000px; } .PreviewPost-Main{ width: 1000px; } `); } } else if(Config.currentValues.hideColumnSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $(".css-1ni4jcm").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".css-kjzwqj").attr("style", "display:flex;justify-content:center;"); } //专栏举报按钮 if ($(".Zi--Report").length == 0) //未添加举报 { let $lastchild = $(".ContentItem-actions").children().eq(-1); if ($lastchild.find(".Zi--Dots").length > 0) $lastchild.hide(); var button_text = ''; var $report = $(button_text); $report.bind("click", function() { $lastchild.find("button").click(); $(".Menu.Post-ActionMenu").find("button").click(); }); $lastchild.after($report); } //有"编辑于"时,增加发布时间 if ($(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1 && !$(".ContentItem-time:not(.css-18wtfyc)").hasClass("done")) { let bianjiyu = $(".ContentItem-time:not(.css-18wtfyc)").text(); $(".ContentItem-time:not(.css-18wtfyc)").click(); $(".ContentItem-time:not(.css-18wtfyc)").text($(".ContentItem-time:not(.css-18wtfyc)").text() + "\xa0\xa0,\xa0\xa0" + bianjiyu); $(".ContentItem-time:not(.css-18wtfyc)").addClass("done"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { //正式文章 if($('.Post-content').length > 0) { if($(".Post-Header").find(".ContentItem-time").length == 0) { let temp_time = $('.Post-content').find(".ContentItem-time").clone(); $('.Post-content').find(".ContentItem-time").hide(); temp_time.css({ "padding": "0px 0px 0px 0px", "margin-top": "14px" }); temp_time.appendTo($(".Post-Header")); } } //预览文章 else if($('.PreviewPost-content').length > 0) { if($(".PreviewPost-Main > header").find(".ContentItem-time").length == 0) { let temp_time = $('.PreviewPost-Main').find(".ContentItem-time").clone(); $('.PreviewPost-Main').find(".ContentItem-time").hide(); temp_time.css({ "padding": "0px 0px 0px 0px", "margin-top": "14px" }); temp_time.appendTo($(".PreviewPost-Main > header")); } } } //专栏设置的已选菜单项变色 $(".css-17px4ve").parent().each(function() { if ($(this).find(".css-17px4ve").children().length > 0) { $(this).css("color", "black"); $(this).find(".Zi--Check").attr("fill", "black"); } }); $('.css-sdgtgb').width($('.css-10r8x72').width()); } //想法 function pin(){ if($('#pin-style').length == 0) { GM_addStyle(` html[data-theme=light] body{background:white!important;} html[data-theme=dark] body{background:rgb(18,18,18)!important;} html[data-theme=dark] .PinToolbar-menuContainer .Menu{display:none!important;} html[data-theme=dark] .PinDetail{background: #191b1f; padding: 20px;} `).id='pin-style'; } /* //想法喜欢按钮 if ($(".Zi--Heart").length == 0) //未添加喜欢 { let $lastchild = $(".ContentItem-actions").children().eq(-1); if ($lastchild.find(".ZDI--Dots24").length > 0) $lastchild.hide(); let button_text = '';var $report = $(button_text); let $heart = $(button_text); $heart.bind("click", function() { $lastchild.find("button").click(); let $button=$(".PinToolbar-menuContainer .Menu").find("button").eq(0); if($button.text().indexOf("取消喜欢")>-1) { $button.click(); $('.Button.Zi--Heart').prop('lastChild').nodeValue=' 喜欢'; } else if($button.text().indexOf("喜欢")>-1) { $button.click(); $('.Button.Zi--Heart').prop('lastChild').nodeValue=' 已喜欢'; } }); $lastchild.before($heart); } */ //想法编辑按钮 $(".ZDI--PencilFill24").closest('.ContentItem-action').hover(function() { $(this).attr("style", "color:#1772f6 !important"); }, function() { $(this).attr("style", "color:#8590A6 !important"); }); //想法删除按钮 $(".ZDI--TrashFill24").closest('.ContentItem-action').hover(function() { $(this).attr("style", "color:red !important"); }, function() { $(this).attr("style", "color:#8590A6 !important"); }); //想法举报按钮 if ($('.ZDI--PencilFill24').length==0 && $(".Zi--Report").length == 0) //未添加举报 { let $lastchild = $(".ContentItem-actions").children().eq(-1); if ($lastchild.find(".ZDI--Dots24").length > 0) $lastchild.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $lastchild.find("button").click(); $(".PinToolbar-menuContainer .Menu").find("button").eq(-1).click(); }); $lastchild.after($report); } //有"编辑于"时,增加发布时间 if ($(".ContentItem-time:not(.css-18wtfyc)").find('a').text().indexOf("编辑于") > -1 && !$(".ContentItem-time:not(.css-18wtfyc)").hasClass("done")) { let data_tooltip = $(".ContentItem-time:not(.css-18wtfyc)").find('a').attr('data-tooltip'); let old_text=$(".ContentItem-time:not(.css-18wtfyc)").find('a').text(); $(".ContentItem-time:not(.css-18wtfyc)").find('a').text(data_tooltip+ "\xa0\xa0,\xa0\xa0" + old_text); $(".ContentItem-time:not(.css-18wtfyc)").addClass("done"); } //发布时间置顶 if (Config.currentValues.publishTop == 1 && $(".ContentItem-meta").find(".ContentItem-time:not(.css-18wtfyc)").length == 0) { let $ContentItem_time_old=$(".ContentItem-time:not(.css-18wtfyc)"); $ContentItem_time_old.hide(); let $ContentItem_time=$ContentItem_time_old.clone(); $ContentItem_time.css({ "padding": "0px 0px 0px 0px", "margin-top": "14px", "display":"block" }); $ContentItem_time.appendTo($(".ContentItem-meta")); } } //视频页 function zvideo(){ if($('#zvideo-style').length == 0) { GM_addStyle(` html[data-theme=dark] .ContentItem-actions{background: #121212 !important;} `).id='zvideo-style'; } //隐藏推荐视频 $(".ZVideo-sideColumn").hide(); //上传视频 if (window.location.href.indexOf('upload-video') > 0) { if($('#zvideo-style').length == 0) { GM_addStyle(` html[data-theme=dark] main{background:rgb(18,18,18)} `).id='zvideo-style'; } } //视频清晰度自动选择最高 if ($('.ZVideo-player div._e296pg:nth-of-type(2) button._5mnvxuz').length > 0 && !$('.ZVideo-player div._e296pg:nth-of-type(2) button._5mnvxuz').hasClass('clear')) { if ($('.ZVideo-player div._e296pg:nth-of-type(2) div._txfrwp button').eq(0).attr('class') != '_rpcx17q') { $('.ZVideo-player div._e296pg:nth-of-type(2) div._txfrwp button').eq(0).click(); $('.ZVideo-player div._e296pg:nth-of-type(2) button._5mnvxuz').addClass('clear'); } } } /* //知乎圈子 function club() { //知乎圈子隐藏侧边栏 if (Config.currentValues.hideClubSideBar == 1) //隐藏侧边栏并拉宽内容 { $(".ClubSideBar").hide(); $(".Club-mainColumn").width($(".Club-container").width()); $(".ClubEdit").width($(".Club-mainColumn").width() - 40); //每个提问的margin-left + margin-right=40px,减去才能正好居中 $('.ClubTopPosts').width($(".Club-mainColumn").width() - 32); $('.ClubPostList').width($(".Club-mainColumn").width()); $('.PostItem.css-1b27c42').width($(".Club-mainColumn").width() - 32); $('section').css('border-right', 'none'); } else if (Config.currentValues.hideClubSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { $(".ClubSideBar").hide(); $(".Club-mainColumn").parent().attr("style", "display:flex;justify-content:center;"); $(".ClubEdit").width($(".Club-mainColumn").width() - 40); //每个提问的margin-left + margin-right=40px,减去才能正好居中 $('.ClubTopPosts').width($(".Club-mainColumn").width() - 32); $('.ClubPostList').width($(".Club-mainColumn").width()); $('.PostItem.css-1b27c42').width($(".Club-mainColumn").width() - 32); $('section').css('border-right', 'none'); } //退出圈子按钮 var $ClubHeaderInfo_buttonGroup = $(".ClubHeaderInfo-buttonGroup"); var $child1 = $ClubHeaderInfo_buttonGroup.children().eq(1 - 1); var $child2 = $ClubHeaderInfo_buttonGroup.children().eq(2 - 1); if ($child2.length > 0 && $child2.text().indexOf("签到") > -1 && $child2.text().indexOf("加入") == -1) //退出圈子 { $child1.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $child1.find("button").click(); $(".ClubHeaderInfoMoreButton-item").click(); }); $child1.after($report); } //圈子中提问举报按钮 $(".PostReaction").each(function() { var $post_dot = $(this).find(".Zi--Dots").closest(".Popover"); if ($(this).find(".Zi--Report").length == 0) //未添加举报 { $post_dot.hide(); let button_text = ''; let $report = $(button_text); $report.bind("click", function() { $post_dot.find("button").click(); $(".PostWebActionButtons-item").click(); }); $post_dot.after($report); } }); //有"最后回复"时,增加发布时间 $(".PostItem-time").each(function() { if ($(this).text().indexOf("发布时间") == -1 && $(this).parent().text().indexOf("最后回复") > -1) { let datetime = new Date($(this).attr("datetime")); let posttime = getUTC8(datetime); let replytime = $(this).text(); $(this).parent().get(0).childNodes[1].nodeValue = ""; $(this).parent().get(0).childNodes[2].nodeValue = ""; $(this).text("发布时间 " + posttime + "\xa0\xa0,\xa0\xa0" + "最后回复 " + replytime); } }); } */ //知乎圈子 const ring = (function() { let widthFlag = 0; let lastUrl = ''; return function() { // URL 变化时重置标志 const currentUrl = window.location.href; if (currentUrl !== lastUrl) { widthFlag = 0; lastUrl = currentUrl; } //全部圈子 if(window.location.href.includes('/ring-feeds')) { // ===== 为避免首页干扰,提前恢复正文及侧边栏默认样式 ==== // 恢复侧边栏显示(防止首页隐藏后残留) $('.css-bkewaf').show(); $('a[aria-label="边栏锚点"]').closest('div').show(); // 恢复内容区域默认宽度(移除之前可能设置的内联宽度) $(".Topstory-mainColumn, .Topstory-mainColumnCard, .Topstory-content").css('width', ''); // 如果有居中样式,也移除 $(".Topstory-mainColumn").css('display', ''); //全部圈子隐藏侧边栏 if (Config.currentValues.hideRingSideBar == 1) //隐藏侧边栏并拉宽内容 { //使用 GM 存储的目标宽度,不存在时为 null let storedWidth = GM_getValue('totalWidth', null); if ($(".Topstory-container").length > 0) { // 首次执行时,需要计算并存储目标宽度 if (storedWidth === null) { //侧边栏 let $sidebar = $(".css-bkewaf"); //内容 let $content = $(".Topstory-mainColumn"); // 必须保证侧边栏可见,否则无法得到正确宽度 if ($sidebar.is(':visible')) { let totalWidth = $content.width() + $sidebar.width(); GM_setValue('totalWidth', totalWidth); storedWidth = totalWidth; } else { // 侧边栏不可见,可延时重试或直接使用备用值(可选) return; } } //只要 storedWidth 有效,就执行布局调整 if (storedWidth !== null) { //隐藏侧边栏 $('.css-bkewaf').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".Topstory-mainColumn").width(storedWidth); $(".Topstory-mainColumnCard").width(storedWidth); $(".Topstory-content").width(storedWidth); $(".css-1g878q7").width(storedWidth); $(".css-ekkpum").width(storedWidth); $(".css-18mcbdu").width(storedWidth); //与圈友分享你的想法...(它的父元素) let coverWidth=$(".css-poklwr").width(); let coverHeight=$(".css-poklwr").height(); $(".css-poklwr").width(storedWidth).height(coverHeight*storedWidth/coverWidth); // 原 widthFlag 不再需要 } } } else if (Config.currentValues.hideRingSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //使用 GM 存储的目标宽度,不存在时为 null let storedWidth = GM_getValue('totalWidth', null); if ($(".Topstory-container").length > 0) { // 首次执行时,需要计算并存储目标宽度 if (storedWidth === null) { //侧边栏 let $sidebar = $(".css-bkewaf"); //内容 let $content = $(".Topstory-mainColumn"); // 必须保证侧边栏可见,否则无法得到正确宽度 if ($sidebar.is(':visible')) { let totalWidth = $content.width() + $sidebar.width(); GM_setValue('totalWidth', totalWidth); storedWidth = totalWidth; } else { // 侧边栏不可见,可延时重试或直接使用备用值(可选) return; } } //只要 storedWidth 有效,就执行布局调整 if (storedWidth !== null) { //隐藏侧边栏 $('.css-bkewaf').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 let totalWidth=$(".Topstory-container").width(); $(".Topstory-mainColumn").attr("style", "display:flex;justify-content:center;"); $(".Topstory-mainColumn").width(totalWidth); //与圈友分享你的想法...(它的祖父元素) $(".css-7cywyh").attr("style", "display:flex;justify-content:center;"); // 原 widthFlag 不再需要 } } } //圈子的发布时间 $(".ContentItem.PinItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); if ($(this).find(".RichContent").length > 0) { $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); } else //没有RichContent { $(this).find(".ContentItem-time:not(.css-18wtfyc):nth-of-type(2)").hide(); } $(this).find(".ContentItem-meta").append(temp_time); } } } if($(this).find('.Button.ContentItem-more').length>0) { $(this).find('.Button.ContentItem-more').click(); } }); } //特定圈子 else { //特定圈子隐藏侧边栏 if (Config.currentValues.hideRingSideBar == 1) //隐藏侧边栏并拉宽内容 { //防止切换圈子后不断变宽 //使用 GM 存储的目标宽度,不存在时为 null let storedWidth = GM_getValue('totalWidth', null); if ($(".css-14pitda").length > 0) { // 首次执行时,需要计算并存储目标宽度 if (storedWidth === null) { //侧边栏 let $sidebar = $(".css-ill7fe"); //内容 let $content = $(".css-kboer3"); // 必须保证侧边栏可见,否则无法得到正确宽度 if ($sidebar.is(':visible')) { let totalWidth = $content.width() + $sidebar.width(); GM_setValue('totalWidth', totalWidth); storedWidth = totalWidth; // 赋值后继续执行下面的调整 } else { // 侧边栏不可见,无法计算,直接返回(可在此添加延时重试,例如 setTimeout 重新执行本段逻辑) return; } } //只要 storedWidth 有效,就执行布局调整 if (storedWidth !== null) { //隐藏侧边栏 $('.css-ill7fe').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".css-kboer3").width(storedWidth); $(".css-1lo6frp").width(storedWidth); $(".css-exh6me").width(storedWidth); //操作按钮与内容对齐 GM_addStyle(`.css-1rnr3jg .RichContent-actions.is-fixed{width:${$(".css-kboer3").width()}px !important;}`).id='ring-style'; // 原 widthFlag 不再需要 } } } else if (Config.currentValues.hideRingSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //使用 GM 存储的目标宽度,不存在时为 null let storedWidth = GM_getValue('totalWidth', null); if ($(".css-14pitda").length > 0) { // 首次执行时,需要计算并存储目标宽度 if (storedWidth === null) { //侧边栏 let $sidebar = $(".css-ill7fe"); //内容 let $content = $(".css-kboer3"); // 必须保证侧边栏可见,否则无法得到正确宽度 if ($sidebar.is(':visible')) { let totalWidth = $content.width() + $sidebar.width(); GM_setValue('totalWidth', totalWidth); storedWidth = totalWidth; // 赋值后继续执行下面的调整 } else { // 侧边栏不可见,无法计算,直接返回(可在此添加延时重试,例如 setTimeout 重新执行本段逻辑) return; } } //只要 storedWidth 有效,就执行布局调整 if (storedWidth !== null) { //隐藏侧边栏 $('.css-ill7fe').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".css-14pitda").attr("style", "display:flex;justify-content:center;"); //操作按钮与内容对齐 GM_addStyle(`.css-1rnr3jg .RichContent-actions.is-fixed{width:${$(".css-kboer3").width()}px !important;}`).id='ring-style'; // 原 widthFlag 不再需要 } } } //圈子的发布时间 $(".ContentItem.PinItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); if ($(this).find(".RichContent").length > 0) { $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); } else //没有RichContent { $(this).find(".ContentItem-time:not(.css-18wtfyc):nth-of-type(2)").hide(); } $(this).find(".ContentItem-meta").append(temp_time); } } } if($(this).find('.Button.ContentItem-more').length>0) { $(this).find('.Button.ContentItem-more').click(); } }); } }; })(); //获取url中?后面的参数 function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } return (false); } //搜索结果页 function search() { if($('#search-style').length == 0) { GM_addStyle(`.css-14iuq0r{left:auto; transform: none;-webkit-transform: none;-ms-transform: none;} html[data-theme=dark] .css-9x92ah{background: #191b1f} `).id='search-style'; } //搜索结果隐藏侧边栏 if (Config.currentValues.hideSearchSideBar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $('.css-1m4ta6s').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".SearchMain").width($(".Search-container").width()); } else if (Config.currentValues.hideSearchSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $('.css-1m4ta6s').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".Search-container").attr("style", "display:flex;justify-content:center;"); } $(".ContentItem.AnswerItem, .ContentItem.ArticleItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时,增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".SearchItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("SearchItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); $(this).find(".SearchItem-meta").append(temp_time); } } } }); //隐藏相关推荐的卡片,仅保留问题卡片 /* $(".RelevantQuery").closest(".Card.SearchResult-Card").hide(); $(".KfeCollection-PcCollegeCard-wrapper").closest(".Card.SearchResult-Card").hide(); if (getQueryVariable("type") == "content") { $('.Card.SearchResult-Card[data-za-detail-view-path-module=\"UserItem\"]').hide(); } */ //显示搜索页综合信息流标签 if (Config.currentValues.flowTag == 1 && getQueryVariable("type") == "content") { $('.Card .List-item .ContentItem').each(function() { if ($(this).find('.Tag').length == 0) { let type; if ($(this).attr('itemprop') != undefined) type = $(this).attr('itemprop'); else if ($(this).attr('itemtype') != undefined && $(this).attr('itemtype').indexOf('Zvideo') > -1) type = 'zvideo'; let typebackground = "", typename = ""; if (type == 'answer') { typebackground = "#0084FF"; typename = '问题'; } else if (type == 'article') { typebackground = "orange"; typename = '文章'; } else if (type == 'zvideo') { typebackground = "red"; typename = '视频'; } if (typename != "") { let tag = '
' + typename + '
'; $(this).find('.ContentItem-title a').before($(tag)); } } }); $('.Card.css-oo264i .css-ywimgq').each(function() { if ($(this).find('.Tag').length == 0) { let tag = '
视频
'; $(this).prepend($(tag)); } }); } } //知乎讲座 function lives() { $("[class*=\'LiveWechatSpread\']").hide(); //隐藏微信推荐 } //收藏夹 function collection() { //收藏夹隐藏侧边栏 if (Config.currentValues.hideCollectionSideBar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $('.css-bkewaf').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".CollectionsDetailPage-mainColumn").width($(".CollectionsDetailPage").width()); } else if (Config.currentValues.hideCollectionSideBar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $('.css-bkewaf').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".CollectionsDetailPage").attr("style", "max-width:694px; display:flex; justify-content:center;"); } //收藏夹举报按钮 $(".ContentItem-actions").each(function() { var $collect_dot = $(this).find(".Zi--Dots").closest(".Popover"); if ($(this).find(".Zi--Report").length == 0) //未添加举报 { $collect_dot.hide(); var button_text = '' let $report = $(button_text); $report.bind("click", function() { $collect_dot.find("button").click(); $('.Popover-content').hide(); $(".AnswerItem-selfMenu button").click(); }); $collect_dot.after($report); if($collect_dot.closest('.Post-ActionMenuButton').length>0 ) $collect_dot.closest('.Post-ActionMenuButton').css('margin-left','0px'); } }); } let style_underline = 0; //按钮变色 function iconColor() { //隐藏下划线标注 if(Config.currentValues.hideUnderlineAnnotation==1) { if($('#style-underline').length == 0) { GM_addStyle(` /*下划线*/ .highlight-wrap { padding-bottom: 0px !important; } .highlight-wrap.other{ border-bottom: none !important; } /*评论小气泡*/ .highlight-wrap.has-comments:after{ display: none !important; } /*下划线点击高亮*/ .highlight-wrap.highlight-wrap-checking{ background: none !important; } @supports (color:lab(from red l 1 1%/calc(alpha + 0.1))) { .highlight-wrap.highlight-wrap-checking { background: none !important; } } /*弹出按钮组*/ .css-fg13ww{ display: none !important; } .ZDI--AgreeFill24.css-tz36ol{ display: none !important; } `).id='style-underline'; } } //隐藏通知气泡 if(Config.currentValues.hideNotifications==1) { if($('#style-notifications').length == 0) { GM_addStyle(` /*隐藏通知气泡*/ .AppHeader[role="banner"] .css-1jdj7vi{ display: none !important; } `).id='style-notifications'; } // 保存原始的 title 描述符 const originalDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'title') || Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'title'); // 正则:去掉开头括号通知内容及后面可能有的空格 function cleanTitle(rawTitle) { return rawTitle.replace(/^\([^)]*\)\s*/, ''); } // 拦截 document.title 的赋值 Object.defineProperty(document, 'title', { get: function() { // 读取时返回真实的 title 文本(取干净的) // 注意直接读取原始 getter 即可 return originalDescriptor.get.call(this); }, set: function(value) { // 写入时先清理,再调用原始 setter const cleaned = cleanTitle(value); originalDescriptor.set.call(this, cleaned); }, configurable: true, enumerable: true }); // 脚本启动时页面可能已经有一个标题了,顺手也清一下 document.title = cleanTitle(document.title); } //引用角标高亮 $('.ztext sup[data-draft-type=reference]').click(function() { $('.ReferenceList li').removeClass('is-active'); let ref_id = $(this).find('a').attr('href'); $(this).closest('.List-item').find(ref_id).addClass('is-active'); $(this).closest('.ContentItem.AnswerItem').find(ref_id).addClass('is-active'); $(this).closest('.Post-content').find(ref_id).addClass('is-active'); $(this).closest('.TopicIntroContent').find(ref_id).addClass('is-active'); }); //悬停时显示浅蓝色边框 if (Config.currentValues.hoverShadow == 1) { if (typeof($("html").attr("data-hover-visible")) == "undefined") { $("html").attr("data-hover-visible", "1"); } $("html").removeAttr("data-focus-visible"); //避免快捷键变色的影响 } //折叠按钮 $(".Zi--EyeSlash").parent().parent().hover(function() { $(this).find(".Zi--EyeSlash").attr("fill", "#22d3c3"); $(this).attr("style", "color:#22d3c3"); }, function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消折叠") > -1) { $(this).find(".Zi--EyeSlash").attr("fill", "#22d3c3"); $(this).attr("style", "color:#22d3c3"); } else { $(this).find(".Zi--EyeSlash").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); //推荐按钮 $(".Zi--Recommend").parent().parent().hover(function() { if (!$(this).hasClass('QuestionWaiting-types')) { $(this).find(".Zi--Recommend").attr("fill", "#fcd02d"); $(this).attr("style", "color:#fcd02d"); } }, function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消推荐") > -1) { $(this).find(".Zi--Recommend").attr("fill", "#fcd02d"); $(this).attr("style", "color:#fcd02d"); } else { $(this).find(".Zi--Recommend").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); $(".Zi--List").parent().parent().hover(function() { $(this).find(".Zi--List").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { $(this).find(".Zi--List").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //评论按钮 $(".Zi--Comment").parent().parent().hover(function() { $(this).find(".Zi--Comment").attr("fill", "#0084FF"); if ($(this).closest(".QuestionHeaderActions").length > 0) $(this).attr("style", "color:#0084FF;margin: 0px 0px 0px 9px;"); else $(this).attr("style", "color:#0084FF"); }, function() { if ($(this).closest(".QuestionHeaderActions").length > 0) { $(this).find(".Zi--Comment").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); } else if ($(this).closest(".css-b2n9t9").length > 0) { $(this).find(".Zi--Comment").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } else if ($(this).prop('lastChild').nodeValue.indexOf("收起评论") == -1) { $(this).find(".Zi--Comment").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); /* //评论按钮(展开评论时) $(".Zi--Comment").parent().parent().each(function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("收起评论") > -1) { $(this).find(".Zi--Comment").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); } }); */ //评论按钮 $(".ZDI--ChatBubbleFill24").closest('.ContentItem-action').hover(function() { $(this).find(".Zi--Comment").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); },function(){ $(this).find(".Zi--Comment").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //评论按钮(展开评论时) $(".ZDI--ChatBubbleFill24").closest('.ContentItem-action').each(function() { if ($(this).parent().hasClass('ContentItem-actions--hotCommentExpanded')) { $(this).find(".Zi--Comment").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); } }); $('.Zi--Catalog').closest('button').hover(function() { $(this).attr('style', 'color:#10dede'); }, function() { $(this).attr('style', 'color:#8590a6'); }); //评论弹窗关闭按钮 $(".Zi--Close").on("click", function() { $(".Zi--Comment").parent().parent().each(function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("收起评论") > -1) { $(this).find(".Zi--Comment").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); }); /* //私信按钮 $(".Zi--Comments").parent().parent().hover(function () { $(this).find(".Zi--Comments").find("path").attr("fill", "#00FF7F"); $(this).css({ "color": "#00FF7F" }); }, function () { if ($(this).hasClass("CommentItemV2-talkBtn")) //评论区查看回复按钮变色 { $(this).find(".Zi--Comments").find("path").attr("fill", "#8590a6"); $(this).css({ "color": "#8590a6" }); } else if ($(this).hasClass("CreationCard-ActionButton")) //内容管理查看评论按钮变色 { $(this).css({ "color": "#8590a6" }); //图标变色在css中实现 } else if ($(".Messages-content").length == 0) //私信框消失,私信按钮变色 { if ($("html").attr("data-theme") == "dark") { $(this).find(".Zi--Comments").find("path").attr("fill", "#8590a6"); $(this).css({ "color": "#8590a6" }); } else { $(this).find(".Zi--Comments").find("path").attr("fill", "rgb(68,68,68)"); $(this).css({ "color": "rgb(68,68,68)" }); } } }); */ //回复按钮 $(".Zi--Reply").parent().parent().hover(function() { $(this).find(".Zi--Reply").attr("fill", "#32CD32"); $(this).attr("style", "color:#32CD32"); }, function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消回复") == -1) { $(this).find(".Zi--Reply").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); //回复按钮(点击后持续变色) $(".Zi--Reply").parent().parent().each(function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消回复") > -1) { $(this).find(".Zi--Reply").attr("fill", "#32CD32"); $(this).attr("style", "color:#32CD32"); } }); //回复按钮(点击后持续变色) $('.css-1o56bgb').click(function() { if ($(this).closest('.css-14nvvry').find('.css-fw5oj4').length == 0) { $(this).attr('style', 'color:#32CD32'); } else { $(this).removeAttr('style'); } }) //点赞按钮 $(".Zi--Like:not(.css-4ky835)").parent().parent().hover(function() { if (window.location.href.indexOf("search") > -1) { if ($(this).hasClass("SearchTopicReview-Icon--like") || $(this).hasClass("SearchTopicReview-Icon--liked")) { $(this).find(".Zi--Like").find("path").attr("fill", "#FF4D82"); $(this).attr("style", "color:#FF4D82;"); } else { $(this).find(".Zi--Like").find("path").attr("fill", "black"); $(this).attr("style", "color:black;"); } } else if (window.location.href.indexOf("people") > -1 || window.location.href.indexOf("org") > -1) { $(this).find(".Zi--Like").attr("fill", "#FF4D82"); //$(this).attr("style", "color:#FF4D82;"); } else if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("踩") > -1 || $(this).attr("data-tooltip") == "不推荐") { if ($("html").attr("data-theme") == "dark") { $(this).find(".Zi--Like").attr("fill", "white"); $(this).css("color", "white"); } else { $(this).find(".Zi--Like").attr("fill", "black"); $(this).css("color", "black"); } } else if ($(this).hasClass('css-8mg22s')) { $(this).find(".Zi--Like").attr("fill", "#FF4D82"); $(this).attr("style", "color:#FF4D82;"); } else { $(this).find(".Zi--Like").attr("fill", "#FF4D82"); $(this).attr("style", "color:#FF4D82;margin:0px;"); } }, function() { if ($(this).find("#topic-recommend").length > 0 || $(this).find("#topic-against").length > 0 || $(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消踩") == -1) $(this).find(".Zi--Like").attr("fill", "currentColor"); if (window.location.href.indexOf("search") > -1) { $(this).find(".Zi--Like").find("path").attr("fill", "#8590A6"); $(this).attr("style", "color:#8590A6;"); } else if (window.location.href.indexOf("people") > -1 || window.location.href.indexOf("org") > -1) { $(this).attr("style", "color:#646464;"); } else if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("取消踩") > -1) { $(this).attr("style", "color:black;"); } else if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue.indexOf("踩") > -1 || $(this).attr("data-tooltip") == "不推荐") { $(this).attr("style", "color:#8590A6;"); } else if ($(this).hasClass('css-8mg22s')) { $(this).find(".Zi--Like").attr("fill", "#8590A6"); $(this).attr("style", "color:#8590A6;"); } else $(this).attr("style", "color:#8590A6; margin:0px;"); }); //踩按钮(点击后持续变色) $(".Zi--Like").parent().parent().each(function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue == "取消踩") $(this).find(".Zi--Like").attr("fill", "black"); if (window.location.href.indexOf("search") > -1) { if ($(this).hasClass("SearchTopicReview-Icon--liked")) { $(this).find(".Zi--Like").find("path").attr("fill", "#FF4D82"); $(this).attr("style", "color:#FF4D82;"); } } else if (window.location.href.indexOf("people") > -1 || window.location.href.indexOf("org") > -1) { if ($(this).hasClass("css-zkfaav") || $(this).hasClass("is-liked")) { $(this).find(".Zi--Like").attr("fill", "#FF4D82"); //$(this).attr("style", "color:#FF4D82;"); } } }); //评论区点赞按钮 $(".ZDI--ThumbFill24").parent().parent().hover(function() { $(this).find(".Zi--Like").attr("fill", "#FF4D82"); $(this).attr("style", "color:#FF4D82;"); }, function() { if ($(this).hasClass("css-h1yvwn")) { $(this).find(".Zi--Like").attr("fill", "#8590A6"); $(this).attr("style", "color:#8590A6;"); } }); $(".GoodQuestionAction-highLightBtn").attr("style", "color:#FF4D82;margin:0px;"); //题目点赞后保持变色 $(".is-liked").attr("style", "color:#FF4D82;margin:0px;"); //评论点赞后保持变色 /* //分享按钮 $(".Zi--Share").parent().parent().parent().hover(function() { $(this).find(".Zi--Share").attr("fill", "blue"); if ($(this).closest(".QuestionHeaderActions").length > 0) $(this).find("button").attr("style", "color:blue;margin: 0px 0px 0px 9px;"); else if ($(this).find(".Post-SideActions-icon").length > 0) $(this).attr("style", "color:blue;"); else $(this).find("button").attr("style", "color:blue;"); }, function() { $(this).find(".Zi--Share").attr("fill", "currentColor"); if ($(this).closest(".QuestionHeaderActions").length > 0) $(this).find("button").attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); else if ($(this).find(".Post-SideActions-icon").length > 0) $(this).attr("style", "color:#8590A6;"); else $(this).find("button").attr("style", "color:#8590A6;"); }); */ //分享按钮 $(".ZDI--ArrowShapeTurnRightFill24").closest('.ShareMenu-toggler').hover(function() { if($(this).closest('.QuestionHeader-footer').length > 0) { $(this).find(".ZDI--ArrowShapeTurnRightFill24").attr("fill", "blue"); $(this).find('button').attr("style", "color:blue; margin: 0px 0px 0px 9px;"); } else { $(this).find(".ZDI--ArrowShapeTurnRightFill24").attr("fill", "blue"); $(this).find('button').attr("style", "color:blue;"); } },function() { if($(this).closest('.QuestionHeader-footer').length > 0) { $(this).find(".ZDI--ArrowShapeTurnRightFill24").attr("fill", "currentColor"); $(this).find('button').attr("style", "color:8590A6; margin: 0px 0px 0px 9px;"); } else { $(this).find(".ZDI--ArrowShapeTurnRightFill24").attr("fill", "currentColor"); $(this).find('button').attr("style", "color:8590A6;"); } }); /* //分享按钮(点击后持续变色) $(".ZDI--ArrowShapeTurnRightFill24").closest('.ShareMenu-toggler').each(function() { if($(this).attr('aria-expanded') == 'true') { $(this).find(".ZDI--ArrowShapeTurnRightFill24").attr("fill", "blue"); $(this).find('button').attr("style", "color:blue"); } }); */ /* //收藏按钮 $(".Zi--Star").parent().parent().hover(function() { if (!$(this).hasClass("ExploreHomePage-ContentSection") && !$(this).hasClass("css-18biwo") && !$(this).hasClass("css-g9eqf4-StrutAlign")) { $(this).find(".Zi--Star").attr("fill", "orange"); $(this).attr("style", "color:orange"); } }, function() { if (!$(this).hasClass("ExploreHomePage-ContentSection") && !$(this).hasClass("css-18biwo") && !$(this).hasClass("css-g9eqf4-StrutAlign")) { $(this).find(".Zi--Star").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); */ //收藏按钮 $(".Zi--Star").closest('.ContentItem-action').hover(function() { if (!$(this).hasClass("ExploreHomePage-ContentSection") && !$(this).hasClass("css-18biwo") && !$(this).hasClass("css-g9eqf4-StrutAlign")) { $(this).find(".Zi--Star").attr("fill", "orange"); $(this).attr("style", "color:orange"); } }, function() { if (!$(this).hasClass("ExploreHomePage-ContentSection") && !$(this).hasClass("css-18biwo") && !$(this).hasClass("css-g9eqf4-StrutAlign")) { $(this).find(".Zi--Star").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); } }); //收藏按钮(点击后持续变色) $(".Zi--Star").closest('.ContentItem-action').each(function() { if ($(this).prop('lastChild').nodeValue != null) { if($(this).attr('aria-label') == '已收藏' && $(this).prop('lastChild').nodeValue != "收藏") { $(this).find(".Zi--Heart").attr("fill", "orange"); $(this).attr("style", "color:orange"); } } }); //喜欢按钮 $(".Zi--Heart").parent().parent().hover(function() { if (!$(this).hasClass('AppHeaderProfileMenu') && !$(this).hasClass('MobileAppHeader-actions')) { $(this).find(".Zi--Heart").attr("fill", "red"); $(this).attr("style", "color:red"); } }, function() { if ($(this).prop('lastChild').nodeValue == "喜欢") $(this).find(".Zi--Heart").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); /* //喜欢按钮(点击后持续变色) $(".Zi--Heart").parent().parent().each(function() { if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue == "取消喜欢") $(this).prop('lastChild').nodeValue = "已喜欢"; if ($(this).prop('lastChild').nodeValue != null && $(this).prop('lastChild').nodeValue == "已喜欢") { $(this).find(".Zi--Heart").attr("fill", "red"); $(this).attr("style", "color:red"); } }); */ //喜欢按钮 $('.Zi--Heart').closest('.ContentItem-action').hover(function(){ $(this).find(".Zi--Heart").attr("fill", "red"); $(this).attr("style", "color:red"); },function(){ $(this).find(".Zi--Heart").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //喜欢按钮(点击后持续变色) $(".Zi--Heart").closest('.ContentItem-action').each(function() { if ($(this).prop('lastChild').nodeValue != null) { if($(this).attr('aria-label') == '取消喜欢' && $(this).prop('lastChild').nodeValue != "喜欢") { $(this).find(".Zi--Heart").attr("fill", "red"); $(this).attr("style", "color:red"); } } }); //喜欢按钮 $(".Like-likeWrapper-ejWmr").hover(function() { $(this).find('svg path').attr("style", 'fill:red'); $(this).find('span').attr("style", 'color:red'); $(this).addClass('hover'); }, function() { if ($(this).find('span').text().indexOf('已喜欢') > -1 || $(this).find('span').text().indexOf('取消喜欢') > -1) { $(this).find('svg path').attr("style", 'fill:red'); $(this).find('span').attr("style", 'color:red'); } else { $(this).find('svg path').attr("style", 'fill:#8590A6'); $(this).find('span').attr("style", 'color:#8590A6'); } $(this).removeClass('hover'); }); //喜欢按钮(点击后持续变色) $(".Like-likeWrapper-ejWmr").each(function() { if ($(this).find('span').text().indexOf('取消喜欢') > -1) $(this).find('span').text("已喜欢"); if ($(this).find('span').text().indexOf('已喜欢') > -1) { $(this).find('svg path').attr("style", 'fill:red'); $(this).find('span').attr("style", 'color:red'); } else { if (!$(this).hasClass('hover')) { $(this).find('svg path').attr("style", 'fill:#8590A6'); $(this).find('span').attr("style", 'color:#8590A6'); } } }); //举报按钮 $(".Zi--Report").parent().parent().hover(function() { $(this).find(".Zi--Report").attr("fill", "brown"); if ($(this).closest(".QuestionHeaderActions").length > 0) $(this).attr("style", "color:brown;margin: 0px 0px 0px 9px;"); else $(this).attr("style", "color:brown"); }, function() { $(this).find(".Zi--Report").attr("fill", "currentColor"); if ($(this).closest(".QuestionHeaderActions").length > 0) $(this).attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); else $(this).attr("style", "color:#8590A6"); }); //评论区举报按钮 $(".ZDI--FlagFill24").parent().parent().hover(function() { $(this).attr("style", "color:brown"); }, function() { $(this).attr("style", "color:#8590A6"); }); /* $(".Zi--Bell").parent().parent().hover(function () { $(this).find(".Zi--Bell path").attr("fill", "#FACB62"); }, function () { if ($(".PushNotifications-content").length == 0) //没有通知框,恢复原色 { if ($("html").attr("data-theme") == "light") //日间模式 { $(this).find(".Zi--Bell path").attr("fill", "rgb(68,68,68)"); } else //夜间模式 { $(this).find(".Zi--Bell path").attr("fill", "#8590A6"); } } else //有通知框,持续变色 { $(this).find(".Zi--Bell path").attr("fill", "#FACB62"); } }); $(".Zi--Bell").parent().parent().on("click", function () { if ($(".PushNotifications-content").length == 0) { $(this).find(".Zi--Bell path").attr("fill", "#FACB62"); } else { $(this).find(".Zi--Bell path").attr("fill", "currentColor"); } }); */ $(".Zi--Heart.PushNotifications-tabIcon").parent().parent().hover(function() { $(this).find(".Zi--Heart").attr("fill", "#0084FF"); }, function() { $(this).find(".Zi--Heart").attr("fill", "currentColor"); }); $(".Zi--Users").parent().parent().hover(function() { $(this).find(".Zi--Users").attr("fill", "#0084FF"); }, function() { $(this).find(".Zi--Users").attr("fill", "currentColor"); }); /* //匿名按钮 $(".Zi--Anonymous").parent().parent().hover(function() { if ($("html").attr("data-theme") == "dark") { $(this).find(".Zi--Anonymous").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3;margin: 0px 0px 0px 9px;"); } else { $(this).find(".Zi--Anonymous").attr("fill", "black"); $(this).attr("style", "color:black;margin: 0px 0px 0px 9px;"); } }, function() { $(this).find(".Zi--Anonymous").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); }); */ //查看问题日志按钮 $(".Zi--Log").parent().parent().hover(function() { $(this).find(".Zi--Log").attr("fill", "purple"); $(this).parent().attr("style", "color:purple;margin: 0px 0px 0px 9px;"); }, function() { $(this).find(".Zi--Log").attr("fill", "currentColor"); $(this).parent().attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); }); //快捷键按钮 $(".Zi--ShortCut").parent().parent().hover(function() { $(this).find(".Zi--ShortCut").attr("fill", "#44B8A1"); $(this).attr("style", "color:#44B8A1;margin: 0px 0px 0px 9px;"); }, function() { $(this).find(".Zi--ShortCut").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6;margin: 0px 0px 0px 9px;"); }); //邀请回答按钮 $(".Zi--Invite").parent().parent().hover(function() { if ($("html").attr("data-theme") == "light") { $(this).find(".Zi--Invite").attr("fill", "black"); $(this).attr("style", "color:black;margin: 0px 8px 0px 0px;"); } else { $(this).find(".Zi--Invite").attr("fill", "white"); $(this).attr("style", "color:white;margin: 0px 8px 0px 0px;"); } }, function() { $(this).find(".Zi--Invite").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6;margin: 0px 8px 0px 0px;"); }); //删除草稿按钮 $(".Zi--Trash").parent().parent().hover(function() { $(this).find(".Zi--Trash").attr("fill", "#C70000"); $(this).attr("style", "color:#C70000"); }, function() { $(this).find(".Zi--Trash").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".SelfCollectionItem-actions .Zi--EditSurround").parent().parent().hover(function() { $(this).find(".Zi--EditSurround").attr("fill", "orange"); $(this).attr("style", "color:orange"); }, function() { $(this).find(".Zi--EditSurround").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".CollectionDetailPageHeader-actions .Zi--EditSurround").parent().parent().hover(function() { $(this).find(".Zi--EditSurround").attr("fill", "orange"); $(this).attr("style", "color:orange"); }, function() { $(this).find(".Zi--EditSurround").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".Zi--Emotion").parent().parent().hover(function() { $(this).find(".Zi--Emotion").find("path").attr("fill", "#0084FF"); }, function() { $(this).find(".Zi--Emotion").find("path").removeAttr("fill"); }); $(".Zi--AddImage").parent().parent().hover(function() { $(this).find(".Zi--AddImage").find("path").attr("fill", "#0084FF"); }, function() { $(this).find(".Zi--AddImage").find("path").removeAttr("fill"); }); $(".Zi--InsertImage").find("path").attr("fill", "blue"); $(".Zi--Image").find("path").attr("fill", "blue"); $(".Zi--InsertVideo, .Zi--FormatClear").find("path").attr("fill", "red"); $(".Zi--InsertFormula").find("path").attr("fill", "rgb(115,216,244)"); $(".Zi--InsertLink").find("path").attr("fill", "#0084FF"); $(".Zi--Folder").find("path").attr("fill", "#FF8C00"); $(".Zi--EditCircle").find("path").attr("fill", "#82480E"); $(".Zi--Juror").find("path").attr("fill", "brown"); $(".Zi--Marked").find("path").attr("fill", "blue"); $(".ZDI--AgreeFill24").find("path").attr("fill", "#FB7299"); if ($("html").attr("data-theme") == "light") { $(".MathToolbar-button svg").attr("fill", "black"); $(".MathToolbar-paletteIcon").css("color", "black"); } else { $(".MathToolbar-button svg").attr("fill", "#d3d3d3"); $(".MathToolbar-paletteIcon").css("color", "#d3d3d3"); } $(".AnswerAdd-topicBiosButton").attr("style", "color:#0084FF"); $(".AnswerAdd-topicBiosButton .Zi--Edit").attr("fill", "#0084FF"); //内容管理-编辑按钮 $(".Button--withLabel .Zi--Edit").closest('.Button--withLabel').hover(function() { $(this).find(".Zi--Trash").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { $(this).find(".Zi--Trash").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //内容管理-数据按钮 $(".Button--withLabel .Zi--Statistics").closest('.Button--withLabel').hover(function() { $(this).find(".Zi--Statistics").attr("fill", "#8763f2"); $(this).attr("style", "color:#8763f2"); }, function() { $(this).find(".Zi--Statistics").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //内容管理-查看评论按钮 $(".Button--withLabel .Zi--Comments").closest('.Button--withLabel').hover(function() { $(this).find(".Zi--Statistics").attr("fill", "#00ff7fcc"); $(this).attr("style", "color:#00ff7fcc"); }, function() { $(this).find(".Zi--Statistics").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); //内容管理-更多按钮的具体菜单项 $('.Button.Menu-item.css-cn5m5x').each(function() { if ($(this).find('.Zi--Check').length > 0) { if ($('html').attr('data-theme') == 'light') { $(this).attr("style", "color:black; background:#f6f6f6"); } else { $(this).attr("style", "color:#d3d3d3; background:#1b1b1b"); } } }) $(".Zi--Document").parent().parent().hover(function() { $(this).find(".Zi--Document").find("path").attr("fill", "#FF8C00"); $(this).attr("style", "color:#FF8C00"); }, function() { $(this).find(".Zi--Document").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }); $(".Zi--Time").parent().hover(function() { if ($("html").attr("data-theme") == "light") { $(this).find(".Zi--Time").find("path").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".Zi--Time").find("path").attr("fill", "white"); $(this).attr("style", "color:white"); } }, function() { $(this).find(".Zi--Time").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }); $(".Zi--Deliver").parent().parent().hover(function() { if ($(this).hasClass('css-1uan5v7')) //专栏列表上方的"推荐文章"按钮 { $('.css-119896g').hover(function() { $(this).find(".Zi--Deliver").find("path").attr("fill", "#02E6B8"); $(this).attr("style", "color:#02E6B8"); }, function() { $(this).find(".Zi--Deliver").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }) } else //专栏文章下方的"申请转载"按钮 { $(this).find(".Zi--Deliver").find("path").attr("fill", "#02E6B8"); $(this).attr("style", "color:#02E6B8"); } }, function() { if (!$(this).hasClass('css-1uan5v7')) //专栏文章下方的"申请转载"按钮 { $(this).find(".Zi--Deliver").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); } }); $(".Zi--FullscreenEnter").parent().parent().hover(function() { $(this).find(".Zi--FullscreenEnter").find("path").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { $(this).find(".Zi--FullscreenEnter").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }); $(".Zi--FullscreenExit").parent().parent().hover(function() { $(this).find(".Zi--FullscreenExit").find("path").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { $(this).find(".Zi--FullscreenExit").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }); $(".AnswerForm-exitFullscreenButton").hover(function() { $(this).find(".AnswerForm-exitFullscreenButton").find("path").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { $(this).find(".AnswerForm-exitFullscreenButton").find("path").removeAttr("fill"); $(this).attr("style", "color:#8590A6"); }); $(".Notifications-footer .Zi--Settings").parent().parent().hover(function() { $(this).find(".Zi--Settings").attr("fill", "purple"); $(this).attr("style", "color:purple"); }, function() { $(this).find(".Zi--Settings").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".Post-ActionMenuButton .Zi--Settings").parent().parent().hover(function() { $(this).find(".Zi--Settings").attr("fill", "purple"); $(this).attr("style", "color:purple"); }, function() { $(this).find(".Zi--Settings").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".TopicActions .Zi--Settings").parent().parent().hover(function() { $(this).find(".Zi--Settings").attr("fill", "purple"); $(this).attr("style", "color:purple"); }, function() { $(this).find(".Zi--Settings").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); $(".ContentItem-action .Zi--Settings, .AnswerForm-footerRight .Zi--Settings").parent().parent().hover(function() { $(this).find(".Zi--Settings").attr("fill", "purple"); $(this).attr("style", "color:purple"); }, function() { $(this).find(".Zi--Settings").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); /* //无障碍按钮 $('.AppHeaderProfileMenu .ZDI--HeartFill16').parent().hover(function() { $(this).find(".ZDI--HeartFill16").attr("fill", "#ff7d7d"); $(this).attr("style", "color:#ff7d7d"); }, function() { if ($("html").attr("data-theme") == "light") { $(this).find(".ZDI--HeartFill16").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".ZDI--HeartFill16").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3"); } }); //设置按钮 $(".AppHeaderProfileMenu .ZDI--GearFill24").parent().hover(function() { $(this).find(".ZDI--GearFill24").attr("fill", "purple"); $(this).attr("style", "color:purple"); }, function() { if ($("html").attr("data-theme") == "light") { $(this).find(".ZDI--GearFill24").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".ZDI--GearFill24").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3"); } }); //退出按钮 $(".AppHeaderProfileMenu .ZDI--PowerFill24").parent().hover(function() { $(this).find(".ZDI--PowerFill24").attr("fill", "red"); $(this).attr("style", "color:red"); }, function() { if ($("html").attr("data-theme") == "light") { $(this).find(".ZDI--PowerFill24").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".ZDI--PowerFill24").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3"); } }); //我的主页按钮 $(".AppHeaderProfileMenu .ZDI--UserFill24").parent().hover(function() { $(this).find(".ZDI--UserFill24").attr("fill", "#08a500"); $(this).attr("style", "color:#08a500"); }, function() { if ($("html").attr("data-theme") == "light") { $(this).find(".ZDI--UserFill24").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".ZDI--UserFill24").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3"); } }); //关怀版按钮 $(".AppHeaderProfileMenu .ZDI--ElderFill16").parent().hover(function() { $(this).find(".ZDI--ElderFill16").attr("fill", "#0084FF"); $(this).attr("style", "color:#0084FF"); }, function() { if ($("html").attr("data-theme") == "light") { $(this).find(".ZDI--ElderFill16").attr("fill", "black"); $(this).attr("style", "color:black"); } else { $(this).find(".ZDI--ElderFill16").attr("fill", "#d3d3d3"); $(this).attr("style", "color:#d3d3d3"); } }); */ $('.ZDI--UserFill24').closest('.AppHeaderProfileMenu-item').addClass('UserFill24'); $('.ZDI--ClockFill24').closest('.AppHeaderProfileMenu-item').addClass('ClockFill24'); $('.ZDI--HeartFill16').closest('.AppHeaderProfileMenu-item').addClass('HeartFill16'); $('.ZDI--ElderFill16').closest('.AppHeaderProfileMenu-item').addClass('ElderFill16'); $('.ZDI--GearFill24').closest('.AppHeaderProfileMenu-item').addClass('GearFill24'); $('.ZDI--PowerFill24').closest('.AppHeaderProfileMenu-item').addClass('PowerFill24'); $(".CommentMoreReplyButton .Button").hover(function() { $(this).attr("style", "color:#00FF7F"); }, function() { $(this).attr("style", "color:#8590A6"); }); $(".CommentCollapseButton").hover(function() { $(this).find("Zi--ArrowUp").attr("fill", "#0084FF"); $(this).css({ "color": "#0084FF" }); }, function() { $(this).find("Zi--ArrowUp").attr("fill", "currentColor"); $(this).css({ "color": "#8590A6" }); }); //点击评论列表右下角出现的"收起评论"时,将评论按钮恢复灰色 $(".CommentCollapseButton").on("click", function() { let $t = $(this).closest(".Comments-container").prev().find(".Zi--Comment").parent().parent(); $t.find(".Zi--Comment").attr("fill", "currentColor"); $t.attr("style", "color:#8590A6"); }); /* $(".ContentItem-time:not(.css-18wtfyc)").each(function() { $(this).find("a").attr("style", "border-bottom: 1px solid rgba(133,144,166,.72);"); }); */ $(".Button.ContentItem-action.ContentItem-rightButton.Button--plain").attr("style", "color:#175199"); $(".QuestionRichText-more").attr("style", "color:#0084FF"); $(".QuestionHeader-actions .Button").attr("style", "color:#0084FF"); $(".Zi--Switch").attr("fill", "#0084FF"); $(".Zi--Switch").parent().parent().css("color", "#0084FF"); $(".Zi--Select").attr("fill", "#0084FF"); $(".Zi--Select").parent().css("color", "#0084FF"); $(".Zi--Dots").hover(function() { $(this).find("path").attr("fill", "#0084FF"); }, function() { $(this).find("path").attr("fill", "#8590A6"); }); $(".Zi--FormatCode").find("path").attr("fill", "#0084FF"); $(".List-headerText").css("top", "-5px"); $(".Post-ActionMenu .Button.Menu-item.Button--plain .Zi--Check").each(function() { $(this).parent().parent().parent().addClass('is-active'); }); $(".AnswerItem-selectMenuItem .Zi--Check, .CommentPermission-item .Zi--Check").each(function() { $(this).parent().parent().parent().addClass('is-active'); }); /* $(".AnswerItem-selectMenuItem").hover(function () { if ($("html").attr("data-theme") == "dark") $(this).attr("style", "color:#d3d3d3"); else $(this).attr("style", "color:black"); }, function () { if ($(this).find(".Zi--Check").length == 0) $(this).attr("style", "color:#8590A6"); }); $(".CommentPermission-item").hover(function () { if ($("html").attr("data-theme") == "dark") $(this).attr("style", "color:#d3d3d3"); else $(this).attr("style", "color:black"); }, function () { if ($(this).find(".Zi--Check").length == 0) $(this).attr("style", "color:#8590A6"); }); */ /* $(".AnswerAdd-toggleAnonymous").hover(function() { $(this).attr("style", "color:#0084FF"); }, function() { $(this).attr("style", "color:#8590A6"); }); */ $(".DisclaimerEntry").hover(function() { if ($("html").attr("data-theme") == "dark") { $(this).find("path").attr("fill", "#d3d3d3"); $(this).find("button").attr("style", "color:#d3d3d3"); } else { $(this).find("path").attr("fill", "black"); $(this).find("button").attr("style", "color:black"); } }, function() { $(this).find("path").attr("fill", "currentColor"); $(this).find("button").attr("style", "color:#8590A6"); }); $(".ImageView.CommentRichText-ImageView.is-active").css({ "z-index": "1000" }); if ($(".css-70qvj9 .Zi--CheckboxOn").length > 0) $(".css-70qvj9 .css-1d83bu8").attr("style", "color:#0084FF"); if ($(".css-70qvj9 .Zi--CheckboxOff").length > 0) $(".css-70qvj9 .css-1d83bu8").attr("style", "color:#8590A6"); /* if ($.cookie('nightmode') == undefined) $.cookie('nightmode', 0, { expires: 365, path: "/", domain: "zhihu.com" }); var $nightmode = $('
'); $nightmode.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); $.cookie('nightmode', 1, { expires: 365, path: "/", domain: "zhihu.com" }); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); $.cookie('nightmode', 0, { expires: 365, path: "/", domain: "zhihu.com" }); } }); if ($("#nightmode").length == 0) { $(".SearchBar").after($nightmode); var $nightmode_question_log = $(''); $nightmode_question_log.hover(function() { $(this).find('span').css('color', 'white'); }, function() { $(this).find('span').css('color', '#eee'); }); $("#zu-top-add-question").before($nightmode_question_log); //问题日志 $nightmode_question_log.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); $.cookie('nightmode', 1, { expires: 365, path: "/", domain: "zhihu.com" }); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); $.cookie('nightmode', 0, { expires: 365, path: "/", domain: "zhihu.com" }); } }); var $nightmode_vip = $(''); $nightmode_vip.hover(function() { $(this).find('span').css('color', 'white'); }, function() { $(this).find('span').css('color', '#eee'); }); $(".TopNavBar-root-f2drS .TopNavBar-searchBar-uo31N").after($nightmode_vip); $nightmode_vip.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); $.cookie('nightmode', 1, { expires: 365, path: "/", domain: "zhihu.com" }); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); $.cookie('nightmode', 0, { expires: 365, path: "/", domain: "zhihu.com" }); } }); var $nightmode_zhuanlan = $nightmode.clone(true); $nightmode_zhuanlan.find('button').css({ "margin": "0px 50px 0px 0px" }); $(".ColumnPageHeader-Button").before($nightmode_zhuanlan); //专栏文章 $(".ColumnPageHeader-WriteButton").before($nightmode_zhuanlan); //专栏文章 $(".PublishPanel-wrapper").before($nightmode_zhuanlan); //写文章 } if ($(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh").length > 0 && $(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh #nightmode").length == 0) //VIP页固定悬浮导航栏 { var $nightmode_vip2 = $('
'); $(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh .TopNavBar-userInfo-bqiw4").before($nightmode_vip2); $nightmode_vip2.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); $.cookie('nightmode', 1, { expires: 365, path: "/", domain: "zhihu.com" }); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); $.cookie('nightmode', 0, { expires: 365, path: "/", domain: "zhihu.com" }); } }); } //跟随系统夜间模式 if(Config.currentValues.prefersColorScheme == 1) { const is_sys_darkmode = Number(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) if(is_sys_darkmode != $.cookie('nightmode')) $.cookie('nightmode', is_sys_darkmode, { expires: 365, path: "/", domain: "zhihu.com" }) } if ($.cookie('nightmode') == 1) { $("html").attr("data-theme", "dark"); $(".nightmode").find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(".nightmode").each(function() { if ($(this).find("span").text().indexOf(" 日间模式") == -1) $(this).find("span").text(" 日间模式"); }); } else { $("html").attr("data-theme", "light"); $(".nightmode").find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(".nightmode").each(function() { if ($(this).find("span").text().indexOf(" 夜间模式") == -1) $(this).find("span").text(" 夜间模式"); }); } */ // 初始化兼容代码:迁移 cookie 到 GM_setValue (function migrateCookieToGM() { // 首先尝试从 cookie 读取夜间模式设置 var cookieValue = $.cookie('nightmode'); if (cookieValue !== undefined && cookieValue !== null) { // 将 cookie 值转换为整数 var nightmodeValue = parseInt(cookieValue, 10); if (!isNaN(nightmodeValue)) { // 保存到 GM_setValue GM_setValue('nightmode', nightmodeValue); // 删除 cookie $.removeCookie('nightmode', { path: "/", domain: "zhihu.com" }); console.log('已迁移夜间模式设置从 Cookie 到 GM_setValue: ' + nightmodeValue); } } })(); // 初始化夜间模式设置(迁移后使用) if (GM_getValue('nightmode') === undefined) { GM_setValue('nightmode', 0); } var $nightmode = $('
'); $nightmode.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); GM_setValue('nightmode', 1); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); GM_setValue('nightmode', 0); } }); if ($("#nightmode").length == 0) { $(".SearchBar").after($nightmode); var $nightmode_question_log = $(''); $nightmode_question_log.hover(function() { $(this).find('span').css('color', 'white'); }, function() { $(this).find('span').css('color', '#eee'); }); $("#zu-top-add-question").before($nightmode_question_log); //问题日志 $nightmode_question_log.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); GM_setValue('nightmode', 1); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); GM_setValue('nightmode', 0); } }); var $nightmode_vip = $(''); $nightmode_vip.hover(function() { $(this).find('span').css('color', 'white'); }, function() { $(this).find('span').css('color', '#eee'); }); $(".TopNavBar-root-f2drS .TopNavBar-searchBar-uo31N").after($nightmode_vip); $nightmode_vip.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); GM_setValue('nightmode', 1); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(this).find("span").text(" 夜间模式"); GM_setValue('nightmode', 0); } }); var $nightmode_zhuanlan = $nightmode.clone(true); $nightmode_zhuanlan.find('button').css({ "margin": "0px 50px 0px 0px" }); $(".ColumnPageHeader-Button").before($nightmode_zhuanlan); //专栏文章 $(".ColumnPageHeader-WriteButton").before($nightmode_zhuanlan); //专栏文章 $(".PublishPanel-wrapper").before($nightmode_zhuanlan); //写文章 } if ($(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh").length > 0 && $(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh #nightmode").length == 0) //VIP页固定悬浮导航栏 { var $nightmode_vip2 = $('
'); $(".TopNavBar-root-f2drS.TopNavBar-fixMode-4nQmh .TopNavBar-userInfo-bqiw4").before($nightmode_vip2); $nightmode_vip2.click(function() { if ($("html").attr("data-theme") == "light") { $("html").attr("data-theme", "dark"); $(this).find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(this).find("span").text(" 日间模式"); GM_setValue('nightmode', 1); } else { $("html").attr("data-theme", "light"); $(this).find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:20px;"); $(this).find("span").text(" 夜间模式"); GM_setValue('nightmode', 0); } }); } //跟随系统夜间模式 if(Config.currentValues.prefersColorScheme == 1) { const is_sys_darkmode = Number(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches); if(is_sys_darkmode != GM_getValue('nightmode')) { GM_setValue('nightmode', is_sys_darkmode); } } // 根据存储的值设置初始主题 var nightmodeValue = GM_getValue('nightmode'); if (nightmodeValue == 1) { $("html").attr("data-theme", "dark"); $(".nightmode").find("img").attr("src", light).attr("style", "vertical-align:middle; width:20px; height:20px;"); $(".nightmode").each(function() { if ($(this).find("span").text().indexOf(" 日间模式") == -1) $(this).find("span").text(" 日间模式"); }); } else { $("html").attr("data-theme", "light"); $(".nightmode").find("img").attr("src", dark).attr("style", "vertical-align:middle; width:18px; height:18px;"); $(".nightmode").each(function() { if ($(this).find("span").text().indexOf(" 夜间模式") == -1) $(this).find("span").text(" 夜间模式"); }); } //自动展开楼中楼评论 $('.css-7dh30y').each(function() { if ($(this).text().indexOf('展开') > -1) { $(this).click(); } }) $(".css-6f4i93").hide(); } let index_addstyle = 0; function index() { if($('#index-style').length == 0) { GM_addStyle(`.ContentItem-action {margin-left: 16px;} .App-main .Topstory div[style="opacity: 1;"]{display:none!important} .App-main .Topstory div[style="height: 180px;"]{display:none!important} `).id='index-style'; } setInterval(function() { //隐藏动态来源 if(Config.currentValues.hideFeedSource==1) { if(window.location.href.indexOf('/follow')>-1) { $('.TopstoryItem').each(function(){ let FeedSource=$(this).find('.FeedSource-firstline').text() if(FeedSource.indexOf('赞同')>-1 || FeedSource.indexOf('收藏')>-1) { $(this).hide(); } }); } } if ($('header.AppHeader').length > 0) { if (!$('header.AppHeader').hasClass('css-1x8hcdw')) $('header.AppHeader').addClass('css-1x8hcdw'); let arr1 = $('header.AppHeader').attr('class').split(' '); let arr2 = "Sticky AppHeader is-hidden is-fixed css-1x8hcdw".split(' '); let arr = arr1.filter(x => arr2.includes(x)); //交集 $('header.AppHeader').attr('class', arr.join(' ')); } if ($('.SearchBar-input').length > 0) { if (!$('.SearchBar-input').hasClass('css-11bw1mm')) $('.SearchBar-input').addClass('css-11bw1mm'); let arr1 = $('.SearchBar-input').attr('class').split(' '); let arr2 = "SearchBar-input SearchBar-input--focus css-11bw1mm Input-wrapper QZcfWkCJoarhIYxlM_sG Input-wrapper--grey is-focus evPjxqnqXpIBzSRrcIDv".split(' '); let arr = arr1.filter(x => arr2.includes(x)); //交集 $('.SearchBar-input').attr('class', arr.join(' ')); } if ($('.SearchBar-searchIcon').length > 0) { if (!$('.SearchBar-searchIcon').hasClass('css-1dlt5yv')) $('.SearchBar-searchIcon').addClass('css-1dlt5yv'); let arr1 = $('.SearchBar-searchIcon').attr('class').split(' '); let arr2 = "Zi Zi--Search SearchBar-searchIcon css-1dlt5yv".split(' '); let arr = arr1.filter(x => arr2.includes(x)); //交集 $('.SearchBar-searchIcon').attr('class', arr.join(' ')); } if ($('.SearchBar-askButton').length > 0) { $('.SearchBar-askButton').removeClass('css-47os02'); } if (!$('.Tabs-link.AppHeader-TabsLink').hasClass('css-1f6tgea')) { $('.Tabs-link.AppHeader-TabsLink').removeClass('css-11e2zdz').addClass('css-1f6tgea'); } if ($('.AppHeader-inner .css-1hlrcxk').attr('fill') != '#0066FF') { $('.AppHeader-inner .css-1hlrcxk').attr('fill', '#0066FF'); } if (!$('.SearchBar-input').hasClass('css-11bw1mm')) { $('.SearchBar-input').removeClass('css-v1juu7').addClass('css-11bw1mm'); } if (!$('.SearchBar-searchIcon').hasClass('css-1dlt5yv')) { $('.SearchBar-searchIcon').removeClass('css-1mo564z').addClass('css-1dlt5yv'); } if (!$('.SearchBar-askButton').hasClass('css-3q84jd')) { $('.SearchBar-askButton').removeClass('css-146z333').removeClass('css-rf6mh0').addClass('css-3q84jd'); } if (!$('.AppHeader-userInfo .Zi').hasClass('css-7dgah8')) { $('.AppHeader-userInfo .Zi').removeClass('css-1iyiq0j').addClass('css-7dgah8'); } }, 100); setTimeout(function() { $('.ContentItem.ZVideoItem').closest('.TopstoryItem').hide(); //隐藏视频信息流 $('.VideoAnswerPlayer').closest('.TopstoryItem').hide(); //隐藏视频回答 $('.ContentItem.EduSectionItem').closest('.TopstoryItem').hide(); //隐藏视频信息流 $('.ContentItem.ZVideoItem').remove(); $('.VideoAnswerPlayer').remove(); $('.ContentItem.EduSectionItem').remove(); }, 500); $(".Zi--Hot").find("path").css({ "fill": "red" }); $(".Zi--Share").closest(".Button").hover(function() { $(this).find("path").css({ "fill": "blue" }); $(this).css({ "color": "blue" }); }, function() { $(this).find("path").css({ "fill": "#8590A6" }); $(this).css({ "color": "#8590A6" }); }); $(".TopstoryItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); $(this).find(".ContentItem-meta").append(temp_time); } } } }); $(".Card.GlobalSideBar-category>a").hide(); $('.LoadingBar').removeClass('is-active'); $(".Zi--Disinterested").parent().parent().hover(function() { $(this).find(".Zi--Disinterested").attr("fill", "rgb(252,96,123)"); $(this).attr("style", "color:rgb(252,96,123)"); }, function() { $(this).find(".Zi--Disinterested").attr("fill", "currentColor"); $(this).attr("style", "color:#8590A6"); }); // ===== 为避免全部圈子(/ring-feeds)干扰,提前恢复正文及侧边栏默认样式 ==== // 恢复侧边栏显示(防止首页隐藏后残留) $('.css-bkewaf').show(); $('a[aria-label="边栏锚点"]').closest('div').show(); // 恢复内容区域默认宽度(移除之前可能设置的内联宽度) $(".Topstory-mainColumn, .Topstory-mainColumnCard, .Topstory-content").css('width', ''); // 如果有居中样式,也移除 $(".Topstory-mainColumn").css('display', ''); //首页隐藏侧边栏 if (Config.currentValues.hideIndexSidebar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $('.css-bkewaf').hide(); $('[data-za-detail-view-path-module="RightSideBar"]').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".Topstory-mainColumn").width($(".Topstory-container").width()); } else if (Config.currentValues.hideIndexSidebar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $('.css-bkewaf').hide(); $('[data-za-detail-view-path-module="RightSideBar"]').hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".Topstory-container").attr("style", "display:flex;justify-content:center;"); } //首页回答举报按钮、不感兴趣按钮 $(".ContentItem-actions").each(function() { if (window.location.href.indexOf('/follow') == -1 && $(this).find(".Zi--Disinterested").length == 0 && $(this).find(".Zi--Settings").length == 0) //未添加不感兴趣 且 不是自己的回答 { let $question_dot = $(this).find(".Zi--Dots").closest(".ContentItem-action"); $question_dot.hide(); let button_text = ''; let $disinterested = $(button_text); $disinterested.bind("click", function() { let $disinterestedBtn = $(this); let buttonPos = $disinterestedBtn.offset(); let buttonWidth = $disinterestedBtn.outerWidth(); // 创建一个观察器来监听DOM变化 let observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { mutation.addedNodes.forEach(function(node) { if (node.nodeType === 1) { // 元素节点 if ($(node).hasClass('Popover-content') || $(node).find('.Popover-content').length) { let $popover = $(node).hasClass('Popover-content') ? $(node) : $(node).find('.Popover-content'); // 立即计算并设置位置 let popoverWidth = $popover.outerWidth(); let left = buttonPos.left + (buttonWidth / 2) - (popoverWidth / 2); let top = buttonPos.top + $disinterestedBtn.outerHeight(); // 在元素插入DOM后立即设置位置,避免重绘 requestAnimationFrame(function() { $popover.css({ 'left': left + 'px', 'top': top + 'px', 'opacity': '1' }); // 设置箭头位置 $popover.find('.Popover-arrow--bottom').css({ 'left': (popoverWidth / 2) + 'px' }); // 查找举报按钮并隐藏 let $lastButton = $popover.find('button:last-child'); if ($lastButton.length && $lastButton.text().indexOf('举报') !== -1) { $lastButton.hide(); } }); } } }); } }); }); // 开始观察文档变化 observer.observe(document.body, { childList: true, subtree: true }); // 触发原始按钮点击 $question_dot.find("button").click(); // 3秒后停止观察 setTimeout(() => { observer.disconnect(); }, 3000); /* $(".Menu.AnswerItem-selfMenu").find("button").each(function() { //回答 if ($(this).text().indexOf("不感兴趣") > -1) { $(this).click(); } }); $(".Menu.ItemOptions-selfMenu").find("button").each(function() { //专栏 if ($(this).text().indexOf("不感兴趣") > -1) { $(this).click(); } }); */ //$('.ZVideoToolbar-menuItem').click(); //视频 }); $question_dot.before($disinterested); } else { $(this).find(".Zi--Dots").closest(".ContentItem-action").hide(); /* // 将原来的 hide() 改为设置透明和禁用交互 $(this).find(".Zi--Dots").closest(".ContentItem-action").css({ 'opacity': '0', 'pointer-events': 'none', // 禁用鼠标事件 'visibility': 'hidden' // 隐藏但仍占据位置 }); */ } if (!$(this).closest('.ContentItem').hasClass('ZVideoItem') && $(this).find(".Zi--Report").length == 0 && $(this).find(".Zi--Settings").length == 0) //非视频 且 未添加举报 且 不是自己的回答 { if($(this).closest('.ContentItem').hasClass('ArticleItem')) //文章 { let $question_dot = $(this).find(".Zi--Dots").closest(".Post-ActionMenuButton"); $question_dot.hide(); let button_text = '' let $report = $(button_text); $report.bind("click", function() { $question_dot.find("button").click(); $(".Menu.Post-ActionMenu").hide(); $(".Menu.Post-ActionMenu").find("button").each(function() { if ($(this).text().indexOf("举报") > -1) { $(this).click(); $('.Popover-content').hide(); } }); }); $question_dot.before($report); } else //回答 { let $question_dot = $(this).find(".Zi--Dots").closest(".ContentItem-action"); $question_dot.hide(); let button_text = '' let $report = $(button_text); $report.bind("click", function() { $question_dot.find("button").click(); $(".Menu.AnswerItem-selfMenu").hide(); $(".Menu.AnswerItem-selfMenu").find("button").each(function() { if ($(this).text().indexOf("举报") > -1) { $(this).click(); $('.Popover-content').hide(); } }); }); $question_dot.before($report); } } else { $(this).find(".Zi--Dots").closest(".ContentItem-action").hide(); } }); //显示首页信息流标签 if (Config.currentValues.flowTag == 1) { $('.Card .Feed .ContentItem').each(function() { if ($(this).find('.Tag').length == 0) { let typebackground = "", typename = ""; /* let zop= $(this).attr('data-zop'); let type = JSON.parse(zop)['type']; if(type=='answer') { typebackground="#0084FF"; typename='问题'; } else if(type=='article') { typebackground="orange"; typename='文章'; } else if(type=='zvideo') { typebackground="red"; typename='视频'; } */ if ($(this).hasClass('AnswerItem')) { typebackground = "#0084FF"; typename = '问题'; } else if ($(this).hasClass('ArticleItem')) { typebackground = "orange"; typename = '文章'; } else if ($(this).hasClass('ZVideoItem') || $(this).hasClass('EduSectionItem')) { typebackground = "red"; typename = '视频'; } if (typename != "") { let tag = '
' + typename + '
'; $(this).find('.ContentItem-title a').before($(tag)); } } }); } } var view_details = 0; //详细资料是否被点击的标志 //用户主页 function people() { if($('#people-style').length == 0) { GM_addStyle(`html[data-theme=dark] .css-1efr9n{color:#d3d3d3;} html[data-theme=dark] .css-h05wt0{color:#8590a6;} `).id='people-style'; } //自动点击"查看详细资料"按钮 if ($(".ProfileHeader-expandButton").text().indexOf("查看详细资料") > -1 && view_details == 0) { $(".ProfileHeader-expandButton").click(); view_details = 1; } //用户主页隐藏侧边栏 if (Config.currentValues.hideProfileSidebar == 1) //隐藏侧边栏并拉宽内容 { //隐藏侧边栏 $('.css-bkewaf').hide(); $(".Profile-sideColumn").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //拉宽内容 $(".Profile-mainColumn").width($(".Profile-main").width()); } else if (Config.currentValues.hideProfileSidebar == 2) //隐藏侧边栏,仅水平居中内容,不拉宽 { //隐藏侧边栏 $('.css-bkewaf').hide(); $(".Profile-sideColumn").hide(); $('a[aria-label="边栏锚点"]').closest('div').hide(); //居中内容 $(".Profile-main").attr("style", "display:flex;justify-content:center;"); } $(".ContentItem.AnswerItem, .ContentItem.ArticleItem").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); $(this).find(".ContentItem-meta").append(temp_time); } } } }); $("#Profile-pins .List-item").each(function() { if (!($(this).find(".ContentItem-time:not(.css-18wtfyc)").hasClass("full")) && $(this).find(".ContentItem-time:not(.css-18wtfyc)").length > 0 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text() != null) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") == -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") > -1) //只有"编辑于"时增加具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); var oldtext = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip + "\xa0\xa0,\xa0\xa0" + oldtext); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } else if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("发布于") > -1 && $(this).find(".ContentItem-time:not(.css-18wtfyc)").text().indexOf("编辑于") == -1) //只有"发布于"时替换为具体发布时间data-tooltip { let data_tooltip = $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").attr("data-tooltip"); $(this).find(".ContentItem-time:not(.css-18wtfyc)").find("a").text(data_tooltip); $(this).find(".ContentItem-time:not(.css-18wtfyc)").addClass("full"); } //发布时间置顶 if (Config.currentValues.publishTop == 1) { if ($(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("css-18wtfyc") && !$(this).find('.ContentItem-time.css-18wtfyc').hasClass('full')) { let temp_out_time = $(this).find('.ContentItem-time.css-18wtfyc').clone(); $(this).find('.ContentItem-time.css-18wtfyc').hide(); $(this).find(".ContentItem-meta").append(temp_out_time); $(this).find('.ContentItem-time.css-18wtfyc').addClass('full'); } else if (!$(this).find(".ContentItem-time:not(.css-18wtfyc)").parent().hasClass("ContentItem-meta")) { let temp_time = $(this).find(".ContentItem-time:not(.css-18wtfyc)").clone(); $(this).find(".RichContent .ContentItem-time:not(.css-18wtfyc)").hide(); $(this).find(".ContentItem-meta").append(temp_time); } } } }); } function column() { $('.css-7q9l37').hide(); $('.Menu .Menu-item').hide(); //专栏列表举报按钮 if ($('.css-16qos9m').find('.Zi--Report').length == 0) { let report = `
`; let $report = $(report); $report.click(function() { $('.css-7q9l37 button').click(); $('.Menu .Menu-item button').eq(0).click(); }); $('.css-16qos9m').append($report); } //取消关注专栏按钮 if ($('.css-16qos9m').find('.unfollow_columns').length == 0) { let $unfollow_columns = $(''); $unfollow_columns.click(function() { $('.css-7q9l37 button').click(); $('.Menu .Menu-item button').eq(1).click(); }); $('.css-16qos9m').append($unfollow_columns); } let left1=$('.css-44kk6u').css('margin-left'); let left2=$('.css-1pariuy').css('margin-left'); if(left1 != left2) { $('.css-1pariuy').css('margin-left', left1) } } //图片调整到最高清晰度 function originalPic() { if (Config.currentValues.blockingPictureVideo == 1) //隐藏图片/视频 { $('img').each(function() { if ($(this).closest('.RichContent-cover').length > 0 && !$(this).closest('.RichContent-cover').hasClass('hide')) //未隐藏 { $(this).closest('.RichContent-cover').hide(); //隐藏首页回答封面 $(this).closest('.RichContent-cover').addClass('hide'); } if ($(this).parent().attr('id') != 'nightmode' && !$(this).hasClass('Avatar')) //非夜间模式按钮,非头像 { if (!$(this).hasClass('hide')) //未隐藏 { $(this).hide(); $(this).addClass('hide'); } } }); $('.TitleImage').hide(); //隐藏专栏文章封面图 } else { $("img").each(function() { if ($(this).attr("data-original") != undefined && !$(this).hasClass("comment_sticker")) { if ($(this).attr("src") != $(this).attr("data-original")) $(this).attr("src", $(this).attr("data-original")); } }); } } /* ============================================================================ * 专栏文章页吸顶标题栏(滚过正文后顶栏「换脸」的那一层) * ---------------------------------------------------------------------------- * 知乎专栏文章页滚过正文后顶栏会换脸,是靠两件事配合完成的(取自 source.html 顶栏 DOM): * 1) 顶栏行(关注/推荐/热榜…)被施加 transform 推走 —— 外层 header.AppHeader * (.css-iilrph)是 overflow:hidden 且固定 62px 高,推出去的内容就直接看不见了; * 2) 覆盖层
(absolute / top:0 / 100%×100%,自身无背景、 * pointer-events:none)里的 .PageHeader 被加上 .is-shown,浮出 * 「文章标题 + 首发于 专栏 + 夜间模式 + 创作」那一层。 * * 两者是配套的:只藏覆盖层会留下一条被推走的「空顶栏」,所以这里同时把顶栏行还原。 * * 定位锚点: * 吸顶栏本体 → .ColumnPageHeader-Wrapper / .Sticky.ColumnPageHeader(语义类名,稳定) * 承载它的层 → .PageHeader,用 :has() 限定「内部含专栏页头」,避开发布页 * (.Pub-PageHeaderWrapper .PageHeader)等其它同名元素 * 顶栏行 → header.AppHeader div:has(> nav),结构定位 * 【绝不使用 css-51utkw / css-ssuylx 这类哈希类名】——每页签状态不同, * 且每次发版必变 * * 副作用提醒:脚本原本会往 .ColumnPageHeader-Button 前插入「夜间模式」按钮, * 开启本项后该按钮随吸顶栏一起不可见;顶栏上那个夜间模式按钮不受影响。 * ========================================================================== */ function hideColumnPageHeader() { if (Config.currentValues.hideColumnPageHeader != 1) return; // 覆盖层本体与吸顶栏本体:都是语义类名,稳定 let css = '.ColumnPageHeader-Wrapper,\n.Sticky.ColumnPageHeader{display:none !important;}\n'; // 承载吸顶栏的 PageHeader:用 :has() 限定「内部含专栏页头的那个」, // 避免误伤发布页的 .Pub-PageHeaderWrapper .PageHeader 等其它同名元素。 // 单独成条——浏览器不支持 :has() 时只丢这一条,不连累上面的规则。 css += '\n.PageHeader:has(.ColumnPageHeader-Wrapper){display:none !important;}\n'; // 把被推走的顶栏行还原回来。用「结构 + :has(> nav)」定位, // 不碰 css-51utkw / css-ssuylx 这类哈希类名(知乎每次发版必变)。 // 单独成条,理由同上。 css += '\nheader.AppHeader div:has(> nav){transform:none !important;visibility:visible !important;opacity:1 !important;}\n'; GM_addStyle(css); } /* ============================================================================ * 导航栏精简:隐藏「AI Works」「故事」「直答」 * ---------------------------------------------------------------------------- * 知乎顶栏由 styled-components / emotion 生成哈希类名(如 .css-72pd91、.css-53paqb、 * .css-1caetj6),每次发版都会变,因此这里一律用 href 属性选择器定位,避免随改版失效。 * 定位锚点(取自页面源码 source.html 第 59440~59505 行): * AI Works → https://www.zhihu.com/project-square 在 nav 内,圈子之后 * 故事 → https://www.zhihu.com/fiore/h5/vip-web 在 nav 内,AI Works 之后 * 直答 → https://zhida.zhihu.com/ 在搜索框 .SearchBar 内最右侧 * * ⚠ 「直答」隐藏后会贴住搜索框,必须补间距,原因见下方 3. 处的注释。 * ========================================================================== */ function hideAppHeaderItems() { // 「直答」隐藏后补回的间距。 // 想调松/调紧只改这一个数:原样保留 直答 时该处的视觉间隔是 15px, // 12px 贴近 38px 圆形「创作」按钮的观感,更大更松、更小更紧凑。 const ZHIDA_HIDDEN_GAP = '15px'; // 普通隐藏规则 let plainRules = []; // 分隔线规则:AI Works / 故事 前面那根 1px 竖线,用 :has() 选中「它的前一个兄弟元素」 let dividerRules = []; // 隐藏直答后需要补间距的元素 let gapRules = []; // 1. AI Works(带 Beta 角标) if (Config.currentValues.hideNavAiWorks == 1) { plainRules.push('header.AppHeader nav a[href*="project-square"]'); dividerRules.push('header.AppHeader nav > div:has(+ a[href*="project-square"])'); } // 2. 故事(跳转盐选 VIP 页,target=_blank) if (Config.currentValues.hideNavStory == 1) { plainRules.push('header.AppHeader nav a[href*="fiore/h5/vip-web"]'); dividerRules.push('header.AppHeader nav > div:has(+ a[href*="fiore/h5/vip-web"])'); } // 3. 直答(在顶栏内但不属于 nav,故不限定 nav;zhida 站自身顶栏用的是 TopNavBar,不会被误伤) if (Config.currentValues.hideNavZhida == 1) { plainRules.push('header.AppHeader a[href*="zhida.zhihu.com"]'); // 直答本体 .css-so42cc 自带 margin-left: 15px / margin-right: 15px // (见 source.html 第 28070 行 data-emotion-css="so42cc"),搜索框与右侧「创作 ⊕」 // 之间的间隔全靠它撑起来;一旦 display:none,两者就会贴在一起。 // 这里把间距补到「创作」按钮的容器上(.SearchBar-askContainer 是语义类名,不是哈希类名)。 gapRules.push('header.AppHeader .SearchBar-askContainer'); } // 普通规则与 :has() 规则分开注入: // 浏览器不支持 :has() 时该条选择器会失效,若与普通规则写在同一选择器列表里会连累整条规则 let css = ''; if (plainRules.length > 0) { css += plainRules.join(',\n') + '{display:none !important;}\n'; } if (dividerRules.length > 0) { css += dividerRules.join(',\n') + '{display:none !important;}\n'; } if (gapRules.length > 0) { css += gapRules.join(',\n') + '{margin-left:' + ZHIDA_HIDDEN_GAP + ' !important;}\n'; } if (css) GM_addStyle(css); } /* ============================================================================ * 隐藏右下角「看山」AI 悬浮入口 * ---------------------------------------------------------------------------- * 知乎页面右下角角标容器(取自 source.html): *