Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name youtube time rewind
- // @version 1.0
- // @description s키로 시간을 저장하고 r로 되돌립니다
- // @match https://www.youtube.com/watch?*
- // ==/UserScript==
- function toSecond(hms) {
- var p = hms.split(':'),
- s = 0, m = 1;
- while (p.length > 0) {
- s += m * parseInt(p.pop(), 10);
- m *= 60;
- }
- return s;
- }
- (function() {
- let savetime=0
- window.getKey = function (keyStroke){
- if ((event.srcElement.tagName != 'INPUT') && (event.srcElement.tagName != 'TEXTAREA')) {
- isNetscape = (document.layers);
- eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
- which = String.fromCharCode(eventChooser).toLowerCase();
- control(which);
- }
- };
- document.onkeypress = getKey;
- window.control = function (key){
- switch(key){
- case 's':
- console.log('time saved')
- savetime=toSecond(document.querySelector('span.ytp-time-current').textContent)
- console.log(savetime)
- break
- case 'r':
- console.log('time rewind')
- let originUrl=location.href
- let rewindUrl
- if(originUrl.includes('t=')){
- originUrl=originUrl.split('&')[0]
- }
- rewindUrl=originUrl+'&t='+savetime
- location.href=rewindUrl
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement