Skip to content

Commit d5e1638

Browse files
committed
修复 [直达问题按钮]、[区分问题文章] 功能在部分搜索词下搜索页开头的"最新讨论"之类的非常规元素异常的问题
1 parent dcdc915 commit d5e1638

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 知乎增强
44
// @name:zh-TW 知乎增強
55
// @name:ru Улучшение Zhihu
6-
// @version 2.3.13
6+
// @version 2.3.14
77
// @author X.I.U
88
// @description A more personalized Zhihu experience~
99
// @description:zh-CN 屏蔽指定类别(视频、盐选、文章、想法、关注[赞同了XX/关注了XX]等等)、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链...
@@ -1115,6 +1115,8 @@ function addTypeTips() {
11151115
let style = `font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin: ${(location.pathname === '/search') ? '2' : '4'}px 4px 0 0;`
11161116
document.body.appendChild(document.createElement('style')).textContent = `/* 区分问题文章 */
11171117
.AnswerItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #f68b83;background-color: #f68b8333;${style}}
1118+
/* 针对的是部分搜索词下搜索页开头的 "最新讨论" 之类的非常规元素 */
1119+
.HotLanding-contentItem .ContentItem[data-za-detail-view-path-module=Content] .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #f68b83;background-color: #f68b8333;${style}}
11181120
.TopstoryQuestionAskItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #ff5a4e;background-color: #ff5a4e33;${style}}
11191121
.ZVideoItem .ContentItem-title a::before, .ZvideoItem .ContentItem-title a::before {content:'视频';color: #00BCD4;background-color: #00BCD433;${style}}
11201122
.PinItem .ContentItem-title a::before {content:'想法';color: #4CAF50;background-color: #4CAF5033;${style}}
@@ -1157,7 +1159,9 @@ function addToQuestion() {
11571159
titleA.innerHTML = titleA.innerHTML.replace('?', "?")
11581160
}
11591161
if (/answer\/\d+/.test(titleA.href)) { // 如果是指向回答的问题(而非指向纯问题的链接)
1160-
titleA.insertAdjacentHTML('afterend', `<a class="zhihu_e_toQuestion VoteButton" href="${titleA.parentElement.parentElement.querySelector('meta[itemprop="url"]').content}" target="_blank">直达问题</a>`);
1162+
const titleA_meta = titleA.parentElement.parentElement.querySelector('meta[itemprop="url"]'); // 获取该问题页地址
1163+
if (!titleA_meta) return // 判断元素是否存在(针对的是部分搜索词下搜索页开头的 "最新讨论" 之类的非常规元素)
1164+
titleA.insertAdjacentHTML('afterend', `<a class="zhihu_e_toQuestion VoteButton" href="${titleA_meta.content}" target="_blank">直达问题</a>`);
11611165
}
11621166
}
11631167

0 commit comments

Comments
 (0)