Skip to content

Commit ebe87b4

Browse files
committed
新增 知乎增强-区分问题和文章脚本
1 parent 5f33811 commit ebe87b4

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| 脚本名称 | 脚本功能 | 安装 | 备用 |
1616
| :---- | :---- | :----: | :----: |
1717
| **知乎增强** | 宽屏显示 | **[「安装」](https://greasyfork.org/scripts/412212)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-Widescreen.user.js)** |
18+
| **知乎增强** | 区分问题和文章 | **[「安装」](https://greasyfork.org/scripts/414027)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-TypeTip.user.js)** |
1819
| **知乎增强** | 一键收起长篇回答 | **[「安装」](https://greasyfork.org/scripts/412205)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-CollapsedAnswer.user.js)** |
1920
| **知乎增强** | 默认显示高清原图 | **[「安装」](https://greasyfork.org/scripts/412217)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-HD-Pictures.user.js)** |
2021
| **知乎增强** | 置顶显示发布时间/编辑时间 | **[「安装」](https://greasyfork.org/scripts/412216)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-Time.user.js)** |

ZhihuEnhanced-TypeTip.user.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ==UserScript==
2+
// @name 知乎增强 - 区分问题和文章
3+
// @version 1.0.0
4+
// @author X.I.U
5+
// @description 首页和搜索页列表中的标题开头添加问题、文章提示
6+
// @match *://www.zhihu.com/
7+
// @match *://www.zhihu.com/search*
8+
// @icon https://static.zhihu.com/static/favicon.ico
9+
// @license GPL-3.0 License
10+
// @run-at document-end
11+
// @namespace https://greasyfork.org/scripts/414027
12+
// ==/UserScript==
13+
14+
(function() {
15+
var postNum;
16+
17+
setInterval(aaaaa, 1000);
18+
//setTimeout(aaaaa, 1000);
19+
20+
function aaaaa() {
21+
// URL 匹配正则表达式
22+
var patt_zhuanlan = /zhuanlan.zhihu.com/,
23+
patt_question = /question\/\d+/,
24+
patt_tip = /zhihu_e_tips/
25+
var postList = document.querySelectorAll('a[data-za-detail-view-id]');
26+
postNum = document.querySelectorAll('small.zhihu_e_tips');
27+
//console.log(`${postList.length} ${postNum.length}`);
28+
if (postList.length > postNum.length){
29+
for(var num = postNum.length;num<postList.length;num++){
30+
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
31+
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
32+
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #0084ff;display: inline-block;height: 18px;">文章</small> ` + postList[num].innerHTML
33+
}else if (patt_question.test(postList[num].href)){ // 如果是问题
34+
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #fd7672;display: inline-block;height: 18px;">问题</small> ` + postList[num].innerHTML
35+
}
36+
//postNum += 1;
37+
}
38+
}
39+
}
40+
}
41+
})();

0 commit comments

Comments
 (0)