congdantoancau

Youtube Upnext Videos Navigator

Sep 22nd, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // *** JAVASCRIPT ***
  2. var i = 0;
  3. var len = 0;
  4.  
  5. $(document).keydown(function (e) {
  6.     // Video queue
  7.     var videos = $('a.yt-simple-endpoint.ytd-compact-video-renderer');
  8.     // Add index to before of videos title
  9.     if (videos.length != len) {
  10.         $('.vid-index').remove();
  11.         len = videos.length;
  12.         for (var j = 0; j < len; j++) {
  13.             videos.eq(j).before('<span class="vid-index"></span>');
  14.             $('.vid-index').eq(j).html(j);
  15.         }
  16.     }
  17.  
  18.     // Declaration of focused element
  19.     var focused = $(':focus');
  20.     var focusedHtml = focused.prevObject[0].activeElement.outerHTML;
  21.     var focusedClass = focused.attr("class");
  22.     var focusedTag = focused.prop("tagName");
  23.  
  24.     var isTextfield = false;
  25.     // If focused tag is defined, distinct is not a textfield
  26.     if (focusedTag) {
  27.         focusedTag = focusedTag.toLowerCase();
  28.         if (
  29.             focusedTag.indexOf("input") >= 0 ||
  30.             focusedClass.indexOf("input") >= 0 ||
  31.             focusedHtml.indexOf("input") >= 0 && focusedTag != "div"
  32.         ) isTextfield = true;
  33.     }
  34.  
  35.  
  36.     // Up key
  37.     if (e.which == 38 && !isTextfield) {
  38.         e.preventDefault();
  39.         if (i > 0) i--;
  40.         videos.eq(i).focus();
  41.     }
  42.     // Down key
  43.     if (e.which == 40 && !isTextfield) {
  44.         e.preventDefault();
  45.         if (i < len - 1) i++;
  46.         videos.eq(i).focus();
  47.     }
  48.  
  49.     // Media-play/pause key
  50.     if (e.which == 179)
  51.         $('.ytp-play-button').click();
  52. });
  53.  
  54.  
  55.  
  56.  
  57. /*** CSS STYLE ***/
  58. a.yt-simple-endpoint.ytd-compact-video-renderer:focus:before {
  59.     content: 'Press [Enter] to play ►';
  60. }
  61.  
  62. a.yt-simple-endpoint.ytd-compact-video-renderer:focus {
  63.     color: red;
  64.     /*border: 1px solid red;*/
  65.     /*background: rbga(120,120,120,0.5);*/
  66. }
  67.  
  68. .vid-index {
  69.     margin-right: 5px;
  70. }
Add Comment
Please, Sign In to add comment