diff options
author | trapezoid | 2009-06-11 16:54:50 +0000 |
---|---|---|
committer | trapezoid | 2009-06-11 16:54:50 +0000 |
commit | 57664cc7a533f051d6815255cfc04727cf20a609 (patch) | |
tree | 8ea3162b769e7e8edc2b42bb0b1dc99e682cbe63 | |
parent | a676aa169fdd07e62cb4d07537b7a687f7847ab1 (diff) | |
download | vimperator-plugins-57664cc7a533f051d6815255cfc04727cf20a609.tar.bz2 |
ldrize_cooperation_fetch_flv.js: insert wait
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@33912 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | ldrize_cooperation_fetch_flv.js | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/ldrize_cooperation_fetch_flv.js b/ldrize_cooperation_fetch_flv.js index 6f1d2f9..e1f520a 100644 --- a/ldrize_cooperation_fetch_flv.js +++ b/ldrize_cooperation_fetch_flv.js @@ -97,6 +97,15 @@ Deferred.next = function (fun) { return d;
};
+Deferred.wait = function (n) {
+ var d = new Deferred(), t = new Date();
+ var id = setTimeout(function () {
+ d.call((new Date).getTime() - t.getTime());
+ }, n * 1000);
+ d.canceller = function () { clearTimeout(id) };
+ return d;
+};
+
function http (opts) {
var d = Deferred();
var req = new XMLHttpRequest();
@@ -199,20 +208,25 @@ function NiconicoFlvHandler(url, title) { liberator.echoerr(e);
});
}
+var count = 0;
function NiconicoMylistHandler(url, title){
let videoId = url.match(/\w{2}\d+/)[0];
- Deferred.http.get(nicoWatchEndPoint + videoId).next(function(watchResult){
- var html = parseHTML(watchResult.responseText, ['img', 'script']);
- Firebug.Console.log(html);
- var csrfToken = getElementsByXPath('//input[@name="csrf_token"]', html)[0].value;
- Firebug.Console.log(csrfToken);
- var mylists = getElementsByXPath('id("mylist_add_group_id")/option', html).map(function(element) [element.innerHTML, element.value]);
- Firebug.Console.log(mylists);
+ Deferred.wait(count++ * 5).next(function(est){
+ return Deferred.http.get(nicoWatchEndPoint + videoId).next(function(watchResult){
+ var html = parseHTML(watchResult.responseText, ['img', 'script']);
+ Firebug.Console.log(html);
+ var csrfToken = getElementsByXPath('//input[@name="csrf_token"]', html)[0].value;
+ Firebug.Console.log(csrfToken);
+ var mylists = getElementsByXPath('id("mylist_add_group_id")/option', html).map(function(element) [element.innerHTML, element.value]);
+ Firebug.Console.log(mylists);
- var params = [['ajax', '1'], ['mylist', 'add'], ['mylist_add', '“o˜^'], ['csrf_token', csrfToken], ['group_id', groupId]].map(function(p) p[0] + "=" + encodeURIComponent(p[1])).join("&");
- return Deferred.http.post(nicoWatchEndPoint + videoId, params).next(function(mylistResult){
- liberator.log(mylistResult.responseText);
+ var params = [['ajax', '1'], ['mylist', 'add'], ['mylist_add', '“o˜^'], ['csrf_token', csrfToken], ['group_id', groupId]].map(function(p) p[0] + "=" + encodeURIComponent(p[1])).join("&");
+ return Deferred.wait(count++ * 5).next(function(est){
+ return Deferred.http.post(nicoWatchEndPoint + videoId, params).next(function(mylistResult){
+ liberator.log(mylistResult.responseText);
+ });
+ });
});
}).error(function(e){
log(e);
|