Remove zhihu video

Just remove zhihu video

目前为 2021-12-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Remove zhihu video
  3. // @namespace https://www.Removezhihuvideo.com
  4. // @version 0.3
  5. // @description Just remove zhihu video
  6. // @author You
  7. // @match https://www.zhihu.com/*
  8. // @icon http://zhihu.com/favicon.ico
  9. // @grant none
  10. // @run-at document-body
  11. // ==/UserScript==
  12.  
  13.  
  14. let inited = false;
  15.  
  16. function callback(mutationsList) {
  17.  
  18. for (let m of mutationsList) {
  19. if (m.type == 'childList' && m.addedNodes.length > 0) {
  20.  
  21. for (let node of m.addedNodes) {
  22. //console.log('addnodes:', node);
  23. if (!inited && node.tagName === 'DIV')
  24. {
  25. for (let cnode of node.querySelectorAll('.TopstoryItem')) {
  26. removeIfVideo(cnode);
  27. }
  28. inited = true;
  29. }
  30. if (node.tagName === 'DIV' && node.classList.contains('TopstoryItem')) {
  31. removeIfVideo(node);
  32. }
  33. }
  34. }
  35. }
  36. }
  37.  
  38. for (let node of document.querySelectorAll('.TopstoryItem')) {
  39. removeIfVideo(node);
  40. }
  41.  
  42.  
  43. const observer = new MutationObserver(callback);
  44. observer.observe(document.body, {
  45. childList: true,
  46. subtree: true
  47. })
  48.  
  49. function removeIfVideo(node) {
  50. let n = node.querySelector('.ZVideoItem');
  51. if (n) {
  52. let m = n.querySelector('iframe');
  53. if (m && m.src &&
  54. m.src.indexOf('www.zhihu.com/video/') >= 0 ||
  55. m.src.indexOf('video.zhihu.com') >= 0
  56. ) {
  57. const m2 = node.querySelector('.ZVideoItem-video');
  58. if (m2 && n.children.length === 3) {
  59. n.children[1].style.display = 'none';
  60. n.children[2].style.display = 'none';
  61. let div = document.createElement('div');
  62. div.innerHTML = '<button class="Button">show video</button>'
  63. n.appendChild(div);
  64. div.addEventListener('click', function () {
  65. n.children[1].style.display = '';
  66. n.children[2].style.display = '';
  67. div.remove();
  68. });
  69. }
  70. }
  71. }
  72. }

QingJ © 2025

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