Youtube toggle comments

Makes to Youtube comments click to view rather than always showing them or hiding them

当前为 2015-01-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube toggle comments
  3. // @description Makes to Youtube comments click to view rather than always showing them or hiding them
  4. // @author Lewis Aron Milne
  5. // @include http://www.youtube.com/watch*
  6. // @include https://www.youtube.com/watch*
  7. // @include http://youtube.com/watch*
  8. // @include https://youtube.com/watch*
  9. // @run-at document-end
  10. // @grant none
  11. // @version 0.0.1.20150118002420
  12. // @namespace https://greasyfork.org/users/7439
  13. // ==/UserScript==
  14.  
  15. var observer = new MutationObserver(function(mutations) {
  16. var triggerNum = 0;
  17. mutations.forEach(function(mutation) {
  18. triggerNum++;
  19. if (triggerNum <= 1)
  20. {
  21. var comments = document.getElementById("watch-discussion");
  22. var toggleLoc = document.getElementById("watch8-secondary-actions");
  23. var toggleDiv = document.createElement("div");
  24.  
  25. toggleDiv.style.textAlign = "center";
  26. toggleDiv.innerHTML = "<button id='toggleBtn' class='yt-uix-button yt-uix-button-default'> Show Comments </button>";
  27.  
  28. comments.parentNode.insertBefore(toggleDiv, comments);
  29. comments.style.display = "none";
  30.  
  31. var toggleBtn = document.getElementById("toggleBtn")
  32. toggleBtn.onclick = function()
  33. {
  34. if (comments.style.display !== "none")
  35. {
  36. comments.style.display = "none";
  37. toggleBtn.innerHTML = "Show Comments";
  38. }
  39. else
  40. {
  41. comments.style.display = "";
  42. toggleBtn.innerHTML = "Hide Comments";
  43. }
  44. }
  45. }
  46. });
  47. });
  48.  
  49. observer.observe(document.getElementById("distiller-spinner"), { attributes: true });