1+ // ==UserScript==
2+ // @name 知乎增强 - 置顶显示发布/编辑时间
3+ // @version 1.0.0
4+ // @description 回答和文章置顶显示发布时间、编辑时间
5+ // @author X.I.U
6+ // @match *://www.zhihu.com/*
7+ // @match https://zhuanlan.zhihu.com/*
8+ // @icon https://static.zhihu.com/static/favicon.ico
9+ // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.1.1/jquery.min.js
10+ // @connect zhihu.com
11+ // @grant unsafeWindow
12+ // @run -at document-end
13+ // @namespace https://greasyfork.org/scripts/412216
14+ // ==/UserScript==
15+
16+ var publishTop = 1 ; //置顶回答时间
17+
18+ //首页
19+ function index ( )
20+ {
21+ $ ( ".TopstoryItem" ) . each ( function ( ) {
22+ if ( ! ( $ ( this ) . find ( ".ContentItem-time" ) . hasClass ( "full" ) ) && $ ( this ) . find ( ".ContentItem-time" ) . length > 0 && $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) != null )
23+ {
24+ if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) == - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) > - 1 ) //只有"编辑于"时增加具体发布时间data-tooltip
25+ {
26+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
27+ var oldtext = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) ;
28+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip + "," + oldtext ) ;
29+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
30+ }
31+ else if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) > - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) == - 1 ) //只有"发布于"时替换为具体发布时间data-tooltip
32+ {
33+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
34+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip ) ;
35+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
36+ }
37+
38+ //发布时间置顶
39+ if ( publishTop == 1 )
40+ {
41+ if ( ! $ ( this ) . find ( ".ContentItem-time" ) . parent ( ) . hasClass ( "ContentItem-meta" ) )
42+ {
43+ let temp_time = $ ( this ) . find ( ".ContentItem-time" ) . clone ( ) ;
44+ $ ( this ) . find ( ".RichContent .ContentItem-time" ) . hide ( ) ;
45+ $ ( this ) . find ( ".ContentItem-meta" ) . append ( temp_time ) ;
46+ }
47+
48+ }
49+ }
50+
51+ } )
52+ }
53+
54+ //回答页
55+ function question ( )
56+ {
57+ //回答的发布时间
58+ $ ( ".ContentItem.AnswerItem" ) . each ( function ( ) {
59+ if ( ! ( $ ( this ) . find ( ".ContentItem-time" ) . hasClass ( "full" ) ) && $ ( this ) . find ( ".ContentItem-time" ) . length > 0 && $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) != null )
60+ {
61+ if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) == - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) > - 1 ) //只有"编辑于"时增加具体发布时间data-tooltip
62+ {
63+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
64+ var oldtext = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) ;
65+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip + "," + oldtext ) ;
66+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
67+ }
68+ else if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) > - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) == - 1 ) //只有"发布于"时替换为具体发布时间data-tooltip
69+ {
70+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
71+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip ) ;
72+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
73+ }
74+
75+ //发布时间置顶
76+ if ( publishTop == 1 )
77+ {
78+ if ( ! $ ( this ) . find ( ".ContentItem-time" ) . parent ( ) . hasClass ( "ContentItem-meta" ) )
79+ {
80+ let temp_time = $ ( this ) . find ( ".ContentItem-time" ) . clone ( ) ;
81+ $ ( this ) . find ( ".RichContent .ContentItem-time" ) . hide ( ) ;
82+ $ ( this ) . find ( ".ContentItem-meta" ) . append ( temp_time ) ;
83+ }
84+ }
85+ }
86+
87+ } )
88+
89+ $ ( ".Pc-card.Card" ) . attr ( "style" , "display:none" )
90+ }
91+
92+ //专栏/文章
93+ function zhuanlan ( )
94+ {
95+ //隐藏推荐文章
96+ $ ( ".Recommendations-Main" ) . hide ( ) ;
97+
98+
99+ //有"编辑于"时,增加发布时间
100+ if ( $ ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) > - 1 && ! $ ( ".ContentItem-time" ) . hasClass ( "done" ) )
101+ {
102+ let bianjiyu = $ ( ".ContentItem-time" ) . text ( ) ;
103+ $ ( ".ContentItem-time" ) . click ( ) ;
104+ $ ( ".ContentItem-time" ) . text ( $ ( ".ContentItem-time" ) . text ( ) + "," + bianjiyu )
105+ $ ( ".ContentItem-time" ) . addClass ( "done" ) ;
106+ }
107+
108+ //发布时间置顶
109+ if ( publishTop == 1 && $ ( ".Post-Header" ) . find ( ".ContentItem-time" ) . length == 0 )
110+ {
111+ $ ( ".ContentItem-time" ) . css ( { "padding" :"0px 0px 0px 0px" , "margin-top" : "14px" } ) ;
112+ $ ( ".ContentItem-time" ) . appendTo ( $ ( ".Post-Header" ) )
113+ }
114+ }
115+
116+ //搜索结果页
117+ function search ( )
118+ {
119+ $ ( ".ContentItem.AnswerItem, .ContentItem.ArticleItem" ) . each ( function ( ) {
120+ console . log ( $ ( this ) . find ( ".ContentItem-time" ) )
121+ if ( ! ( $ ( this ) . find ( ".ContentItem-time" ) . hasClass ( "full" ) ) && $ ( this ) . find ( ".ContentItem-time" ) . length > 0 && $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) != null )
122+ {
123+ if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) == - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) > - 1 ) //只有"编辑于"时,增加具体发布时间data-tooltip
124+ {
125+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
126+ var oldtext = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) ;
127+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip + "," + oldtext ) ;
128+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
129+ }
130+ else if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) > - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) == - 1 ) //只有"发布于"时替换为具体发布时间data-tooltip
131+ {
132+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
133+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip ) ;
134+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
135+ }
136+
137+ //发布时间置顶
138+ if ( publishTop == 1 )
139+ {
140+ if ( ! $ ( this ) . find ( ".ContentItem-time" ) . parent ( ) . hasClass ( "SearchItem-meta" ) )
141+ {
142+ let temp_time = $ ( this ) . find ( ".ContentItem-time" ) . clone ( ) ;
143+ $ ( this ) . find ( ".RichContent .ContentItem-time" ) . hide ( ) ;
144+ $ ( this ) . find ( ".SearchItem-meta" ) . append ( temp_time ) ;
145+ }
146+ }
147+ }
148+
149+ } )
150+
151+ //隐藏相关推荐的卡片,仅保留问题卡片
152+ $ ( ".RelevantQuery" ) . closest ( ".Card.SearchResult-Card" ) . hide ( ) ;
153+ $ ( ".KfeCollection-PcCollegeCard-wrapper" ) . closest ( ".Card.SearchResult-Card" ) . hide ( ) ;
154+ if ( getQueryVariable ( "type" ) == "content" )
155+ {
156+ $ ( '.Card.SearchResult-Card[data-za-detail-view-path-module="UserItem"]' ) . hide ( ) ;
157+ }
158+
159+ }
160+
161+ //用户主页
162+ function people ( )
163+ {
164+ $ ( ".ContentItem.AnswerItem" ) . each ( function ( ) {
165+ if ( ! ( $ ( this ) . find ( ".ContentItem-time" ) . hasClass ( "full" ) ) && $ ( this ) . find ( ".ContentItem-time" ) . length > 0 && $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) != null )
166+ {
167+ if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) == - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) > - 1 ) //只有"编辑于"时增加具体发布时间data-tooltip
168+ {
169+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
170+ var oldtext = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( ) ;
171+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip + "," + oldtext ) ;
172+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
173+ }
174+ else if ( $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "发布于" ) > - 1 && $ ( this ) . find ( ".ContentItem-time" ) . text ( ) . indexOf ( "编辑于" ) == - 1 ) //只有"发布于"时替换为具体发布时间data-tooltip
175+ {
176+ let data_tooltip = $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . attr ( "data-tooltip" ) ;
177+ $ ( this ) . find ( ".ContentItem-time" ) . find ( "span" ) . text ( data_tooltip ) ;
178+ $ ( this ) . find ( ".ContentItem-time" ) . addClass ( "full" ) ;
179+ }
180+
181+ //发布时间置顶
182+ if ( publishTop == 1 )
183+ {
184+ if ( ! $ ( this ) . find ( ".ContentItem-time" ) . parent ( ) . hasClass ( "ContentItem-meta" ) )
185+ {
186+ let temp_time = $ ( this ) . find ( ".ContentItem-time" ) . clone ( ) ;
187+ $ ( this ) . find ( ".RichContent .ContentItem-time" ) . hide ( ) ;
188+ $ ( this ) . find ( ".ContentItem-meta" ) . append ( temp_time ) ;
189+ }
190+ }
191+ }
192+
193+ } )
194+ }
195+
196+ ( function ( ) {
197+ //折叠谢邀
198+ let timer = setInterval ( function ( ) {
199+ if ( $ ( ".QuestionInvitation-content" ) . text ( ) . indexOf ( "更多推荐结果" ) > - 1 )
200+ {
201+ clearInterval ( timer ) ;
202+ $ ( ".QuestionInvitation-content" ) . addClass ( "hide" ) ;
203+ $ ( ".QuestionInvitation-content" ) . hide ( ) ;
204+
205+ $ ( ".QuestionInvitation-title" ) . html ( $ ( ".QuestionInvitation-title" ) . text ( ) + '<span style="color:#8590A6;">(点击此处展开/折叠)</span>' )
206+
207+ $ ( ".Topbar" ) . click ( function ( ) {
208+
209+ if ( ( $ ( ".QuestionInvitation-content" ) . hasClass ( "hide" ) ) )
210+ {
211+ $ ( ".QuestionInvitation-content" ) . removeClass ( "hide" ) . addClass ( "show" ) ;
212+ $ ( ".QuestionInvitation-content" ) . show ( ) ;
213+ }
214+ else
215+ {
216+ $ ( ".QuestionInvitation-content" ) . removeClass ( "show" ) . addClass ( "hide" ) ;
217+ $ ( ".QuestionInvitation-content" ) . hide ( ) ;
218+ }
219+ } )
220+ }
221+ } )
222+
223+ //每个页面对应的功能函数
224+ if ( window . location . href . indexOf ( "question" ) > - 1 ) //回答页
225+ setInterval ( question , 300 ) ;
226+ else if ( window . location . href . indexOf ( "search" ) > - 1 ) //搜索结果页
227+ setInterval ( search , 300 ) ;
228+ else if ( window . location . href . indexOf ( "zhuanlan" ) > - 1 ) //专栏/文章
229+ setInterval ( zhuanlan , 300 ) ;
230+ else if ( window . location . href . indexOf ( "people" ) > - 1 || window . location . href . indexOf ( "org" ) > - 1 ) //用户主页
231+ setInterval ( people , 300 ) ;
232+ else
233+ setInterval ( index , 300 ) ; //首页
234+ } ) ( ) ;
0 commit comments