Youtube toggle comments

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

  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.20150228222421
  12. // @namespace https://greasyfork.org/users/7439
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. var comments = document.getElementById("watch-discussion");
  17. var toggleLoc = document.getElementById("watch8-secondary-actions");
  18. var toggleDiv = document.createElement("div");
  19.  
  20. toggleDiv.style.textAlign = "center";
  21. toggleDiv.innerHTML = "<button id='toggleBtn' class='yt-uix-button yt-uix-button-default'> Show Comments </button>";
  22.  
  23. comments.parentNode.insertBefore(toggleDiv, comments);
  24. comments.style.display = "none";
  25.  
  26. var toggleBtn = document.getElementById("toggleBtn");
  27. toggleBtn.onclick = function() {
  28. if (comments.style.display !== "none") {
  29. comments.style.display = "none";
  30. toggleBtn.innerHTML = "Show Comments";
  31. }
  32. else {
  33. comments.style.display = "";
  34. toggleBtn.innerHTML = "Hide Comments";
  35. }
  36. }
  37. }) ();