Youtube toggle comments

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

当前为 2014-12-07 提交的版本,查看 最新版本

  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.20141207213652
  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 toggleDiv = document.createElement("div");
  23.  
  24. toggleDiv.style.textAlign = "center";
  25. toggleDiv.innerHTML = "<input id='toggleBtn' value='Show Comments' type='submit'>";
  26.  
  27. comments.parentNode.insertBefore(toggleDiv, comments);
  28. comments.style.display = "none";
  29.  
  30. var toggleBtn = document.getElementById("toggleBtn")
  31. toggleBtn.onclick = function()
  32. {
  33. if (comments.style.display !== "none")
  34. {
  35. comments.style.display = "none";
  36. toggleBtn.value = "Show Comments";
  37. }
  38. else
  39. {
  40. comments.style.display = "";
  41. toggleBtn.value = "Hide Comments";
  42. }
  43. }
  44. }
  45. });
  46. });
  47.  
  48. observer.observe(document.getElementById("distiller-spinner"), { attributes: true });