Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         youtube time rewind
  3. // @version      1.0
  4. // @description  s키로 시간을 저장하고 r로 되돌립니다
  5. // @match        https://www.youtube.com/watch?*
  6. // ==/UserScript==
  7.  
  8. function toSecond(hms) {
  9.     var p = hms.split(':'),
  10.         s = 0, m = 1;
  11.  
  12.     while (p.length > 0) {
  13.         s += m * parseInt(p.pop(), 10);
  14.         m *= 60;
  15.     }
  16.  
  17.     return s;
  18. }
  19.  
  20. (function() {
  21.     let savetime=0
  22.     window.getKey = function (keyStroke){
  23.         if ((event.srcElement.tagName != 'INPUT') && (event.srcElement.tagName != 'TEXTAREA')) {
  24.             isNetscape = (document.layers);
  25.             eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
  26.             which = String.fromCharCode(eventChooser).toLowerCase();
  27.             control(which);
  28.         }
  29.     };
  30.     document.onkeypress = getKey;
  31.  
  32.     window.control = function (key){
  33.         switch(key){
  34.             case 's':
  35.                 console.log('time saved')
  36.                 savetime=toSecond(document.querySelector('span.ytp-time-current').textContent)
  37.                 console.log(savetime)
  38.                 break
  39.             case 'r':
  40.                 console.log('time rewind')
  41.                 let originUrl=location.href
  42.                 let rewindUrl
  43.  
  44.                 if(originUrl.includes('t=')){
  45.                     originUrl=originUrl.split('&')[0]
  46.                 }
  47.                 rewindUrl=originUrl+'&t='+savetime
  48.                 location.href=rewindUrl
  49.         }
  50.     };
  51. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement