// ==UserScript==
// @name 知乎 显示匿名按钮、查看问题日志按钮、快捷键帮助按钮、知乎跳转改为直链
// @namespace http://tampermonkey.net/
// @version 0.8.2
// @description 显示匿名按钮、查看问题日志按钮、快捷键帮助按钮、知乎跳转改为直链
// @author AN drew
// @match https://www.zhihu.com/*
// @match https://zhuanlan.zhihu.com/p/*
// @require https://code.jquery.com/jquery-3.1.1.min.js
// @grant none
// @downloadURL none
// ==/UserScript==
var $hint =$('
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
快捷键帮助
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' 操作'+
'
'+
'
'+
'
'+
'
'+
' :赞同'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :反对'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :喜欢'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :展开 / 收起评论'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
Shift'+
'
'+
' +'+
'
'+
'
'+
'
'+
' C'+
'
'+
'
'+
'
'+
' :聚焦到评论框'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :展开 / 收起全文'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' C'+
'
'+
'
'+
'
'+
' :收藏'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' X'+
'
'+
'
'+
'
'+
' :分享'+
'
'+
'
'+
'
'+
'
'+
'
'+
' 导航'+
'
'+
'
'+
'
'+
'
'+
' :下一项'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :上一项'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' G'+
'
'+
'
'+
'
'+
' :第一项'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
Shift'+
'
'+
' +'+
'
'+
'
'+
'
'+
' G'+
'
'+
'
'+
'
'+
' :最后一项'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
Shift'+
'
'+
' +'+
'
'+
'
'+
'
'+
' U'+
'
'+
'
'+
'
'+
' :向上滚动半屏'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
Shift'+
'
'+
' +'+
'
'+
'
'+
'
'+
' D'+
'
'+
'
'+
'
'+
' :向下滚动半屏'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :搜索'+
'
'+
'
'+
'
'+
'
'+
'
'+
' :快捷键帮助'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
')
function addAnonymous($QuestionHeaderActions,$child5)
{
var a ='';
var $anonymous = $(a)
$anonymous.bind("click",function(){
$child5.find("button").click();
$(".Menu.QuestionHeader-menu > button").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);
var $Popover = $('')
$Popover.append($log)
$QuestionHeaderActions.append($Popover)
}
function addShortCut($QuestionHeaderActions)
{
var s ='';
var $shortcut = $(s)
$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 $child4 = $QuestionHeaderActions.children().eq(4-1)
var $child5 = $QuestionHeaderActions.children().eq(5-1)
var $child6 = $QuestionHeaderActions.children().eq(6-1)
var $child7 = $QuestionHeaderActions.children().eq(7-1)
var $child8 = $QuestionHeaderActions.children().eq(8-1)
if($child4.length>0 && $child4.text().indexOf("举报")> -1) //已登录
{
$child5.attr("style","display:none")
if($child6.length == 0) //未添加匿名
{
addAnonymous($QuestionHeaderActions,$child5)
}
if($child7.length == 0) //未添加查看问题日志
{
addLog($QuestionHeaderActions)
}
if($child8.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 //未登录
{
$child4.attr("style","display:none")
if($child5.length == 0) //未添加查看问题日志
{
addLog($QuestionHeaderActions)
}
if($child6.length == 0) //未添加快捷键帮助
{
addShortCut($QuestionHeaderActions)
}
}
$(".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);
}
})
$(".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("https://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))
}
})
$("a[class*='LinkCard']").each(function(){
console.log($(this).find("LinkCard-title").get(0))
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("https://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_child4 = $(this).children().eq(4-1)
var post_child5 = $(this).children().eq(5-1)
if(post_child5.length==0 || post_child5.text().indexOf("举报")==-1 ) //未添加举报
{
addReport4(post_child4)
}
})
}
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)
console.log($child6)
console.log($child7)
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)
console.log($child6)
console.log($child7)
if($child7.length==0 || $child7.text().indexOf("收起") > -1)
{
addReport5($child6)
}
})
}
(function() {
'use strict';
$("time").css({"color":"blue","font-weight":"bold","font-size":"15px"})
setInterval(directLink,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.zhihu.com") > -1)
setInterval(zhuanlan, 300);
// Your code here...
})();