YouTube - load more all

Adds a button to auto load all videos - in essence it repeatedly clicks "Load more" button.

目前为 2015-08-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - load more all
  3. // @namespace monnef.tk
  4. // @description Adds a button to auto load all videos - in essence it repeatedly clicks "Load more" button.
  5. // @include https://www.youtube.com/*
  6. // @version 1
  7. // @grant none
  8. // @require http://cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. var myClass = "load-more-all";
  12. var clickDelay = 1000;
  13. var debug = false;
  14.  
  15. this.$ = this.jQuery = jQuery.noConflict(true);
  16.  
  17. function log(msg){
  18. if(debug){
  19. console.log("[LoadMoreAll]: " + msg);
  20. }
  21. }
  22.  
  23. function getLoadMoreButton() {
  24. return $(".load-more-button");
  25. }
  26.  
  27. function clickOnLoadMore() {
  28. getLoadMoreButton().each(function() {
  29. var e = $(this);
  30. var click = document.createEvent("MouseEvents");
  31. click.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  32. this.dispatchEvent(click);
  33. });
  34. }
  35.  
  36. function isLoading() {
  37. return getLoadMoreButton().hasClass("yt-uix-load-more-loading");
  38. }
  39.  
  40. function tryClickAndReschedule() {
  41. if (getLoadMoreButton().length > 0) {
  42. if (!isLoading()) {
  43. log("Clicking.");
  44. clickOnLoadMore();
  45. } else {
  46. log("Still loading, skipping click.");
  47. }
  48. setTimeout(tryClickAndReschedule, clickDelay);
  49. } else {
  50. log("Ending auto-clicking, button not found.")
  51. }
  52. }
  53.  
  54. function startClicking() {
  55. log(getLoadMoreButton().attr("class"));
  56. tryClickAndReschedule();
  57. }
  58.  
  59. function insertButton() {
  60. getLoadMoreButton().each(function() {
  61. var e = $(this);
  62. var button = $("<button/>")
  63. .addClass(myClass)
  64. .addClass("yt-uix-button")
  65. .addClass("yt-uix-button-default")
  66. .css("font-weight", "bolder")
  67. .css("display", "block")
  68. .css("margin", "1rem auto")
  69. .text("Load ALL")
  70. .click(function() {
  71. $("." + myClass).remove();
  72. startClicking()
  73. });
  74. e.after(button);
  75. });
  76. }
  77.  
  78. insertButton();