|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 知乎增强 |
3 | | -// @version 1.7.7 |
| 3 | +// @version 1.7.8 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起当前回答/评论(左键两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽用户 (发布的内容)、屏蔽关键词(标题/评论)、屏蔽盐选内容、净化标题消息、展开问题描述、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链 |
6 | 6 | // @match *://www.zhihu.com/* |
@@ -1003,72 +1003,12 @@ function blockYanXuan() { |
1003 | 1003 | // 区分问题文章 |
1004 | 1004 | function addTypeTips() { |
1005 | 1005 | if (!menu_value('menu_typeTips')) return |
1006 | | - |
1007 | | - // 一开始加载的信息流 + 添加标签样式 |
1008 | | - if (location.pathname === '/search') { |
1009 | | - document.lastChild.appendChild(document.createElement('style')).textContent = `small.zhihu_e_tips {font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin-top: 2px;}`; |
1010 | | - addSetInterval_('h2.ContentItem-title a:not(.zhihu_e_toQuestion)'); |
1011 | | - } else { |
1012 | | - document.lastChild.appendChild(document.createElement('style')).textContent = `small.zhihu_e_tips {font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin-top: 4px;}`; |
1013 | | - document.querySelectorAll('h2.ContentItem-title a:not(.zhihu_e_toQuestion)').forEach(function(item){addTypeTips_(item);}) |
1014 | | - } |
1015 | | - |
1016 | | - // 后续加载的信息流 |
1017 | | - const observer = new MutationObserver(mutationsList => { |
1018 | | - for (const mutation of mutationsList) { |
1019 | | - for (const target of mutation.addedNodes) { |
1020 | | - if (target.nodeType != 1) return |
1021 | | - addTypeTips_(target.querySelector('h2.ContentItem-title a:not(.zhihu_e_toQuestion)')); |
1022 | | - } |
1023 | | - } |
1024 | | - }); |
1025 | | - observer.observe(document, { childList: true, subtree: true }); |
1026 | | - |
1027 | | - window.addEventListener('locationchange', function(){ |
1028 | | - if (location.pathname.indexOf('/people/') > -1) { |
1029 | | - if (location.pathname.split('/').length === 3) { |
1030 | | - addSetInterval_('h2.ContentItem-title a:not(.zhihu_e_toQuestion)'); |
1031 | | - observer.observe(document, { childList: true, subtree: true }); |
1032 | | - } else { |
1033 | | - observer.disconnect(); |
1034 | | - } |
1035 | | - } else { |
1036 | | - addSetInterval_('h2.ContentItem-title a:not(.zhihu_e_toQuestion)'); |
1037 | | - } |
1038 | | - }) |
1039 | | - |
1040 | | - function addTypeTips_(titleA) { |
1041 | | - if (!titleA) return // 判断是否为真 |
1042 | | - if (titleA.querySelector('small.zhihu_e_tips')) return // 判断是否已添加 |
1043 | | - |
1044 | | - let patt_zhuanlan = /zhuanlan.zhihu.com/, |
1045 | | - patt_question = /question\/\d+/, |
1046 | | - patt_question_answer = /answer\/\d+/, |
1047 | | - patt_video = /\/zvideo\//; |
1048 | | - if (patt_zhuanlan.test(titleA.href)) { // 如果是文章 |
1049 | | - titleA.innerHTML = `<small class="zhihu_e_tips" style="color: #2196F3;background-color: #2196F333;">文章</small> ` + titleA.innerHTML |
1050 | | - } else if (patt_question.test(titleA.href)) { // 如果是问题 |
1051 | | - if (!titleA.dataset.tooltip) { // 排除用户名后面的蓝标、黄标等链接 |
1052 | | - if (patt_question_answer.test(titleA.href)) { // 如果是指向回答的问题(而非指向纯问题的链接) |
1053 | | - titleA.innerHTML = `<small class="zhihu_e_tips" style="color: #f68b83;background-color: #f68b8333;">问题</small> ` + titleA.innerHTML |
1054 | | - } else { |
1055 | | - titleA.innerHTML = `<small class="zhihu_e_tips" style="color: #ff5a4e;background-color: #ff5a4e33;">问题</small> ` + titleA.innerHTML |
1056 | | - } |
1057 | | - } |
1058 | | - } else if (patt_video.test(titleA.href)) { // 如果是视频 |
1059 | | - titleA.innerHTML = `<small class="zhihu_e_tips" style="color: #00BCD4;background-color: #00BCD433;">视频</small> ` + titleA.innerHTML |
1060 | | - } |
1061 | | - } |
1062 | | - |
1063 | | - function addSetInterval_(A) { |
1064 | | - let timer = setInterval(function(){ |
1065 | | - let aTag = document.querySelectorAll(A); |
1066 | | - if (aTag.length > 0) { |
1067 | | - clearInterval(timer); |
1068 | | - aTag.forEach(function(item){addTypeTips_(item);}) |
1069 | | - } |
1070 | | - }); |
1071 | | - } |
| 1006 | + 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;` |
| 1007 | + document.body.appendChild(document.createElement('style')).textContent = `/* 区分问题文章 */ |
| 1008 | +.AnswerItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #f68b83;background-color: #f68b8333;${style}} |
| 1009 | +.TopstoryQuestionAskItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #ff5a4e;background-color: #ff5a4e33;${style}} |
| 1010 | +.ZVideoItem .ContentItem-title a::before, .ZvideoItem .ContentItem-title a::before {content:'视频';color: #00BCD4;background-color: #00BCD433;${style}} |
| 1011 | +.ArticleItem .ContentItem-title a::before {content:'文章';color: #2196F3;background-color: #2196F333;${style}}`; |
1072 | 1012 | } |
1073 | 1013 |
|
1074 | 1014 |
|
|
0 commit comments