知乎看图脚本

让我们愉快地看图吧

  1. // ==UserScript==
  2. // @name 知乎看图脚本
  3. // @namespace https://github.com/cheezone
  4. // @version 1.0
  5. // @description 让我们愉快地看图吧
  6. // @author 以茄之名
  7. // @author:en Chezz
  8. // @homepage https://www.zhihu.com/people/iCheez
  9. // @match https://www.zhihu.com/question/*
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-3.3.1.slim.min.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var css=`.Select-option:hover{background-color:rgb(246,246,246)}.Select-option{background-color:rgb(256,256,256)} `
  18. //按钮之间总是会粘结,特别恶心
  19. var head = document.head || document.getElementsByTagName('head')[0];
  20. var style = document.createElement('style');
  21. style.type = 'text/css';
  22. style.appendChild(document.createTextNode(css));
  23. head.appendChild(style);
  24. var appendChild = Node.prototype.appendChild;
  25. $(".RichText:has(figure)").parents('.AnswerItem').addClass('has-img');
  26. Node.prototype.appendChild = function() {
  27. if(this.classList&&this.classList.contains('RichContent')){
  28. if($(this).find('.RichText:has(figure)').length>0){
  29. $(this).parents('.AnswerItem').addClass('has-img');
  30. }else
  31. if($('body').hasClass('hiden-img')){
  32. $(this).parents('.AnswerItem').hide();
  33. //
  34. }
  35. }
  36. if(this.tabIndex==-1 && this.tagName=='DIV'){
  37. if(this.innerText=='默认排序'){
  38. console.error(this);
  39. var but=this.firstChild.cloneNode();
  40. but.id='show-image-only';
  41. if($('body').hasClass('hiden-img')){
  42. but.innerText='恢复答案';
  43. $('.Button.Select-button.Select-plainButton.Button--plain').text('默认排序')
  44. }else{
  45. $('.Button.Select-button.Select-plainButton.Button--plain').text('只看有图')
  46. but.innerText='只看有图的答案';
  47. }
  48.  
  49. this.insertBefore(but,this.firstChild);
  50. but.addEventListener('click', function(event) {
  51. if($('body').hasClass('hiden-img')){
  52. $('.AnswerItem:not(.has-img)').show();
  53. $('body').removeClass('hiden-img')
  54.  
  55. }else{
  56.  
  57. $('.AnswerItem:not(.has-img)').hide();
  58. $('body').addClass('hiden-img')
  59. }
  60. });
  61.  
  62. }
  63. }
  64. return appendChild.apply(this, arguments);
  65. };
  66. })();

QingJ © 2025

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