YouTube Stop Loading & Playback

By JoeSimmons Last update Mar 21, 2009 — Installed 994 times.

There are 3 previous versions of this script.

// ==UserScript==
// @name           YouTube Stop Loading & Playback
// @namespace      http://userscripts.org/users/23652
// @description    Click a button to stop the video's loading and playback and click it again to start it over
// @include        http://*.youtube.com/watch?*
// @include        http://youtube.com/watch?*
// @copyright      JoeSimmons
// ==/UserScript==

// OPTIONS /////////////////////////////////////////////////////
// You can change the icon here
var icon = 'http://i40.tinypic.com/xlfccg.gif';
////////////////////////////////////////////////////////////////

function stopplay() {
var state = unsafeWindow._gel('movie_player').getPlayerState();
if(state==-1 || state==0) {
var mp = document.getElementById('movie_player');
mp.parentNode.replaceChild(orig_mp, mp);
}
else if(state==1 || state==2 || state==3 || state==5) {
unsafeWindow._gel('movie_player').stopVideo();
unsafeWindow._gel('movie_player').seekTo(0, false);
}
}

with(document) {
var vid_title = getElementById('watch-vid-title'),
	span = createElement('span'),
	stop_link = createElement('a'),
	stop_img = createElement('img');
	}

// Copy of the original player to be used by the play button
var orig_mp = document.getElementById('movie_player').cloneNode(true);

// Stop image; change this if you want
stop_img.src = icon;
	
stop_link.href = 'javascript:void(0);';
stop_link.setAttribute('id', 'stopplay');
stop_link.addEventListener('click', stopplay, false);

stop_link.appendChild(stop_img);
span.appendChild(stop_link);
span.setAttribute('style', 'font-size: 14px; font-family: Tahoma;');
span.appendChild(document.createTextNode(' '+vid_title.firstChild.nextSibling.textContent));
vid_title.replaceChild(span, vid_title.firstChild.nextSibling);