知乎信息显示

显示作者昵称,IP属地;一键屏蔽作者;显示推送类型;一键清空页面

  1. // ==UserScript==
  2. // @name 知乎信息显示
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.0
  5. // @description 显示作者昵称,IP属地;一键屏蔽作者;显示推送类型;一键清空页面
  6. // @author EFZ
  7. // @match *://www.zhihu.com/
  8. // @icon https://pic2.zhimg.com/v2-d41c2ceaed8f51999522f903672a521f_s.jpg
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_addStyle
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM_download
  15. // ==/UserScript==
  16.  
  17. //菜单
  18. let id1=GM_registerMenuCommand("屏蔽问题",menu1)
  19. let id2=GM_registerMenuCommand("屏蔽关键词",menu2)
  20. let id3=GM_registerMenuCommand("视频下载质量",menu3)
  21. function menu1(){
  22. GM_setValue('questionToken',prompt('请输入待过滤问题的token,用|分隔\n例: 4739847473|2894637237|2383284211',GM_getValue('questionToken',''))||GM_getValue('questionToken',''))
  23. }
  24. function menu2(){
  25. GM_setValue('keywords',prompt('请输入待过滤词语,用|分隔\n例: 积分题|为开头,写|如果你有,',GM_getValue('keywords',''))||GM_getValue('keywords',''))
  26. }
  27. function menu3(){
  28. GM_setValue('definition',prompt('请选择视频下载的质量\nHD或SD',GM_getValue('definition','HD'))||GM_getValue('definition','HD'))
  29. }
  30. //CSS
  31. GM_addStyle(".userTable{color: #06f;font-size: small;font_family: fantasy;width: 80% !important}")
  32. //初始化
  33. window.onload=function(){
  34. var adCards1=document.getElementsByClassName("Pc-card")
  35. var adCards2=document.getElementsByClassName("Business-Card-PcRightBanner-link")
  36. let num1=adCards1.length
  37. let num2=adCards2.length
  38. for(let i=0;i<num1;i++){adCards1[0].remove()}
  39. for(let i=0;i<num2;i++){adCards2[0].remove()}
  40. console.log('欢迎使用"知乎信息显示"')
  41. }
  42. //一键清空页面
  43. var operator=document.getElementsByClassName("SearchBar")[0]
  44. var ask=document.getElementsByClassName("SearchBar-askButton")[0]
  45. var button=document.createElement("button")
  46. button.classList.add('Button','SearchBar-askButton','css-3q84jd','Button--primary','Button--blue')
  47. ask.setAttribute("style","position: relative;left:50px;")
  48. button.setAttribute("style","position: relative;left:50px;")
  49. button.textContent="清空"
  50. button.addEventListener("click", delete_all)
  51. operator.appendChild(button)
  52. function delete_all(){
  53. let articles=document.querySelectorAll('.TopstoryItem')
  54. let num=articles.length
  55. for(let i=0;i<num;i++){articles[i].remove()}
  56. }
  57. //监视器
  58. var observer=new MutationObserver((records)=>records.forEach(deal))
  59. observer.observe(document.getElementsByClassName("Topstory-recommend")[0].children[0],{childList: true})
  60. //信息提取,操作
  61. function item_card(item){return JSON.parse(item.firstChild.getAttribute('data-za-extra-module')).card}
  62. function item_title(item){return JSON.parse(item.firstChild.firstChild.firstChild.getAttribute('data-zop')).title}
  63. function author_name(item){return item.getElementsByClassName("AuthorInfo")[1].children[0].getAttribute('content')}
  64. function author_token(item){return item.getElementsByClassName("AuthorInfo")[1].children[2].getAttribute('content').slice(29)}
  65. function image_collection(item){return item.querySelectorAll("img")}
  66. function check_anonymity1(authorToken){if (authorToken){return '关注作者'}return'无法关注'}
  67. function check_anonymity2(authorToken){if (authorToken){return '屏蔽作者'}return'无法屏蔽'}
  68. function check_image(num){if (num>1){return '下载全部图片'}return '无图片'}
  69. function check_video(card){if (card.has_video){return '下载视频'}return '无视频'}
  70. function check_formula(imageCollection,type){
  71. if (type!='Zvideo'){
  72. for(let i=1;i<imageCollection.length;i++){
  73. if (imageCollection[i].alt=='[公式]'){
  74. return '有公式'}
  75. }
  76. }
  77. return '无公式'
  78. }
  79. function check_type(type){
  80. switch(type){
  81. case 'Answer': return '回答'
  82. case 'Zvideo': return '视频'
  83. case 'QuestionAsk': return '提问'
  84. case 'Post': return '文章'
  85. }
  86. }
  87. //信息显示
  88. function deal(record){
  89. var item=record.addedNodes[0]
  90. if (item){
  91. if (item.classList.contains('TopstoryItem--advertCard')||item_card(item).content.type=='QuestionAsk'){item.remove()}
  92. else {
  93. var itemCard=item_card(item)
  94. var type=itemCard.content.type
  95. var point=item.firstChild.firstChild.firstChild.firstChild
  96. var table=document.createElement('table')
  97. point.insertBefore(table,point.firstChild)
  98. table.setAttribute('class','userTable')
  99. item.getElementsByClassName("Button")[0].click()
  100. var authorName=author_name(item)
  101. var authorToken=author_token(item)
  102. var imageCollection=image_collection(item)
  103. var imageNum=imageCollection.length
  104. item.getElementsByClassName("ContentItem-rightButton")[0].click()
  105. if (itemCard.has_video){var videoID=itemCard.content.video_id}
  106. if (type=='Zvideo'){
  107. var videoText
  108. var videoToken=itemCard.content.token
  109. GM_xmlhttpRequest({
  110. method: 'GET',
  111. url: '/zvideo/'+ videoToken,
  112. onload: function(response){videoText=response.responseText}
  113. })
  114. }
  115. table.innerHTML=`<tbody><tr><td>${check_type(type)}</td><td><button class="userButton">${check_image(imageNum)}</button></td><td><button class="userButton">${check_video(itemCard)}</button></td><td>${check_formula(imageCollection,type)}</td></tr>`+
  116. `<tr><td>${authorName}</td><td><button class="userButton">下载头像</button></td><td><button class="userButton">${check_anonymity1(authorToken)}</button></td><td><button class="userButton">${check_anonymity2(authorToken)}</button></td></tr></tbody>`
  117. var buttons=item.querySelectorAll(".userButton")
  118. buttons[0].addEventListener("click",function(){
  119. if(imageNum>1){
  120. for(let i=1;i<imageNum;i++){GM_download(imageCollection[i].src,'知乎图片'+i)}
  121. }
  122. })
  123. buttons[1].addEventListener("click",function(){
  124. if (itemCard.has_video){
  125. GM_xmlhttpRequest({method: 'GET',url: 'https://lens.zhihu.com/api/v4/videos/'+videoID,onload: function(response){GM_download(JSON.parse(response.responseText).playlist[GM_getValue('definition','HD')].play_url,item_title(item))}})
  126. }
  127. })
  128. buttons[2].addEventListener("click",function(){GM_download(imageCollection[0].src,authorName)})
  129. buttons[3].addEventListener("click",function(){if(authorToken){
  130. var key96
  131. var key81
  132. if (this.textContent=='关注作者'){GM_xmlhttpRequest({method: 'POST',url: `/api/v4/members/${authorToken}/followers`,headers: {'x-zse-93': '101_3_2.0','x-zse-96': key96,'x-zst-81': key81}});this.textContent='取消关注'}
  133. else if (this.textContent=='取消关注'){GM_xmlhttpRequest({method: 'DELETE',url: `/api/v4/members/${authorToken}/followers`});this.textContent='关注作者'}
  134. }
  135. })
  136. buttons[4].addEventListener("click",function(){if (authorToken){
  137. if (this.textContent=='屏蔽作者'){GM_xmlhttpRequest({method: 'POST',url: `/api/v4/members/${authorToken}/actions/block`});this.textContent='取消屏蔽'}
  138. else if (this.textContent=='取消屏蔽'){GM_xmlhttpRequest({method: 'DELETE',url: `/api/v4/members/${authorToken}/actions/block`});this.textContent='屏蔽作者'}
  139. }
  140. }
  141. )
  142. //GM_xmlhttpRequest({method: 'GET',url: `https://www.zhihu.com/api/v4/members/${authorToken}`,onload: function(response){......=JSON.parse(response.responseText).ip_info}})
  143. }
  144. }
  145. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址