Sort/Remove YouTube Watch Later List

Adds sort and remove button for the Youtube Watch Later page

  1. // ==UserScript==
  2. // @id SortRemoveYouTubeWatchLaterlist
  3. // @namespace https://gf.qytechs.cn/users/42190
  4. // @name Sort/Remove YouTube Watch Later List
  5. // @Author Jus7ForFun
  6. // @version 0.2.2
  7. // @description Adds sort and remove button for the Youtube Watch Later page
  8. // @match https://www.youtube.com/*
  9. // @match http://www.youtube.com/*
  10. // @license GNU GPL v3
  11. // @require https://code.jquery.com/jquery-latest.min.js
  12. // ==/UserScript==
  13.  
  14.  
  15. function waitForKeyElements (
  16. selectorTxt, /* Required: The jQuery selector string that
  17. specifies the desired element(s).
  18. */
  19. actionFunction, /* Required: The code to run when elements are
  20. found. It is passed a jNode to the matched
  21. element.
  22. */
  23. bWaitOnce, /* Optional: If false, will continue to scan for
  24. new elements even after the first match is
  25. found.
  26. */
  27. iframeSelector /* Optional: If set, identifies the iframe to
  28. search.
  29. */
  30. ) {
  31. var targetNodes, btargetsFound;
  32.  
  33. if (typeof iframeSelector == "undefined")
  34. targetNodes = $(selectorTxt);
  35. else
  36. targetNodes = $(iframeSelector).contents ()
  37. .find (selectorTxt);
  38.  
  39. if (targetNodes && targetNodes.length > 0) {
  40. btargetsFound = true;
  41. /*--- Found target node(s). Go through each and act if they
  42. are new.
  43. */
  44. targetNodes.each ( function () {
  45. var jThis = $(this);
  46. var alreadyFound = jThis.data ('alreadyFound') || false;
  47.  
  48. if (!alreadyFound) {
  49. //--- Call the payload function.
  50. var cancelFound = actionFunction (jThis);
  51. if (cancelFound)
  52. btargetsFound = false;
  53. else
  54. jThis.data ('alreadyFound', true);
  55. }
  56. } );
  57. }
  58. else {
  59. btargetsFound = false;
  60. }
  61.  
  62. //--- Get the timer-control variable for this selector.
  63. var controlObj = waitForKeyElements.controlObj || {};
  64. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  65. var timeControl = controlObj [controlKey];
  66.  
  67. //--- Now set or clear the timer as appropriate.
  68. if (btargetsFound && bWaitOnce && timeControl) {
  69. //--- The only condition where we need to clear the timer.
  70. clearInterval (timeControl);
  71. delete controlObj [controlKey];
  72. }
  73. else {
  74. //--- Set a timer, if needed.
  75. if ( ! timeControl) {
  76. timeControl = setInterval ( function () {
  77. waitForKeyElements ( selectorTxt,
  78. actionFunction,
  79. bWaitOnce,
  80. iframeSelector
  81. );
  82. },
  83. 300
  84. );
  85. controlObj [controlKey] = timeControl;
  86. }
  87. }
  88. waitForKeyElements.controlObj = controlObj;
  89. }
  90.  
  91. waitForKeyElements ("#pl-video-table", SortButton);
  92.  
  93. waitForKeyElements(".playlist-actions", RemoveButton);
  94.  
  95.  
  96. function qselector(query, context) {
  97. return (context || document).querySelector(query);
  98. }
  99.  
  100. function MakeButton(text, action) {
  101. var btn = document.createElement('button');
  102. btn.className = 'yt-uix-button yt-uix-button-size-default yt-uix-button-default';
  103. btn.innerHTML = '<span class="yt-uix-button-content">' + text + '</span>';
  104. btn.addEventListener('click', action, false);
  105. qselector('.playlist-actions').appendChild(btn);
  106. }
  107.  
  108.  
  109. function RemoveButton () {
  110. MakeButton ('Clear The List', function(evt) {
  111. Removelist ();
  112. });
  113. }
  114.  
  115.  
  116. function SortButton () {
  117. MakeButton ('Sort Alphabetically', function(evt) {
  118. SortList ();
  119. });
  120. }
  121.  
  122.  
  123. function Removelist(){
  124. var el = document.getElementsByClassName('pl-video-edit-remove');
  125. if (el.length > 0) {
  126. el[el.length-1].click();
  127. setTimeout(Removelist,200);
  128. }
  129. }
  130.  
  131. function SortList () {
  132. $('html, body').css('display', 'none');
  133. var WatchLaterListRows = [],
  134. SortedList = '';
  135. $('#pl-video-table > tbody > tr').each(function() {
  136. var video = $(this);
  137. WatchLaterListRows.push(video[0]);
  138. video.remove();
  139. });
  140. var Sorted = $.makeArray(WatchLaterListRows).sort(function(a,b){
  141. return ( $(a).attr('data-title') < $(b).attr('data-title') ) ? -1 : 1;
  142. });
  143. $.each(Sorted, function(index, video) {
  144. SortedList += video.outerHTML;
  145. });
  146. $('#pl-load-more-destination').append(SortedList);
  147. $('html, body').css('display', 'block');
  148. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址