zhi-hu

知知乎乎(收藏夹双列;隐藏视频回答;加宽;区分问题和视频)

当前为 2023-06-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name zhi-hu
  3. // @namespace https://greasyfork.org/zh-CN/scripts/438709-zhi-hu
  4. // @version 0.0.14
  5. // @description 知知乎乎(收藏夹双列;隐藏视频回答;加宽;区分问题和视频)
  6. // @author Song
  7. // @match *://www.zhihu.com/*
  8. // @match *://zhuanlan.zhihu.com/*
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12. (function () {
  13.  
  14. function addStyle() {
  15. let el = document.createElement('style');
  16. el.setAttribute('name', 'zhi_zhi_hu_hu');
  17. document.head.appendChild(el);
  18. }
  19.  
  20. /**
  21. * 插入样式表
  22. */
  23. function insertCSS() {
  24. let styleSheet = document.styleSheets[document.styleSheets.length - 1];
  25. /*收藏栏的样式,变成双列*/
  26. styleSheet.insertRule('.Modal--large.FavlistsModal {width: 600px;}');
  27. styleSheet.insertRule('.Favlists-content .Favlists-item {width: 230px; float: left;}');
  28. styleSheet.insertRule(' .Favlists-content .Favlists-item:nth-child(even){margin-left: 60px;}');
  29.  
  30. /*隐藏视频回答*/
  31. styleSheet.insertRule('.VideoAnswerPlayer, .VideoAnswerPlayer video, .VideoAnswerPlayer-video, .VideoAnswerPlayer-iframe {height: 2px;}');
  32. // styleSheet.insertRule('.ZVideoItem {height: 2px;}');
  33. styleSheet.insertRule('.ContentItem.ZVideoItem {height: 8px;}');
  34. styleSheet.insertRule('.ContentItem.EduSectionItem {height: 8px;}');
  35. styleSheet.insertRule('.ZvideoItem .RichContent-cover{ height:8px; }');
  36. styleSheet.insertRule('.ZvideoItem .RichContent-cover-inner{height:4px; }');
  37. styleSheet.insertRule('.VideoAnswerPlayer video, nav.TopstoryTabs > a[aria-controls="Topstory-zvideo"]{height:4px; }');
  38.  
  39.  
  40. /*区分问题 和 视频*/
  41. let style = `font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin: ${(location.pathname === '/search') ? '2' : '4'}px 4px 0 0;`
  42. let styles = [
  43. `.AnswerItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'回答';color: #f68b83;background-color: #f68b8333;${style}}`,
  44. `.TopstoryQuestionAskItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'回答';color: #ff5a4e;background-color: #ff5a4e33;${style}}`,
  45. `.ZVideoItem .ContentItem-title a::before, .ZvideoItem .ContentItem-title a::before {content:'视频';color: #00BCD4;background-color: #00BCD433;${style}}`,
  46. `.ArticleItem .ContentItem-title a::before {content:'文章';color: #2196F3;background-color: #2196F333;${style}}`
  47. ];
  48. styles.forEach(s => styleSheet.insertRule(s));
  49.  
  50. /*视频*/
  51. styleSheet.insertRule('.ZVideoItem .RichContent{opacity: 0.5; color: #666 !important; font-style:italic !important;}');
  52.  
  53. /*调整列表中专栏文章的样式*/
  54. styleSheet.insertRule('.ContentItem[itemprop=article]{opacity: 0.5; color: #666;font-style:italic;}');
  55. styleSheet.insertRule('.ContentItem[itemprop=article] .ContentItem-title{color: #666; }');
  56.  
  57.  
  58. }
  59.  
  60. /**
  61. * 增宽
  62. * @param {number} maxWidth
  63. */
  64. function widening(maxWidth) {
  65. const ww = window.innerWidth - 30;
  66. if (ww < 1000) return;
  67.  
  68. let w = ww > maxWidth ? maxWidth : ww;
  69. let styleSheet = document.styleSheets[document.styleSheets.length - 1];
  70. styleSheet.insertRule('.Topstory-container, .Question-main{min-width:' + w + 'px !important;}');
  71. styleSheet.insertRule('.Topstory-mainColumn, .Question-mainColumn{width:' + (w - 300) + 'px !important;}');
  72. // document.querySelector('.Topstory-container').style.minWidth = w + 'px';
  73. // document.querySelector('.Topstory-mainColumn').style.width = (w - 300) + 'px';
  74. // 专栏文章
  75. styleSheet.insertRule('.Post-Main .Post-RichTextContainer {min-width:' + w + 'px !important;}');
  76. }
  77.  
  78. addStyle();
  79. widening(1200);
  80. insertCSS();
  81. })();