Created
January 17, 2011 09:13
-
-
Save ynkdir/782642 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
(function(){ | |
var http_get = function(url) { | |
var async = false; | |
var req = new XMLHttpRequest(); | |
req.open("GET", url, async); | |
req.withCredentials = true; | |
req.send(); | |
return req.responseText; | |
}; | |
var http_post = function(url, params) { | |
var async = false; | |
var req = new XMLHttpRequest(); | |
req.open("POST", url, async); | |
req.withCredentials = true; | |
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
req.send(params); | |
return req.responseText; | |
}; | |
var encode_params = function(params) { | |
var s = ""; | |
for (var key in params) { | |
if (s != "") { | |
s += "&"; | |
} | |
s += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]); | |
} | |
return s; | |
}; | |
var decode_params = function(params) { | |
var o = {}; | |
var a = params.split("&"); | |
for (var i = 0; i < a.length; i++) { | |
var b = a[i].split("="); | |
var key = decodeURIComponent(b[0]); | |
var value = decodeURIComponent(b[1]); | |
o[key] = value; | |
} | |
return o; | |
}; | |
var download = function(url) { | |
var div = document.createElement("div"); | |
div.innerHTML = '右クリックで保存 <a href="' + url + '">' + url + '</a>'; | |
document.body.insertBefore(div, document.body.firstChild); | |
}; | |
var getflv = function(id) { | |
var url = "http://flapi.nicovideo.jp/api/getflv?v=" + id; | |
var t = http_get(url); | |
var o = decode_params(t); | |
download(o.url); | |
}; | |
getflv(Video.v); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment