Clean zhuanlan.zhihu

制作知乎专栏方便打印的版本

  1. // ==UserScript==
  2. // @name Clean zhuanlan.zhihu
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 制作知乎专栏方便打印的版本
  6. // @author You
  7. // @match https://zhuanlan.zhihu.com/*
  8. // @grant none
  9. // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
  10. // @require https://greasyfork.org/scripts/31940-waitforkeyelements/code/waitForKeyElements.js?version=209282
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var staticClassNames = [
  17. 'Sticky ColumnPageHeader',
  18. 'Sticky RichContent-actions',
  19. ];
  20.  
  21. var AJAXClassNames = [
  22. 'Sticky ColumnPageHeader',
  23. 'CommentList',
  24. 'Recommendations-List',
  25. 'Recommendations-Main',
  26. 'Comments-container',
  27. ];
  28.  
  29. // jQuery remove/empty does not work.
  30. // from stackoverflow:
  31. // https://stackoverflow.com/questions/3387427/remove-element-by-id
  32. Element.prototype.remove = function() {
  33. this.parentElement.removeChild(this);
  34. }
  35. NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
  36. for(var i = this.length - 1; i >= 0; i--) {
  37. if(this[i] && this[i].parentElement) {
  38. this[i].parentElement.removeChild(this[i]);
  39. }
  40. }
  41. }
  42.  
  43. // static
  44. staticClassNames.forEach(function(name) {
  45. var elems = document.getElementsByClassName(name);
  46. elems.remove();
  47. console.log(name);
  48. });
  49.  
  50. // dynamic
  51. AJAXClassNames.forEach(function(name) {
  52. waitForKeyElements('.'+name, function(elem){ elem.empty();});
  53. });
  54.  
  55. })();