🏠 Home 

Infinite scroll for YouTube

Implementation infinite scroll at youtube.com's search r###lt page.


Install this script?
  1. // ==UserScript==
  2. // @name Infinite scroll for YouTube
  3. // @name:ja YouTubeで無限スクロール
  4. // @namespace https://twitter.com/sititou70
  5. // @description Implementation infinite scroll at youtube.com's search r###lt page.
  6. // @description:ja YouTube.comの検索結果で無限スクロールを実現します。
  7. // @include /https*:\/\/www\.youtube\.com\/.*/
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js
  9. // @version 1.1
  10. // @grant none
  11. // ==/UserScript==
  12. jQuery.noConflict();
  13. (function($){
  14. //exclude iframe document
  15. if ($("html").attr("lang") === "")return;
  16. //get scroll value
  17. var get_scroll_value = function(){
  18. return $(window).scrollTop();
  19. };
  20. //get and set next page
  21. var get_next_page = function(){
  22. if(now_loading)return;
  23. if(next_page_url == "last_page" || next_page_url == "undefined")return;
  24. now_loading = true;
  25. $(r###lt_list_selector).append("<div style='text-align: center;' id='infinite_scroll_for_youyube_loading_massage'>loading next page...</div>");
  26. $.ajax({
  27. type: "GET",
  28. url: next_page_url,
  29. dataType: "html",
  30. }).done(function(res){
  31. now_loading = false;
  32. $(r###lt_list_selector).append($(res).find(r###lt_list_selector + " > li"));
  33. $("#infinite_scroll_for_youyube_loading_massage").remove();
  34. next_page_url = get_next_page_url($(res));
  35. if(next_page_url == "last_page"){
  36. $(r###lt_list_selector).append("<div style='text-align: center;' id='infinite_scroll_for_youyube_loading_massage'>loaded last page</div>");
  37. }
  38. }).fail(function(){
  39. console.log("fail ajax");
  40. });
  41. };
  42. //get next page url from page dom jquery object
  43. var get_next_page_url = function(dom){
  44. var url = dom.find(".branded-page-box > a").last().attr("href");
  45. if(typeof url == "undefined")return "undefined";
  46. if(url == next_page_url)return "last_page";
  47. return url;
  48. };
  49. //it is called when the scrolls
  50. $(window).scroll(function(){
  51. if(next_page_url == "undefined")next_page_url = get_next_page_url($("html"));
  52. if($(".branded-page-box").offset().top - $(window).height() < get_scroll_value() + adjust_scroll_px){
  53. get_next_page();
  54. }
  55. });
  56. var now_loading = false;
  57. var next_page_url = get_next_page_url($("html"));
  58. var r###lt_list_selector = "#r###lts > ol > li:nth-child(2) > ol";
  59. var adjust_scroll_px = 300;
  60. })(jQuery);