Skip to content

Commit 2a7e937

Browse files
committed
合并 其他知乎增强脚本(和其他的脚本格式统一)
1 parent 3a2c352 commit 2a7e937

5 files changed

Lines changed: 147 additions & 143 deletions

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
| 脚本名称 | 脚本功能 | 安装 | 备用 |
1616
| :---- | :---- | :----: | :----: |
1717
| **知乎 美化** | 宽屏显示 | **[「安装」](https://greasyfork.org/scripts/412212)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/Zhihu-Beautification.user.js)** |
18-
| **知乎 增强** | 区分问题和文章 | **[「安装」](https://greasyfork.org/scripts/414027)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-TypeTip.user.js)** |
19-
| **知乎 增强** | 一键收起长篇回答 | **[「安装」](https://greasyfork.org/scripts/412205)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-CollapsedAnswer.user.js)** |
20-
| **知乎 增强** | 默认显示高清原图 | **[「安装」](https://greasyfork.org/scripts/412217)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-HD-Pictures.user.js)** |
21-
| **知乎 增强** | 置顶显示发布时间/编辑时间 | **[「安装」](https://greasyfork.org/scripts/412216)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/ZhihuEnhanced-Time.user.js)** |
18+
| **知乎 增强** | 一键收起回答、置顶显示时间、区分问题文章 | **[「安装」](https://greasyfork.org/scripts/412205)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/Zhihu-Enhanced.user.js)** |
2219
| **Github 增强** | 高速下载 \[Clone、Release、Raw、Code(ZIP)\] | **[「安装」](https://greasyfork.org/scripts/412245)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/GithubEnhanced-High-Speed-Download.user.js)** |
2320
| **3DM论坛 美化** | 精简多余内容 | **[「安装」](https://greasyfork.org/scripts/413593)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/3dm-Beautification.user.js)** |
2421
| **3DM论坛 增强** | 自动回复、自动无缝翻页、清理置顶帖子 | **[「安装」](https://greasyfork.org/scripts/412890)** | **[「安装」](https://cdn.jsdelivr.net/gh/XIU2/UserScript@master/3dm-Enhanced.user.js)** |
Lines changed: 146 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,69 @@
11
// ==UserScript==
2-
// @name 知乎增强 - 置顶显示发布/编辑时间
3-
// @version 1.0.2
2+
// @name 知乎增强
3+
// @version 1.1.0
44
// @author X.I.U
5-
// @description 回答和文章置顶显示发布时间、编辑时间
6-
// @match *://www.zhihu.com/*
7-
// @match https://zhuanlan.zhihu.com/*
5+
// @description 一键收起回答、置顶显示时间、区分问题文章
6+
// @include *://www.zhihu.com/*
7+
// @match *://zhuanlan.zhihu.com/*
88
// @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
9+
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
10+
// @grant GM_registerMenuCommand
11+
// @grant GM_unregisterMenuCommand
12+
// @grant GM_openInTab
13+
// @grant GM_getValue
14+
// @grant GM_setValue
15+
// @grant GM_notification
1216
// @license GPL-3.0 License
1317
// @run-at document-end
14-
// @namespace https://greasyfork.org/scripts/412216
18+
// @namespace https://greasyfork.org/scripts/412205
1519
// ==/UserScript==
1620

17-
var publishTop=1; //置顶回答时间
21+
var menu_collapsedAnswer = GM_getValue('xiu2_menu_collapsedAnswer');
22+
var menu_publishTop = GM_getValue('xiu2_menu_publishTop');
23+
var menu_typeTips = GM_getValue('xiu2_menu_typeTips');
24+
var menu_collapsedAnswer_ID, menu_publishTop_ID, menu_typeTips_ID, menu_feedBack_ID;
25+
if (menu_collapsedAnswer == null){menu_collapsedAnswer = true; GM_setValue('xiu2_menu_collapsedAnswer', menu_collapsedAnswer)};
26+
if (menu_publishTop == null){menu_publishTop = true; GM_setValue('xiu2_menu_publishTop', menu_publishTop)};
27+
if (menu_typeTips == null){menu_typeTips = true; GM_setValue('xiu2_menu_typeTips', menu_typeTips)};
28+
registerMenuCommand();
1829

19-
//首页
20-
function index()
30+
// 注册脚本菜单
31+
function registerMenuCommand() {
32+
var menu_collapsedAnswer_, menu_publishTop_, menu_typeTips_;
33+
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
34+
GM_unregisterMenuCommand(menu_collapsedAnswer_ID);
35+
GM_unregisterMenuCommand(menu_publishTop_ID);
36+
GM_unregisterMenuCommand(menu_typeTips_ID);
37+
GM_unregisterMenuCommand(menu_feedBack_ID);
38+
menu_collapsedAnswer = GM_getValue('xiu2_menu_collapsedAnswer');
39+
menu_publishTop = GM_getValue('xiu2_menu_publishTop');
40+
menu_typeTips = GM_getValue('xiu2_menu_typeTips');
41+
}
42+
43+
if (menu_collapsedAnswer){menu_collapsedAnswer_ = "√";}else{menu_collapsedAnswer_ = "×";}
44+
if (menu_publishTop){menu_publishTop_ = "√";}else{menu_publishTop_ = "×";}
45+
if (menu_typeTips){menu_typeTips_ = "√";}else{menu_typeTips_ = "×";}
46+
47+
menu_collapsedAnswer_ID = GM_registerMenuCommand(`[ ${menu_collapsedAnswer_} ] 一键收起回答`, function(){menu_switch(menu_collapsedAnswer,'xiu2_menu_collapsedAnswer','一键收起回答')});
48+
menu_publishTop_ID = GM_registerMenuCommand(`[ ${menu_publishTop_} ] 置顶显示时间`, function(){menu_switch(menu_publishTop,'xiu2_menu_publishTop','置顶显示时间')});
49+
menu_typeTips_ID = GM_registerMenuCommand(`[ ${menu_typeTips_} ] 区分问题文章`, function(){menu_switch(menu_typeTips,'xiu2_menu_typeTips','区分问题文章')});
50+
menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
51+
}
52+
53+
// 菜单开关
54+
function menu_switch(menu_status, Name, Tips) {
55+
if (menu_status){
56+
GM_setValue(`${Name}`, false);
57+
GM_notification(`已关闭 [${Tips}] 功能\n(刷新网页后生效)`);
58+
}else{
59+
GM_setValue(`${Name}`, true);
60+
GM_notification(`已开启 [${Tips}] 功能\n(刷新网页后生效)`);
61+
}
62+
registerMenuCommand(); // 重新注册脚本菜单
63+
};
64+
65+
// 置顶显示时间 - 首页
66+
function topTime_index()
2167
{
2268
$(".TopstoryItem").each(function(){
2369
if( !($(this).find(".ContentItem-time").hasClass("full")) && $(this).find(".ContentItem-time").length>0 && $(this).find(".ContentItem-time").find("span").text() != null)
@@ -37,7 +83,7 @@ function index()
3783
}
3884

3985
//发布时间置顶
40-
if(publishTop==1)
86+
if(menu_publishTop)
4187
{
4288
if(!$(this).find(".ContentItem-time").parent().hasClass("ContentItem-meta"))
4389
{
@@ -52,8 +98,8 @@ function index()
5298
})
5399
}
54100

55-
//回答页
56-
function question()
101+
// 置顶显示时间 - 回答页
102+
function topTime_question()
57103
{
58104
//回答的发布时间
59105
$(".ContentItem.AnswerItem").each(function(){
@@ -74,7 +120,7 @@ function question()
74120
}
75121

76122
//发布时间置顶
77-
if(publishTop==1)
123+
if(menu_publishTop)
78124
{
79125
if(!$(this).find(".ContentItem-time").parent().hasClass("ContentItem-meta"))
80126
{
@@ -90,8 +136,8 @@ function question()
90136
$(".Pc-card.Card").attr("style","display:none")
91137
}
92138

93-
//专栏/文章
94-
function zhuanlan()
139+
// 置顶显示时间 - 专栏/文章
140+
function topTime_zhuanlan()
95141
{
96142
//隐藏推荐文章
97143
$(".Recommendations-Main").hide();
@@ -107,15 +153,15 @@ function zhuanlan()
107153
}
108154

109155
//发布时间置顶
110-
if(publishTop==1 && $(".Post-Header").find(".ContentItem-time").length==0)
156+
if(menu_publishTop && $(".Post-Header").find(".ContentItem-time").length==0)
111157
{
112158
$(".ContentItem-time").css({"padding":"0px 0px 0px 0px","margin-top": "14px"});
113159
$(".ContentItem-time").appendTo($(".Post-Header"))
114160
}
115161
}
116162

117-
//搜索结果页
118-
function search()
163+
// 置顶显示时间 - 搜索结果页
164+
function topTime_search()
119165
{
120166
$(".ContentItem.AnswerItem, .ContentItem.ArticleItem").each(function(){
121167
//console.log($(this).find(".ContentItem-time"))
@@ -136,7 +182,7 @@ function search()
136182
}
137183

138184
//发布时间置顶
139-
if(publishTop==1)
185+
if(menu_publishTop)
140186
{
141187
if(!$(this).find(".ContentItem-time").parent().hasClass("SearchItem-meta"))
142188
{
@@ -150,8 +196,8 @@ function search()
150196
})
151197
}
152198

153-
//用户主页
154-
function people()
199+
// 置顶显示时间 - 用户主页
200+
function topTime_people()
155201
{
156202
$(".ContentItem.AnswerItem").each(function(){
157203
if( !($(this).find(".ContentItem-time").hasClass("full")) && $(this).find(".ContentItem-time").length>0 && $(this).find(".ContentItem-time").find("span").text() != null)
@@ -171,7 +217,7 @@ function people()
171217
}
172218

173219
//发布时间置顶
174-
if(publishTop==1)
220+
if(menu_publishTop)
175221
{
176222
if(!$(this).find(".ContentItem-time").parent().hasClass("ContentItem-meta"))
177223
{
@@ -185,6 +231,62 @@ function people()
185231
})
186232
}
187233

234+
//图片调整到最高清晰度
235+
function originalPic(){
236+
$("img").each(function(){
237+
if($(this).attr("data-original")!=undefined && !$(this).hasClass("comment_sticker"))
238+
{
239+
if($(this).attr("src") != $(this).attr("data-original"))
240+
$(this).attr("src",$(this).attr("data-original"))
241+
}
242+
})
243+
$(".Modal-inner").css({"overflow-y":"hidden"})
244+
}
245+
246+
// 一键收起回答
247+
function collapsedAnswer(){
248+
if(menu_collapsedAnswer){
249+
var button_Add = `<button id="collapsed-button" data-tooltip="收起回答" data-tooltip-position="left" data-tooltip-will-hide-on-click="false" aria-label="收起回答" type="button" class="Button CornerButton Button--plain"><svg class="ContentItem-arrowIcon is-active" aria-label="收起回答" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M16.036 19.59a1 1 0 0 1-.997.995H9.032a.996.996 0 0 1-.997-.996v-7.005H5.03c-1.1 0-1.36-.633-.578-1.416L11.33 4.29a1.003 1.003 0 0 1 1.412 0l6.878 6.88c.782.78.523 1.415-.58 1.415h-3.004v7.005z"></path></svg></button>`
250+
var style_Add = document.createElement('style');
251+
style_Add.innerHTML = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:45px !important;}';
252+
document.head.appendChild(style_Add);
253+
$(".CornerAnimayedFlex").prepend(button_Add);
254+
$("#collapsed-button").on("click", function () {
255+
document.querySelectorAll('.ContentItem-rightButton').forEach(function (el) {
256+
if (el.attributes[0].name === "data-zop-retract-question") {
257+
el.click()
258+
}
259+
});
260+
})
261+
}
262+
}
263+
264+
var postNum;
265+
// 区分问题文章
266+
function addTypeTips() {
267+
if(menu_typeTips){
268+
// URL 匹配正则表达式
269+
var patt_zhuanlan = /zhuanlan.zhihu.com/,
270+
patt_question = /question\/\d+/,
271+
patt_tip = /zhihu_e_tips/
272+
var postList = document.querySelectorAll('a[data-za-detail-view-id]');
273+
postNum = document.querySelectorAll('small.zhihu_e_tips');
274+
//console.log(`${postList.length} ${postNum.length}`);
275+
if (postList.length > postNum.length){
276+
for(var num = postNum.length;num<postList.length;num++){
277+
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
278+
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
279+
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
280+
}else if (patt_question.test(postList[num].href)){ // 如果是问题
281+
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
282+
}
283+
//postNum += 1;
284+
}
285+
}
286+
}
287+
}
288+
}
289+
188290
(function() {
189291
//折叠谢邀
190292
let timer=setInterval(function(){
@@ -212,15 +314,24 @@ function people()
212314
}
213315
})
214316

317+
//图片调整到最高清晰度
318+
setInterval(originalPic,100)
319+
215320
//每个页面对应的功能函数
216-
if(window.location.href.indexOf("question") > -1) //回答页
217-
setInterval(question, 300);
218-
else if(window.location.href.indexOf("search") > -1) //搜索结果页
219-
setInterval(search, 300);
220-
else if(window.location.href.indexOf("zhuanlan") > -1) //专栏/文章
221-
setInterval(zhuanlan, 300);
222-
else if(window.location.href.indexOf("people") > -1 || window.location.href.indexOf("org") > -1) //用户主页
223-
setInterval(people, 300);
224-
else
225-
setInterval(index, 300); //首页
321+
if(window.location.href.indexOf("question") > -1){ // 回答页
322+
collapsedAnswer(); // 一键收起回答
323+
setInterval(topTime_question, 300); // 置顶显示时间
324+
}else if(window.location.href.indexOf("search") > -1){ // 搜索结果页
325+
collapsedAnswer(); // 一键收起回答
326+
setInterval(topTime_search, 300); // 置顶显示时间
327+
}else if(window.location.href.indexOf("zhuanlan") > -1){ // 专栏/文章
328+
setInterval(topTime_zhuanlan, 300); // 置顶显示时间
329+
}else if(window.location.href.indexOf("people") > -1 || window.location.href.indexOf("org") > -1){ // 用户主页
330+
collapsedAnswer(); // 一键收起回答
331+
setInterval(topTime_people, 300); // 置顶显示时间
332+
}else{ // 首页
333+
collapsedAnswer(); // 一键收起回答
334+
setInterval(topTime_index, 300); // 置顶显示时间
335+
setInterval(addTypeTips, 1000); // 区分问题文章
336+
}
226337
})();

ZhihuEnhanced-CollapsedAnswer.user.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

ZhihuEnhanced-HD-Pictures.user.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

ZhihuEnhanced-TypeTip.user.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)