Last active
August 29, 2015 14:17
-
-
Save Yonezpt/0707dc296232a5dcd1c5 to your computer and use it in GitHub Desktop.
Force playlist autoplay for YouTube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @version 1.0.6 | |
// @name Force playlist autoplay for YouTube | |
// @match *://www.youtube.com/* | |
// @run-at document-start | |
// @grant none | |
// @noframes | |
// ==/UserScript== | |
(function ytapl() { | |
'use strict'; | |
var injection; | |
if (document.querySelector('[name="html5player/html5player"]')) { | |
window.location.reload(false); | |
} else if (!document.getElementById('ytapl')) { | |
injection = document.createElement('script'); | |
injection.id = 'ytapl'; | |
injection.textContent = '(' + ytapl + '())'; | |
document.documentElement.appendChild(injection); | |
return; | |
} | |
function playerReady(api) { | |
function playerState(state) { | |
var progress = document.getElementsByClassName('ytp-time-current')[0].textContent, | |
total = document.getElementsByClassName('ytp-time-duration')[0].textContent; | |
if (state === 0 && progress !== '0:00' && progress === total) { | |
api.nextVideo(); | |
} | |
} | |
if (typeof api === 'object' && !document.getElementById('c4-player')) { | |
api.addEventListener('onStateChange', playerState, false); | |
} | |
} | |
window.onYouTubePlayerReady = playerReady; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment