Created
October 1, 2012 13:23
-
-
Save KensakuKOMATSU/3811774 to your computer and use it in GitHub Desktop.
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
var xhr = new XMLHttpRequest(); | |
xhr.open("get", "http://m.youtube.com/watch?ajax=1&layout=mobile&tsp=1&utcoffset=540&v=Dbydyibcfi8&preq="); | |
// xhr.setRequestHeader("User-Agent", "Mozilla/5.0(iPad; U; CPU OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5") | |
xhr.onload = function(e) { | |
console.log(JSON.parse(e.target.responseText.slice(4)).content.video.fmt_stream_map[1].url); | |
// window.open(JSON.parse(e.target.responseText.slice(4)).content.video.fmt_stream_map[1].url); | |
} | |
xhr.send(); | |
/* | |
// http://developer.chrome.com/extensions/webRequest.html | |
var UA = null; | |
var description = null; | |
var requestFilter = { | |
urls: ["<all_urls>"] | |
}, | |
extraInfoSpec = ['requestHeaders', 'blocking'], | |
handler = function (details) { | |
if (UA == null) { | |
return; | |
} | |
var headers = details.requestHeaders, | |
blockingResponse = {}; | |
for (var i = 0, l = headers.length; i < l; ++i) { | |
if (headers[i].name == 'User-Agent') { | |
headers[i].value = UA; | |
break; | |
} | |
} | |
blockingResponse.requestHeaders = headers; | |
return blockingResponse; | |
}; | |
chrome.webRequest.onBeforeSendHeaders.addListener(handler, requestFilter, extraInfoSpec); | |
// called from the popup | |
function setUA(ua, desc) { | |
UA = ua; | |
description = desc; | |
} | |
function clearUA() { | |
UA = null; | |
description = null; | |
} | |
function getUA() { | |
return UA; | |
} | |
function getDescription() { | |
return description; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment