// ==UserScript== // @name 知乎 显示匿名按钮、查看问题日志按钮、快捷键帮助按钮、知乎跳转改为直链 // @namespace http://tampermonkey.net/ // @version 0.8.8 // @description 显示匿名按钮、查看问题日志按钮、快捷键帮助按钮、知乎跳转改为直链 // @author AN drew // @match https://www.zhihu.com/* // @match https://zhuanlan.zhihu.com/* // @require https://code.jquery.com/jquery-3.1.1.min.js // @grant none // @downloadURL none // ==/UserScript== var $hint =$('
'+ '
'+ '
'+ ' '+ '
'+ '
'+ '
') function addReport($QuestionHeaderActions,$more) { var r ='' var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".Menu.QuestionHeader-menu").children().eq(2).click(); }) $more.after($report) } function addAnonymous($QuestionHeaderActions,$more) { var a ='' var $anonymous = $(a) $anonymous.bind("click",function(){ $more.find("button").click(); $(".Menu.QuestionHeader-menu").children().eq(0).click(); }) $QuestionHeaderActions.append($anonymous) } function addLog($QuestionHeaderActions) { var url = window.location.href; var end,href; if(url.indexOf("answer")>-1) { end=url.indexOf("answer") href = url.substring(0,end); } else { href=url+"/" } var L='' var $log = $(L); $QuestionHeaderActions.append($log) } function addShortCut($QuestionHeaderActions) { var s ='' var $shortcut = $(s) $shortcut.css({"margin-left":"10px"}) $shortcut.click(function(){ $(".Modal-wrapper").show() }); $QuestionHeaderActions.append($shortcut) } function addReport1($more) { $more.hide() var r = '' var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".Menu.AnswerItem-selfMenu").find("button").click(); }) $more.after($report) } function question() { if($(".Modal-wrapper").length==0) { $(document.body).append($hint) $(".Modal-wrapper").hide() $(".Modal-closeButton").click(function(){ $(".Modal-wrapper").hide() }) } var $QuestionHeaderActions = $("div.QuestionHeaderActions") var $more = $(".Zi--Dots").parent().parent().parent() //更多 var $report = $(".Title.Zi--Report") //举报 var $anonymous = $(".Zi--Anonymous")//匿名 var $log = $(".Zi--Log") //日志 var $shortcut = $(".Zi--ShortCut") //快捷键 $more.attr("style","display:none") if($(".AppHeader-profileAvatar").length>0) //已登录 { if($report.length == 0) //未添加举报 { addReport($QuestionHeaderActions,$more) } if($anonymous.length == 0) //未添加匿名 { addAnonymous($QuestionHeaderActions,$more) } if($log.length == 0) //未添加查看问题日志 { addLog($QuestionHeaderActions) } if($shortcut.length == 0) //未添加快捷键帮助 { addShortCut($QuestionHeaderActions) } var $ContentItem_actions = $(".ContentItem-actions") $ContentItem_actions.each(function(){ var $Content_child5 = $(this).children().eq(5-1) //喜欢 var $Content_child6 = $(this).children().eq(6-1) //更多 var $Content_child7 = $(this).children().eq(7-1) //举报 if($Content_child5.length>0 && $Content_child5.text().indexOf("喜欢")==-1) { return true; } else if($Content_child7.length==0 || $Content_child7.text().indexOf("举报")==-1 ) //未添加举报 { addReport1($Content_child6) } }) } else //未登录 { $log = $(".Zi--Log") //日志 $shortcut = $(".Zi--ShortCut") //快捷键 if($log.length == 0) //未添加查看问题日志 { addLog($QuestionHeaderActions) } if($shortcut.length == 0) //未添加快捷键帮助 { addShortCut($QuestionHeaderActions) } } $(".CommentCollapseButton").on("click",function(){ $(this).parent().parent().parent().prev().find(".Zi--Comment").attr("fill","currentColor") }) $(".ContentItem-time").each(function(){ if($(this).text().indexOf("发布于")==-1) { var data_tooltip = $(this).find("span").attr("data-tooltip"); var oldtext = $(this).find("span").text(); $(this).find("span").text(data_tooltip+"\xa0\xa0,\xa0\xa0"+oldtext); } }) var $QuestionButtonGroup = $(".QuestionHeader-footer-main").find(".QuestionButtonGroup") $QuestionButtonGroup.children().eq(0).css({"margin": "0px 0px 0px 8px"}) $QuestionButtonGroup.children().eq(1).css({"margin": "0px 0px 0px 8px"}) $(".QuestionHeaderActions").children().eq(0).css({"margin": "0px 8px 0px 0px"}) $(".GoodQuestionAction-commonBtn").css("margin","0") $(".GoodQuestionAction-commonBtn").css("margin-right","10px") $(".Pc-card.Card").attr("style","display:none") $(".Card.ViewAll").attr("style","background-color:#0084FF") $(".QuestionMainAction.ViewAll-QuestionMainAction").attr("style","color:white") } function directLink() { var equal,colon,external_href,protocol,path,new_href; $("a[class*='external']").each(function(){ if($(this).find("span").length>0) { new_href = $(this).text() $(this).attr("href",decodeURIComponent(new_href)) } else if($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) { external_href=$(this).attr("href") equal = external_href.lastIndexOf("http") colon = external_href.lastIndexOf("%3A") protocol = external_href.substring(equal,colon) path = external_href.substring(colon+5,external_href.length) new_href = protocol+"://"+path console.log(new_href) $(this).attr("href",decodeURIComponent(new_href)) } }) $("a[class*='LinkCard']").each(function(){ if($(this).find("LinkCard-title").length>0 && $(this).find("LinkCard-title").indexOf("http")>-1 ) { new_href = $(this).find("LinkCard-title").text() $(this).attr("href",decodeURIComponent(new_href)) } else if($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) { external_href=$(this).attr("href") equal = external_href.lastIndexOf("http") colon = external_href.lastIndexOf("%3A") protocol = external_href.substring(equal,colon) path = external_href.substring(colon+5,external_href.length) new_href = protocol+"://"+path $(this).attr("href",decodeURIComponent(new_href)) } }) $(".TopstoryItem--advertCard").hide() } function addReport2($more) { $more.hide() var r = '' var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".Menu.Post-ActionMenu").find("button").click(); }) $more.after($report) } function zhuanlan() { $(".Recommendations-Main").hide() var $ContentItem_actions = $(".ContentItem-actions") var $child5 = $ContentItem_actions.children().eq(5-1) var $child6 = $ContentItem_actions.children().eq(6-1) if($child6.length == 0) //未添加举报 { addReport2($child5) } } function zvideo() { $(".ZVideo-sideColumn").hide() } function addReport3($more) { $more.hide() var r =''; var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".ClubHeaderInfoMoreButton-item").click(); }) $more.after($report) } function addReport4($more) { $more.hide() var r = '' var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".PostWebActionButtons-item").click(); }) $more.after($report) } function club() { var $ClubHeaderInfo_buttonGroup = $(".ClubHeaderInfo-buttonGroup") var $child1 = $ClubHeaderInfo_buttonGroup.children().eq(1-1) var $child2 = $ClubHeaderInfo_buttonGroup.children().eq(2-1) if($child2.length > 0 && $child2.text().indexOf("签到") > -1 && $child2.text().indexOf("加入") == -1) //退出圈子 { addReport3($child1) } $(".PostReaction").each(function(){ var post_child5 = $(this).children().eq(5-1) var post_child6 = $(this).children().eq(6-1) if(post_child6.length==0 || post_child6.text().indexOf("举报")==-1 ) //未添加举报 { addReport4(post_child5) } }) } function addReport5($more) { $more.hide() var r = '' var $report = $(r) $report.bind("click",function(){ $more.find("button").click(); $(".AnswerItem-selfMenu").children().eq(1).click(); }) $more.after($report) } function search() { $(".ContentItem-actions").each(function(){ var $child6 = $(this).children().eq(6-1) var $child7 = $(this).children().eq(7-1) if($child7.text().indexOf("收起") > -1) { addReport5($child6) } }) } function lives() { $("[class*='LiveWechatSpread']").remove() } function collection() { $(".ContentItem-actions").each(function(){ var $child6 = $(this).children().eq(6-1) var $child7 = $(this).children().eq(7-1) if($child7.length==0 || $child7.text().indexOf("收起") > -1) { addReport5($child6) } }) } function iconColor() { $(".Zi--List").parent().parent().hover(function(){ $(this).find(".Zi--List").attr("fill","#0084FF") },function(){ $(this).find(".Zi--List").attr("fill","currentColor") }) $(".Zi--Comment").parent().parent().hover(function(){ $(this).find(".Zi--Comment").attr("fill","#0084FF") },function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("收起评论")==-1) $(this).find(".Zi--Comment").attr("fill","currentColor") }) $(".Zi--Comment").parent().parent().on("click",function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("收起评论")==-1) $(this).find(".Zi--Comment").attr("fill","#0084FF") else $(this).find(".Zi--Comment").attr("fill","currentColor") }) $(".Zi--Comments").parent().parent().hover(function(){ $(this).find(".Zi--Comments").attr("fill","#00FF7F") },function(){ if($(".Messages-content").length==0) $(this).find(".Zi--Comments").attr("fill","currentColor") }) $(".Zi--Comments").parent().parent().on("click",function(){ if($(".Messages-content").length==0) $(this).find(".Zi--Comments").attr("fill","#00FF7F") else $(this).find(".Zi--Comments").attr("fill","currentColor") }) $(".Zi--Reply").parent().parent().hover(function(){ $(this).find(".Zi--Reply").attr("fill","#32CD32") },function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("取消回复")==-1) $(this).find(".Zi--Reply").attr("fill","currentColor") }) $(".Zi--Reply").parent().parent().on("click",function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("取消回复")==-1) $(this).find(".Zi--Reply").attr("fill","#32CD32") else $(this).find(".Zi--Reply").attr("fill","currentColor") }) $(".Zi--Reply").parent().parent().each(function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("取消回复") > -1) $(this).find(".Zi--Reply").attr("fill","#32CD32") }) $(".Zi--Like").parent().parent().hover(function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("踩") > -1 || $(this).attr("data-tooltip")=="不推荐") $(this).find(".Zi--Like").attr("fill","black") else $(this).find(".Zi--Like").attr("fill","#0084FF") },function(){ if($(this).find("#topic-recommend").length>0 ||$(this).find("#topic-against").length>0 || $(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue.indexOf("取消踩") == -1) $(this).find(".Zi--Like").attr("fill","currentColor") }) $(".Zi--Like").parent().parent().each(function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue=="取消踩") $(this).find(".Zi--Like").attr("fill","black") }) $(".Zi--Share").parent().parent().hover(function(){ $(this).find(".Zi--Share").attr("fill","blue") },function(){ $(this).find(".Zi--Share").attr("fill","currentColor") }) $(".Zi--Star").parent().parent().hover(function(){ $(this).find(".Zi--Star").attr("fill","orange") },function(){ $(this).find(".Zi--Star").attr("fill","currentColor") }) $(".Zi--Heart").parent().parent().hover(function(){ $(this).find(".Zi--Heart").attr("fill","red") },function(){ if($(this).prop('lastChild').nodeValue=="喜欢") $(this).find(".Zi--Heart").attr("fill","currentColor") }) $(".Zi--Heart").parent().parent().on("click",function(){ if($(this).prop('lastChild').nodeValue=="喜欢") $(this).find(".Zi--Heart").attr("fill","red") else $(this).find(".Zi--Heart").attr("fill","currentColor") }) $(".Zi--Heart").parent().parent().each(function(){ if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue=="取消喜欢") $(this).prop('lastChild').nodeValue="已喜欢" if($(this).prop('lastChild').nodeValue!=null && $(this).prop('lastChild').nodeValue=="已喜欢") $(this).find(".Zi--Heart").attr("fill","red") }) $(".Zi--Report").parent().parent().hover(function(){ $(this).find(".Zi--Report").attr("fill","brown") },function(){ $(this).find(".Zi--Report").attr("fill","currentColor") }) $(".Zi--Bell").parent().parent().hover(function(){ $(this).find(".Zi--Bell").attr("fill","#FACB62") },function(){ if($(".PushNotifications-content").length==0) $(this).find(".Zi--Bell").attr("fill","currentColor") }) $(".Zi--Bell").parent().parent().on("click",function(){ if($(".PushNotifications-content").length==0) $(this).find(".Zi--Bell").attr("fill","#FACB62") else $(this).find(".Zi--Bell").attr("fill","currentColor") }) $(".Zi--Heart.PushNotifications-tabIcon").parent().parent().hover(function(){ $(this).find(".Zi--Heart").attr("fill","#0084FF") },function(){ $(this).find(".Zi--Heart").attr("fill","currentColor") }) $(".Zi--Users").parent().parent().hover(function(){ $(this).find(".Zi--Users").attr("fill","#0084FF") },function(){ $(this).find(".Zi--Users").attr("fill","currentColor") }) $(".Zi--Anonymous").parent().parent().hover(function(){ $(this).find(".Zi--Anonymous").attr("fill","black") },function(){ $(this).find(".Zi--Anonymous").attr("fill","currentColor") }) $(".Zi--Log").parent().parent().hover(function(){ $(this).find(".Zi--Log").attr("fill","blue") },function(){ $(this).find(".Zi--Log").attr("fill","currentColor") }) $(".Zi--ShortCut").parent().parent().hover(function(){ $(this).find(".Zi--ShortCut").attr("fill","#6D6D6D") },function(){ $(this).find(".Zi--ShortCut").attr("fill","currentColor") }) $(".Zi--Trash").parent().parent().hover(function(){ $(this).find(".Zi--Trash").attr("fill","#C70000") },function(){ $(this).find(".Zi--Trash").attr("fill","currentColor") }) $(".Zi--Emotion").parent().parent().hover(function(){ $(this).find(".Zi--Emotion").find("path").attr("fill","#0084FF") },function(){ $(this).find(".Zi--Emotion").find("path").removeAttr("fill") }) $(".Zi--AddImage").parent().parent().hover(function(){ $(this).find(".Zi--AddImage").find("path").attr("fill","#0084FF") },function(){ $(this).find(".Zi--AddImage").find("path").removeAttr("fill") }) $(".Zi--InsertImage").parent().hover(function(){ $(this).find(".Zi--InsertImage").find("path").attr("fill","#0084FF") },function(){ $(this).find(".Zi--InsertImage").find("path").removeAttr("fill") }) $(".Zi--InsertVideo").parent().hover(function(){ $(this).find(".Zi--InsertVideo").find("path").attr("fill","red") },function(){ $(this).find(".Zi--InsertVideo").find("path").removeAttr("fill") }) $(".Zi--InsertLink").parent().hover(function(){ $(this).find(".Zi--InsertLink").find("path").attr("fill","black") },function(){ $(this).find(".Zi--InsertLink").find("path").removeAttr("fill") }) $(".Zi--Folder").parent().hover(function(){ $(this).find(".Zi--Folder").find("path").attr("fill","#FF8C00") },function(){ $(this).find(".Zi--Folder").find("path").removeAttr("fill") }) $(".Zi--Switch").attr("fill","#0084FF") $(".Zi--Switch").parent().parent().css("color","black") } (function() { 'use strict'; setInterval(directLink,100) setInterval(iconColor,100) if(window.location.href.indexOf("question") > -1) setInterval(question, 300); else if(window.location.href.indexOf("zvideo") > -1) setInterval(zvideo, 300); else if(window.location.href.indexOf("club") > -1) setInterval(club, 300); else if(window.location.href.indexOf("search") > -1) setInterval(search, 300); else if(window.location.href.indexOf("lives") > -1) setInterval(lives, 300); else if(window.location.href.indexOf("collection") > -1) setInterval(collection, 300); else if(window.location.href.indexOf("zhuanlan") > -1) setInterval(zhuanlan, 300); // Your code here... })();