Created
November 11, 2012 04:49
-
-
Save phmongeau/4053756 to your computer and use it in GitHub Desktop.
Disable autoplay userscript
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== | |
// @id com.phmongeau.ytnoauto | |
// @name Youtube NoAuto | |
// @version 1.0 | |
// @namespace com.phmongeau.youtube.noauto | |
// @author Philippe Mongeau | |
// @description | |
// @include *youtube.com/watch?* | |
// @run-at document-start | |
// ==/UserScript== | |
document.addEventListener("DOMNodeInserted", function(e) { | |
if(e.target.tagName == "VIDEO") { | |
function pauseVideo(){ | |
if(e.target.readyState > e.target.HAVE_NOTHING){ | |
e.target.pause(); | |
e.target.currentTime = 0; | |
e.target.paused ? clearInterval(intervalID) : null; | |
} | |
} | |
var intervalID = setInterval(pauseVideo, 100); | |
} | |
}, false); | |
window.addEventListener("load", function() { | |
mplayer = document.getElementById("movie_player"); | |
flash_vars = mplayer ? mplayer.getAttribute("flashvars"): null; | |
if (flash_vars != null) { | |
var m_player = document.getElementById("movie_player"); | |
m_player.setAttribute("flashvars", "autoplay=0&" + flash_vars); | |
m_player.src += "#"; | |
} | |
var matchTime = new RegExp("#t=([0-9].*s)"); | |
var splitTime = new RegExp("[hms]"); | |
var t = matchTime.exec(window.location.href); | |
if (t.length > 1) { | |
var time = 0; | |
var vids = document.getElementsByTagName("video"); | |
var ts = t[1].split(splitTime); | |
ts.pop(); | |
for (var i = 0; i < ts.length; ++i) { | |
time += ts[i] * Math.pow(60, ts.length - i - 1); | |
} | |
for (var i = 0; i < vids.length; ++i) { | |
vids[i].currentTime = time; | |
} | |
} | |
}, false); | |
unsafeWindow.toggle = function() { | |
vid = document.getElementsByTagName("video")[0]; | |
if(vid.paused) { | |
vid.play(); | |
}else { | |
vid.pause(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment