YouTube With No JavaScript

By pwlin Last update Jan 26, 2012 — Installed 2,419 times.

There are 16 previous versions of this script.

// ==UserScript==
// @name     YouTube With No JavaScript
// @version	0.2.13
// @description This hack will eliminate the need of Javascript for playing clips on YouTube site. (Handy if you have NoScript extension on) 
// @namespace     http://userscripts.org/scripts/show/21900
// @include    http://youtube.com/*
// @include    http://www.youtube.com/*
// @include    https://youtube.com/*
// @include    https://www.youtube.com/*
// ==/UserScript==

function $(id,doc){ if (!doc || doc == '') {doc = document ; } return doc.getElementById(id); }
function $xpath(q,doc) { if (!doc || doc == '') {doc = document ; } return doc.evaluate(q, doc,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); }
(function(){
	try {
		
		if($('default-language-box')){
			$('default-language-box').style.display = 'none';
		}
		
		if($('watch-description')){
			$('watch-description').setAttribute('class','watch-expander yt-uix-expander yt-uix-expander-animated');
			var watch_expander_body = $xpath('//html//div[@id="watch-description"]//div[@class="watch-expander-body yt-uix-expander-body"]');
			if(watch_expander_body.snapshotItem(0)){
				watch_expander_body.snapshotItem(0).setAttribute('style','overflow: scroll');
			}
		}
		
		if($('watch-player') && $('watch-video')){
			var flash_script = $('watch-video').getElementsByTagName('script');
			if(flash_script && flash_script[1]){
				flash_script = flash_script[1].innerHTML;
				flash_script = flash_script.match(/var swf = "(.*?)[\s\S]+document\./)[0];
				flash_script = flash_script.replace('document.','');
				flash_script = flash_script.replace('var swf = "','');
				flash_script = flash_script.replace(/" \+ "/g,'') ;
				flash_script = flash_script.replace(/\\"/g,'"');
				flash_script = flash_script.replace(/\\\//g,'/');
				flash_script = flash_script.replace(/\\u003c/ig,'<');
				flash_script = flash_script.replace(/\\u003e/ig,'>');
				flash_script = flash_script.replace(/\\u0072/ig,'r');
				flash_script = flash_script.replace(/\\u0069/ig,'i');
				flash_script = flash_script.replace(/\\u0065/ig,'e');
				flash_script = flash_script.replace(/\\u0026/ig,'&');
				flash_script = flash_script.replace(/<\/noembed>";/,'</noembed>');
				$('watch-player').innerHTML = flash_script;
			}
		}	
		
		if($('watch-related')){
			// /watch#!v=3iejdFZr6CY&feature=fvw
			var all_thumbnails_links = $('watch-related').getElementsByTagName('a');
			for (var i = 0 , k = all_thumbnails_links.length; i < k; i++){
				var link = all_thumbnails_links[i];
				if (link.getAttribute('href').match('watch#!v')){
					link.setAttribute('href', link.getAttribute('href').replace(/watch#!v/,'watch?v'));
				}
			}
			
		}
		
		var video_thumbnails = document.getElementsByTagName('img');
		for (var i = 0 , k = video_thumbnails.length; i < k; i++){
			var img = video_thumbnails[i];
			// img.getAttribute('src') == 'http://s.ytimg.com/yt/img/pixel-vfl73.gif'
			if(img.getAttribute('src').match(/pixel-/)){
				var img_thumb = img.getAttribute('data-thumb');
				if(img_thumb){
					img.setAttribute('src', img_thumb);
				}
			}
		}
			
	}
	catch(e){
		// alert(e);
	}
			
})();