All pastes #895994 Raw Edit

Stuff

public javascript v1 · immutable
·published 2008-02-08 06:51 UTC
rendered paste body
	var finalLink;	/***Thanks to Sergei Zhirikov for the code ( http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/de9aabb632082e82/2394752ae7cd7126#2394752ae7cd7126 )***/	// accepted HTTP status codes 	var redirect = {300: null, 301: null, 302: null, 303: null, 307: null}; 	var listener = { 	    onStartRequest: function(request, context) {}, 			    onStopRequest: function(request, context, status) { 			        if (status == 0x804B001F) { // NS_ERROR_REDIRECT_LOOP 				            var channel = request.QueryInterface(Components.interfaces.nsIHttpChannel); 					            if (channel.responseStatus in redirect) { 					                var respHead = null; 						                try { 	                    respHead = channel.getResponseHeader('Location'); 	                } 					catch (exc) { 						                    // no 'Location' header sent with the redirect; 						LOG('no Location header sent with the redirect '+exc);							                } 	                if (respHead != null) { 											if(respHead.indexOf('cache.googlevideo.com')>-1){							respHead = respHead.split('&origin=')[1]+'/get_video?video_id='+vidID;																}						if(respHead.indexOf('&signature')>-1){																respHead = respHead.split('&')[0];																embedVID(respHead);													}							                } 	            } 	        } 	    }, 	    onDataAvailable: function(request, context, stream, offset, length) { 			        // abort the request in case we didn't get redirected 			request.cancel(Components.results.NS_ERROR_UNEXPECTED); 				    }, 	    QueryInterface: function(iid) { 			        if (iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsIStreamListener) || iid.equals(Components.interfaces.nsIRequestObserver)) {				            return this; 							}	        else {				            throw Components.results.NS_NOINTERFACE; 							}	    }, 	}; 	var channel = null, context = null; 	try { 			channel = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newChannel(srcWithT, null, null).QueryInterface(Components.interfaces.nsIHttpChannel) 			} 	catch (exc) { 		// something went wrong when creating a channel instance 		LOG('something went wrong when creating a channel instance '+exc);			} 	if (channel) { 			channel.redirectionLimit = 0; 		channel.asyncOpen(listener, context); 			}