diff --git a/GithubEnhanced-High-Speed-Download.user.js b/GithubEnhanced-High-Speed-Download.user.js index 32ab3a23d..cced16688 100644 --- a/GithubEnhanced-High-Speed-Download.user.js +++ b/GithubEnhanced-High-Speed-Download.user.js @@ -3,7 +3,7 @@ // @name:zh-CN Github 增强 - 高速下载 // @name:zh-TW Github 增強 - 高速下載 // @name:ru Улучшение GitHub – быстрое скачивание -// @version 2.6.38 +// @version 2.6.39 // @author X.I.U // @description High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files (Based on public welfare), project list file quick download (☁) // @description:zh-CN 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件 (公益加速)、项目列表单文件快捷下载 (☁) @@ -34,7 +34,7 @@ const download_url_us = [ ['https://gh.h233.eu.org/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@X.I.U/XIU2] 提供'], //['https://gh.api.99988866.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [github.com/hunshcn/gh-proxy] 提供'], // 官方演示站用的人太多了 - ['https://rapidgit.jjda.de5.net/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [热心网友] 提供'], + //['https://rapidgit.jjda.de5.net/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [热心网友] 提供'],//挂了,522超时 ['https://gh.ddlc.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@mtr-static-official] 提供'], ['https://gh-proxy.org/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [gh-proxy.com] 提供'], //['https://hk.gh-proxy.org/https://github.com', '其他', '[中国香港] - 该公益加速源由 [gh-proxy.com] 提供'], @@ -46,7 +46,7 @@ ['https://gh.jasonzeng.dev/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [gh.jasonzeng.dev] 提供'], ['https://gh.monlor.com/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [gh.monlor.com] 提供'], //['https://fastgit.cc/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [fastgit.cc] 提供'], // 挂了 - ['https://github.tbedu.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [github.tbedu.top] 提供'], + //['https://github.tbedu.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [github.tbedu.top] 提供'],//挂了 DNS_PROBE_FINISHED_NXDOMAIN ['https://github.geekery.cn/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [github.geekery.cn] 提供'], ['https://github.ednovas.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [github.ednovas.xyz] 提供'], ['https://ghfile.geekertao.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [ghfile.geekertao.top] 提供'], @@ -99,7 +99,7 @@ //['https://jsd.proxy.aks.moe/gh', '香港 2', '[中国 香港] - 该公益加速源由 [cdn.akass.cn] 提供'], // 证书错误 ['https://wget.la/https://raw.githubusercontent.com', '香港 1', '[中国香港、中国台湾、日本、美国等](CDN 不固定) - 该公益加速源由 [ucdn.me] 提供 - 缓存:无(或很短)'], ['https://hk.gh-proxy.org/https://raw.githubusercontent.com', '香港 2', '[中国香港] - 该公益加速源由 [gh-proxy.com] 提供 - 缓存:有(官方注明 2 小时)'], - ['https://hub.glowp.xyz/https://raw.githubusercontent.com', '香港 3', '[中国香港] - 该公益加速源由 [hub.glowp.xyz] 提供 - 缓存:有'], + //['https://hub.glowp.xyz/https://raw.githubusercontent.com', '香港 3', '[中国香港] - 该公益加速源由 [hub.glowp.xyz] 提供 - 缓存:有'], //域名到期失效 //['https://gitproxy.click/https://raw.githubusercontent.com', '香港', '[中国 香港] - 该公益加速源由 [gitproxy.click] 提供'], // 输出错误 //['https://cdn.moran233.xyz/https://raw.githubusercontent.com', '香港', '[中国 香港] - 该公益加速源由 [cdn.moran233.xyz] 提供'], // 404 //['https://gitdl.cn/https://raw.githubusercontent.com', '香港 3', '[中国香港] - 该公益加速源由 [gitdl] 提供 - 缓存:有'], // 输出文件错误 @@ -189,7 +189,7 @@ if (target.tagName === 'DIV' && target.dataset.viewComponent === 'true' && target.classList[0] === 'Box') addRelease(); } } - } else if (document.querySelector('#repository-container-header:not([hidden])')) { // 项目首页 + } else if (document.querySelector('#repo-title-component')) { // 项目首页 for (const mutation of mutationsList) { for (const target of mutation.addedNodes) { if (target.nodeType !== 1) return @@ -505,4 +505,4 @@ window.dispatchEvent(new Event('urlchange')) }); } -})(); \ No newline at end of file +})(); diff --git a/Zhihu-Beautification.user.js b/Zhihu-Beautification.user.js index 584671e36..92c3a6708 100644 --- a/Zhihu-Beautification.user.js +++ b/Zhihu-Beautification.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 知乎美化 -// @version 1.5.20 +// @version 1.5.24 // @author X.I.U // @description 宽屏显示、暗黑模式(4种)、暗黑模式跟随浏览器、屏蔽首页活动广告、隐藏文章开头大图、调整图片最大高度、向下翻时自动隐藏顶栏 // @match *://www.zhihu.com/* @@ -13,6 +13,7 @@ // @grant GM_getValue // @grant GM_setValue // @grant GM_notification +// @grant window.onurlchange // @sandbox JavaScript // @license GPL-3.0 License // @run-at document-start @@ -27,9 +28,9 @@ ['menu_widescreenDisplay', '宽屏显示', '勾选 = 该页面开启宽屏显示(刷新后查看效果)', ''], ['menu_widescreenDisplayIndex', '首页', '宽屏显示', true], ['menu_widescreenDisplayQuestion', '问题页', '宽屏显示', true], - ['menu_widescreenDisplaySearch', '搜索页、话题页、圈子', '宽屏显示', true], + ['menu_widescreenDisplaySearch', '搜索页、话题页', '宽屏显示', true], ['menu_widescreenDisplayCollection', '收藏页', '宽屏显示', true], - ['menu_widescreenDisplayPost', '文章页', '宽屏显示', false], + ['menu_widescreenDisplayPost', '文章页(暂不可用)', '宽屏显示', false], ['menu_widescreenDisplayPeople', '用户主页', '用户主页', false], ['menu_widescreenDisplayWidth', '宽屏宽度', '宽屏宽度 (默认 1000)', '1000'], ['menu_darkMode', '暗黑模式', '暗黑模式', true], @@ -43,7 +44,11 @@ if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])}; } registerMenuCommand(); + if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化 addStyle(); + window.addEventListener('urlchange', function(){ // 网页 URL 动态变化后再次执行(针对在任何页面搜索时) + if (menu_value('menu_widescreenDisplaySearch') && (location.pathname === '/search' || location.pathname.indexOf('/club/') > -1 || location.pathname.indexOf('/topic/') > -1)) {addStyle()}; + }) // 向下翻时自动隐藏顶栏 if (menu_value('menu_hideTitle')) setTimeout(hideTitle, 2000); @@ -217,19 +222,19 @@ html[data-theme=light] .AppHeader-notifications:not([aria-label=通知])>div:fir @media only screen and (max-width: ${Number(GM_getValue('menu_widescreenDisplayWidth'))+50}px) {.Topstory-container {width: 97% !important;}} `, style_widescreenDisplayQuestion = `/* 宽屏显示 - 问题页 */ -.Question-mainColumn, .ListShortcut, .QuestionWaiting-mainColumn {width: inherit !important;} +.QuestionWaiting-mainColumn {width: inherit !important;} .Question-mainColumn+div,[data-za-detail-view-path-module="RightSideBar"], .Question-sideColumn, .GlobalSideBar {display: none !important;} .QuestionWaiting-mainColumn {margin-right: 0 !important;} -.Question-main {width: ${GM_getValue('menu_widescreenDisplayWidth')}px;} -@media only screen and (max-width: ${Number(GM_getValue('menu_widescreenDisplayWidth'))+50}px) {.Question-main {width: auto !important;}} -@media only screen and (max-width: ${GM_getValue('menu_widescreenDisplayWidth')-100}px) {.Question-main {width: 98.5% !important;}} +.Question-mainColumn, .ListShortcut {width: ${GM_getValue('menu_widescreenDisplayWidth')}px; margin: auto!important;} +@media only screen and (max-width: ${Number(GM_getValue('menu_widescreenDisplayWidth'))+50}px) {.Question-mainColumn, .ListShortcut {width: auto !important;}} +@media only screen and (max-width: ${GM_getValue('menu_widescreenDisplayWidth')-100}px) {.Question-mainColumn, .ListShortcut {width: 98.5% !important;}} .AuthorInfo {max-width: 100% !important;} `, style_widescreenDisplaySearch = `/* 宽屏显示 - 搜索页 */ -.SearchMain, .ContentLayout-mainColumn, .Club-mainColumn, .Post-mainColumn, [data-za-detail-view-path-module=TopicItem]>div:first-child {width: inherit !important;} -.SearchMain+div, .ContentLayout-sideColumn, .Card.QuestionHeaderTopicMeta, .ClubSideBar, [data-za-detail-view-path-module=TopicItem]>div:not(:first-child) {display: none !important;} -.Search-container, .ContentLayout, .Club-container, .Post-container, [data-za-detail-view-path-module=TopicItem] {width: ${GM_getValue('menu_widescreenDisplayWidth')}px;} -@media only screen and (max-width: ${Number(GM_getValue('menu_widescreenDisplayWidth'))+50}px) {.Search-container, .ContentLayout, .Club-container, .Post-container, [data-za-detail-view-path-module=TopicItem] {width: 97.5% !important;}} +.SearchMain, .App-main>[data-za-detail-view-path-module=TopicItem]>div:first-child {width: inherit !important;} +.SearchMain+div, .App-main>[data-za-detail-view-path-module=TopicItem]>div:not(:first-child) {display: none !important;} +.Search-container, .App-main>[data-za-detail-view-path-module=TopicItem] {width: ${GM_getValue('menu_widescreenDisplayWidth')}px;} +@media only screen and (max-width: ${Number(GM_getValue('menu_widescreenDisplayWidth'))+50}px) {.Search-container, .App-main>[data-za-detail-view-path-module=TopicItem] {width: 97.5% !important;}} `, style_widescreenDisplayCollection = `/* 宽屏显示 - 收藏页 */ .CollectionsDetailPage-mainColumn {width: inherit !important;} @@ -262,6 +267,8 @@ html[data-theme=light] .AppHeader-notifications:not([aria-label=通知])>div:fir .ztext .content_image, .ztext .origin_image, .GifPlayer img {max-height: 500px !important;width: auto !important;} `, style_darkMode_1 = `/* 暗黑模式(方案 1) */ +/* 首页工具条宽度 */ +html[data-theme=dark] .Card.TopstoryItem.TopstoryItem-isRecommend .ContentItem-actions, .Card.TopstoryItem.TopstoryItem-isFollow .ContentItem-actions {margin: 0 -16px -10px;} /* 右上角 通知/私信 红点颜色 */ html[data-theme=dark] .AppHeader-notifications:not([aria-label=通知])>div:first-of-type, html[data-theme=dark] .AppHeader-messages:not([aria-label=私信])>div:first-of-type {color: #ffffff !important;border: 2px solid #2d333b !important;} /* 文字颜色 */ @@ -523,7 +530,7 @@ html {filter: brightness(65%) sepia(30%) !important; background-image: url();} // 获取知乎 Cookie 中的主题类型 function getTheme() { - let name = 'theme=', + let name = 'themeApp=', ca = document.cookie.split(';'); for (let i=0; i function pushState(){ + var ret = f.apply(this, arguments); + window.dispatchEvent(new Event('pushstate')); + window.dispatchEvent(new Event('urlchange')); + return ret; + })(history.pushState); + + history.replaceState = ( f => function replaceState(){ + var ret = f.apply(this, arguments); + window.dispatchEvent(new Event('replacestate')); + window.dispatchEvent(new Event('urlchange')); + return ret; + })(history.replaceState); + + window.addEventListener('popstate',()=>{ + window.dispatchEvent(new Event('urlchange')) + }); + } })(); \ No newline at end of file diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 222676ddb..07258f8a1 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -3,7 +3,7 @@ // @name:zh-CN 知乎增强 // @name:zh-TW 知乎增強 // @name:ru Улучшение Zhihu -// @version 2.3.29 +// @version 2.3.32 // @author X.I.U // @description A more personalized Zhihu experience~ // @description:zh-CN 移除登录弹窗、屏蔽指定类别(视频、盐选、文章、想法、关注[赞同/关注了XX]等)、屏蔽低赞/低评、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链... @@ -248,8 +248,8 @@ function collapsedAnswer() { //console.log('1111', document.querySelector('.CornerAnimayedFlex')) if (document.querySelector('.CornerAnimayedFlex') && !document.getElementById('collapsed-button')) { // 向网页中插入收起全部回答按钮+样式+绑定点击事件 - document.head.appendChild(document.createElement('style')).textContent = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:45px !important;}'; - document.querySelector('.CornerAnimayedFlex').insertAdjacentHTML('afterBegin', ''); + document.head.appendChild(document.createElement('style')).textContent = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:25px !important;} .CornerAnimayedFlex {height: auto;}'; + document.querySelector('.CornerAnimayedFlex').insertAdjacentHTML('afterBegin', ''); document.getElementById('collapsed-button').onclick = function () { // 收起所有评论(悬浮的 [收起评论]) @@ -295,119 +295,122 @@ function collapsedAnswer() { function collapsedNowAnswer(selectors) { backToTop(selectors) // 快捷回到顶部 if (!menu_value('menu_collapsedNowAnswer')) return - document.querySelector(selectors).onclick = function(event){ - if (event.target == this) { - // 下面这段主要是 [收起回答],顺便 [收起评论](如果展开了的话) - let rightButton = document.querySelector('.ContentItem-actions.Sticky.RichContent-actions.is-fixed.is-bottom') - if (rightButton) { // 悬浮在底部的 [收起回答](此时正在浏览回答内容 [中间区域]) - // 固定的 [收起评论](先看看是否展开评论) - let commentCollapseButton = rightButton.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') - //console.log('111') - if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click(); - // 再去收起回答 - rightButton = rightButton.querySelector('.ContentItem-rightButton[data-zop-retract-question]') - //console.log('222') - if (rightButton) rightButton.click(); - - } else { // 固定在回答底部的 [收起回答](此时正在浏览回答内容 [尾部区域]) - - // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域]) - //if (getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container'))) {getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container')).click();console.log('asfaf')} - - let answerCollapseButton_ = false; - for (let el of document.querySelectorAll('.ContentItem-rightButton[data-zop-retract-question]')) { // 遍历所有回答底部的 [收起] 按钮 - if (isElementInViewport(el)) { // 判断该 [收起] 按钮是否在可视区域内 - // 固定的 [收起评论](先看看是否展开评论,即存在 [收起评论] 按钮) - let commentCollapseButton = el.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') - // 如果展开了评论,就收起评论 - //console.log('333') - //if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click(); - if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) { - commentCollapseButton.click(); - if (!isElementInViewport(commentCollapseButton)) scrollTo(0,el.offsetTop+50) - } - //console.log('444') - el.click() // 再去收起回答 - answerCollapseButton_ = true; // 如果找到并点击收起了,就没必要执行下面的代码了(可视区域中没有 [收起回答] 时) - break - } - } - // 针对完全看不到 [收起回答] 按钮时(如 [头部区域],以及部分明明很长却不显示悬浮横条的回答) - if (!answerCollapseButton_) { - for (let el of document.querySelectorAll('.List-item, .Card.AnswerCard, .Card.TopstoryItem')) { // 遍历所有回答主体元素 - if (isElementInViewport_(el)) { // 判断该回答是否在可视区域内 + let element = document.querySelector(selectors) + if (element) { + element.onclick = function(event){ + if (event.target == this) { + // 下面这段主要是 [收起回答],顺便 [收起评论](如果展开了的话) + let rightButton = document.querySelector('.ContentItem-actions.Sticky.RichContent-actions.is-fixed.is-bottom') + if (rightButton) { // 悬浮在底部的 [收起回答](此时正在浏览回答内容 [中间区域]) + // 固定的 [收起评论](先看看是否展开评论) + let commentCollapseButton = rightButton.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + //console.log('111') + if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click(); + // 再去收起回答 + rightButton = rightButton.querySelector('.ContentItem-rightButton[data-zop-retract-question]') + //console.log('222') + if (rightButton) rightButton.click(); + + } else { // 固定在回答底部的 [收起回答](此时正在浏览回答内容 [尾部区域]) + + // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域]) + //if (getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container'))) {getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container')).click();console.log('asfaf')} + + let answerCollapseButton_ = false; + for (let el of document.querySelectorAll('.ContentItem-rightButton[data-zop-retract-question]')) { // 遍历所有回答底部的 [收起] 按钮 + if (isElementInViewport(el)) { // 判断该 [收起] 按钮是否在可视区域内 // 固定的 [收起评论](先看看是否展开评论,即存在 [收起评论] 按钮) - let commentCollapseButton = el.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + let commentCollapseButton = el.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') // 如果展开了评论,就收起评论 - //console.log('555',commentCollapseButton) + //console.log('333') + //if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click(); if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) { commentCollapseButton.click(); if (!isElementInViewport(commentCollapseButton)) scrollTo(0,el.offsetTop+50) } - let answerCollapseButton__ = el.querySelector('.ContentItem-rightButton[data-zop-retract-question]'); - //console.log('666') - if (answerCollapseButton__) answerCollapseButton__.click() // 再去收起回答 + //console.log('444') + el.click() // 再去收起回答 + answerCollapseButton_ = true; // 如果找到并点击收起了,就没必要执行下面的代码了(可视区域中没有 [收起回答] 时) break } } - } - } - - // 下面这段只针对 [收起评论](如果展开了的话) - let commentCollapseButton_ = false, commentCollapseButton__ = false; - // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域]) - let commentCollapseButton = getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container')) - if (commentCollapseButton) { - //console.log('777', commentCollapseButton) - commentCollapseButton.click(); - } else { // 固定的 [收起评论](此时正在浏览评论内容 [头部区域]) - let commentCollapseButton_1 = document.querySelectorAll('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type, .ContentItem-action > button.Button.Button--plain.Button--withIcon.Button--withLabel:first-of-type') - if (commentCollapseButton_1.length > 0) { - for (let el of commentCollapseButton_1) { - if (el.textContent.indexOf('收起评论') > -1) { - if (isElementInViewport(el)) { - //console.log('888') - el.click() - commentCollapseButton_ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 [收起评论] 时) + // 针对完全看不到 [收起回答] 按钮时(如 [头部区域],以及部分明明很长却不显示悬浮横条的回答) + if (!answerCollapseButton_) { + for (let el of document.querySelectorAll('.List-item, .Card.AnswerCard, .Card.TopstoryItem')) { // 遍历所有回答主体元素 + if (isElementInViewport_(el)) { // 判断该回答是否在可视区域内 + // 固定的 [收起评论](先看看是否展开评论,即存在 [收起评论] 按钮) + let commentCollapseButton = el.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + // 如果展开了评论,就收起评论 + //console.log('555',commentCollapseButton) + if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) { + commentCollapseButton.click(); + if (!isElementInViewport(commentCollapseButton)) scrollTo(0,el.offsetTop+50) + } + let answerCollapseButton__ = el.querySelector('.ContentItem-rightButton[data-zop-retract-question]'); + //console.log('666') + if (answerCollapseButton__) answerCollapseButton__.click() // 再去收起回答 break } } } } - if (commentCollapseButton_ == false) { // 可视区域中没有 [收起评论] 时(此时正在浏览评论内容 [头部区域] + [尾部区域](不上不下的,既看不到固定的 [收起评论] 又看不到悬浮的 [收起评论])),需要判断可视区域中是否存在评论元素 - let commentCollapseButton_1 = document.querySelectorAll('.Comments-container') + + // 下面这段只针对 [收起评论](如果展开了的话) + let commentCollapseButton_ = false, commentCollapseButton__ = false; + // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域]) + let commentCollapseButton = getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container')) + if (commentCollapseButton) { + //console.log('777', commentCollapseButton) + commentCollapseButton.click(); + } else { // 固定的 [收起评论](此时正在浏览评论内容 [头部区域]) + let commentCollapseButton_1 = document.querySelectorAll('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type, .ContentItem-action > button.Button.Button--plain.Button--withIcon.Button--withLabel:first-of-type') if (commentCollapseButton_1.length > 0) { for (let el of commentCollapseButton_1) { - if (isElementInViewport(el)) { - let parentElement = findParentElement(el, 'List-item') || findParentElement(el, 'Card '), - commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') - if (commentCollapseButton.textContent.indexOf('收起评论') > -1) { - //console.log('999') - commentCollapseButton.click() - if (!isElementInViewport(commentCollapseButton)) {console.log(parentElement,parentElement.offsetTop,parentElement.offsetHeight);scrollTo(0,parentElement.offsetTop+parentElement.offsetHeight-50)} - commentCollapseButton__ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 评论元素 时) + if (el.textContent.indexOf('收起评论') > -1) { + if (isElementInViewport(el)) { + //console.log('888') + el.click() + commentCollapseButton_ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 [收起评论] 时) break } } } } - if (commentCollapseButton__ == false) { // 如果上面的都没找到,那么就尝试寻找评论末尾的 [评论回复框] - let commentCollapseButton_2 = document.querySelectorAll('.Editable-content') - if (commentCollapseButton_2.length > 0) { - for (let el of commentCollapseButton_2) { + if (commentCollapseButton_ == false) { // 可视区域中没有 [收起评论] 时(此时正在浏览评论内容 [头部区域] + [尾部区域](不上不下的,既看不到固定的 [收起评论] 又看不到悬浮的 [收起评论])),需要判断可视区域中是否存在评论元素 + let commentCollapseButton_1 = document.querySelectorAll('.Comments-container') + if (commentCollapseButton_1.length > 0) { + for (let el of commentCollapseButton_1) { if (isElementInViewport(el)) { let parentElement = findParentElement(el, 'List-item') || findParentElement(el, 'Card '), - commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') - //console.log(commentCollapseButton) + commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') if (commentCollapseButton.textContent.indexOf('收起评论') > -1) { - //console.log('101010') + //console.log('999') commentCollapseButton.click() if (!isElementInViewport(commentCollapseButton)) {console.log(parentElement,parentElement.offsetTop,parentElement.offsetHeight);scrollTo(0,parentElement.offsetTop+parentElement.offsetHeight-50)} + commentCollapseButton__ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 评论元素 时) break } } } } + if (commentCollapseButton__ == false) { // 如果上面的都没找到,那么就尝试寻找评论末尾的 [评论回复框] + let commentCollapseButton_2 = document.querySelectorAll('.Editable-content') + if (commentCollapseButton_2.length > 0) { + for (let el of commentCollapseButton_2) { + if (isElementInViewport(el)) { + let parentElement = findParentElement(el, 'List-item') || findParentElement(el, 'Card '), + commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + //console.log(commentCollapseButton) + if (commentCollapseButton.textContent.indexOf('收起评论') > -1) { + //console.log('101010') + commentCollapseButton.click() + if (!isElementInViewport(commentCollapseButton)) {console.log(parentElement,parentElement.offsetTop,parentElement.offsetHeight);scrollTo(0,parentElement.offsetTop+parentElement.offsetHeight-50)} + break + } + } + } + } + } } } } @@ -419,10 +422,13 @@ function collapsedNowAnswer(selectors) { // 回到顶部(监听点击事件,鼠标右键点击网页两侧空白处) function backToTop(selectors) { if (!menu_value('menu_backToTop')) return - document.querySelector(selectors).oncontextmenu = function(event){ - if (event.target == this) { - event.preventDefault(); - window.scrollTo(0,0) + let element = document.querySelector(selectors) + if (element) { + element.oncontextmenu = function(event){ + if (event.target == this) { + event.preventDefault(); + window.scrollTo(0,0) + } } } } @@ -1682,7 +1688,7 @@ function switchHomeRecommend() { if (location.pathname.indexOf('question') > -1 && location.href.indexOf('/log') == -1) { // 回答页 // if (location.pathname.indexOf('waiting') == -1) { collapsedNowAnswer('.QuestionPage'); // 收起当前回答 + 快捷返回顶部 - collapsedNowAnswer('.Question-main'); // 收起当前回答 + 快捷返回顶部 + collapsedNowAnswer('.QuestionPage>#AnswerFormPortalContainer+div>div:first-child'); //收起当前回答 + 快捷返回顶部 questionRichTextMore(); // 展开问题描述 if (location.pathname.indexOf('answer') == -1) { // 问题页而不是回答页 blockLowCount('question'); // 屏蔽低赞/低评回答/文章