Youtube comments remover and description expander

Removes comments section from Youtube video pages and auto expand description section

当前为 2017-08-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube comments remover and description expander
  3. // @description Removes comments section from Youtube video pages and auto expand description section
  4. // @include /^http(|s)://www\.youtube\.com/watch\?v=.*$/
  5. // @grant none
  6. // @author iceman94
  7. // @copyright 2015+, iceman94
  8. // @version 0.01
  9. // @grant none
  10. // @namespace 38a3e9648fc5260c75446e376a8dabb3
  11. // ==/UserScript==
  12.  
  13.  
  14. //=======================================================================================================
  15. // Cross-browsers load function
  16. // Tests in this order :
  17. // -support for jQuery API
  18. // |-uses $(window).load method if available
  19. // |-uses $(window).ready method if available
  20. // -support for DOMContentLoaded event (compatible only with the following browsers :
  21. // Chrome >= 0.2; Firefox >= 1.0; IE >= 9.0; Opera >= 9.0; Safari >= 3.1)
  22. // -support for document.attachEvent
  23. // -uses setTimeout w/ 5000ms delay
  24. //=======================================================================================================
  25.  
  26. function XBLoad(func, verbose)
  27. {
  28. verbose = verbose || false;
  29.  
  30. if (window.jQuery)
  31. {
  32. if ($(window).load)
  33. {
  34. if (verbose == true) { console.log('Javascript loaded using $(window).load method'); };
  35. return $(window).load(function() { func(); });
  36. }
  37. else if ($(window).ready)
  38. {
  39. if (verbose == true) { console.log('Javascript loaded using $(window).ready method'); };
  40. return $(window).ready(function() { func(); });
  41. };
  42. }
  43. else if (document.addEventListener)
  44. {
  45. if (verbose == true) { console.log('Javascript loaded using document.addEventListener method'); };
  46. document.addEventListener('DOMContentLoaded', function(event)
  47. {
  48. return func();
  49. });
  50. }
  51. else if (document.attachEvent)
  52. {
  53. if (verbose == true) { console.log('Javascript loaded using document.attachEvent method'); };
  54. document.attachEvent('load', function()
  55. {
  56. return func();
  57. });
  58. }
  59. else
  60. {
  61. if (verbose == true) { console.log('Javascript loaded using setTimeout method'); };
  62. return setTimeout(function() { func(); }, 5000);
  63. };
  64. };
  65.  
  66. //=======================================================================================================
  67. // Setting up functions
  68. //=======================================================================================================
  69.  
  70. // Searches for string in a given array and returns an object comprised of an index and its content
  71. function searchStringInArray (str, arr)
  72. {
  73. var obj = {};
  74. for (var i=0; i<arr.length; i++)
  75. {
  76. if (arr[i].match(str))
  77. {
  78. obj.idx = i;
  79. obj.content = arr[i];
  80. return obj;
  81. }
  82. }
  83. return -1;
  84. }
  85.  
  86. // Deletes a DOM node based of its type (id, tag or class)
  87. function delElement (elmt_type, elmt_name)
  88. {
  89. switch (elmt_type)
  90. {
  91. case 'id':
  92. var tgt = document.getElementById(elmt_name);
  93. break;
  94. case 'tag':
  95. var tgt = document.getElementsByTagName(elmt_name)[0];
  96. break;
  97. case 'class':
  98. var tgt = document.getElementsByClassName(elmt_name)[0];
  99. break;
  100. default:
  101. console.log("delElement syntax error\nUsage:\n delElement(<[id|tag|class]>, <elmt_name>)");
  102. return -1;
  103. }
  104. tgt.parentNode.removeChild(tgt);
  105. }
  106.  
  107. // Deletes index from a given array by value
  108. function delIdxFromArrayByValue (str, arr)
  109. {
  110. if (searchStringInArray(str, arr))
  111. {
  112. arr.splice(searchStringInArray(str, arr).idx, 1);
  113. }
  114. }
  115.  
  116. // Wrapper comprised of all functions to be called by the GM/TM script
  117. function showtime ()
  118. {
  119. delElement('id', 'watch-discussion');
  120. var dscNode = document.getElementById('action-panel-details');
  121. var dscClassesArr = dscNode.className.split(' ');
  122. delIdxFromArrayByValue('yt-uix-expander-collapsed', dscClassesArr);
  123. dscNode.className = dscClassesArr.join(' ');
  124. }
  125.  
  126.  
  127. //=======================================================================================================
  128. // Showtime !
  129. //=======================================================================================================
  130.  
  131. XBLoad(showtime());