Advertisement
congdantoancau

Youtube search keyboard navigation

Sep 13th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.77 KB | None | 0 0
  1. // JAVASCIPT
  2.    
  3. // Manager hotkey
  4.     var i = -1;
  5. $(document).keydown(function(e) {
  6.    
  7.     if (e.which == 38) {
  8.         e.preventDefault();
  9.         var len = $('a[id="video-title"]').length;
  10.         console.log(len);
  11.         if (i > 0) {
  12.             i--;
  13.         }
  14.         console.log(i + " " + len);
  15.         $('a[id="video-title"]')[i].focus();
  16.     }
  17.    
  18.     if (e.which == 40) {
  19.         e.preventDefault();
  20.         var len = $('a[id="video-title"]').length;
  21.         console.log(len);
  22.         if (i < len) {
  23.             i++;
  24.         }
  25.         console.log(i + " " + len);
  26.         $('a[id="video-title"]')[i].focus();
  27.     }
  28.    
  29.     // Media-play/pause key
  30.     if (e.which == 179)
  31.         $('.ytp-play-button').click();
  32. });
  33.  
  34. /**** CSS ****/
  35. #video-title:focus {
  36.     border: 1px solid red;
  37.     color: red!important;
  38.     outline-color: yellow;
  39. }
  40.  
  41.  
  42. #video-title:focus:before {
  43.     content: '► ';
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement