From 31ed477450f55042d3e88e13b4a44904ac07668b Mon Sep 17 00:00:00 2001 From: trapezoid Date: Thu, 3 Apr 2008 01:59:32 +0000 Subject: lang/javascript/vimperator-plugins/trunk/ldrize_cooperation.js, ldrize_cooperation_fetch_flv.js: add loading plugins future git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@8715 d0d07461-0603-4401-acd4-de1884942a52 --- ldrize_cooperation.js | 9 ++++- ldrize_cooperation_fetch_flv.js | 75 +++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/ldrize_cooperation.js b/ldrize_cooperation.js index 9857f65..6ec7952 100644 --- a/ldrize_cooperation.js +++ b/ldrize_cooperation.js @@ -1,5 +1,5 @@ // Vimperator plugin: 'Cooperation LDRize Mappings' -// Version: 0.13 +// Version: 0.14 // Last Change: 03-Apr-2008. Jan 2008 // License: Creative Commons // Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid @@ -102,6 +102,13 @@ this.initLDRizeCaptureKeys(this.captureMappings); this.initLDRizeCooperationFuture(); this.setupStatusbarPanel(); + + if(liberator.plugins.LDRizeCooperationPlugins != undefined){ + liberator.plugins.LDRizeCooperationPlugins.forEach(function(func){ + func.apply(self,arguments); + }); + delete liberator.plugins.LDRizeCooperationPlugins; + } }, setupStatusbarPanel: function(){ var self = this; diff --git a/ldrize_cooperation_fetch_flv.js b/ldrize_cooperation_fetch_flv.js index ae7a418..9e3c545 100755 --- a/ldrize_cooperation_fetch_flv.js +++ b/ldrize_cooperation_fetch_flv.js @@ -1,58 +1,53 @@ // Vimperator plugin: 'Cooperation LDRize Mappings - Niconico Flv Fetcher' -// Version: 0.1 +// Version: 0.2 // Last Change: 03-Apr-2008. Jan 2008 // License: Creative Commons // Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid // // Cooperation LDRize Mappings - Niconico Flv Fetcher for vimperator0.6.* -// +// Require LDRize Cooperation ver 0.13 (function(){ - function LDRizeCooperationNiconicoFlvFetcher(LDRizeCooperation){ - var NiconicoFlvFetcher = [ - { - pattern: 'http://www.nicovideo.jp/watch/*', - handler: function(url,title){ - const nicoApiEndPoint = "http://www.nicovideo.jp/api/getflv?v="; - const nicoWatchEndPoint = "http://www.nicovideo.jp/watch/"; - var videoId = url.match(/\wm\d+/)[0]; - httpGET(nicoApiEndPoint + videoId,function(apiResult){ - var flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]); + function LDRizeCooperationNiconicoFlvFetcher(){ + var NiconicoFlvFetcher = { + pattern: 'http://www.nicovideo.jp/watch/*', + handler: function(url,title){ + const nicoApiEndPoint = "http://www.nicovideo.jp/api/getflv?v="; + const nicoWatchEndPoint = "http://www.nicovideo.jp/watch/"; + var videoId = url.match(/\wm\d+/)[0]; + httpGET(nicoApiEndPoint + videoId,function(apiResult){ + var flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]); - httpGET(nicoWatchEndPoint + videoId,function(watchPage){ - try{ - var DownloadManager = Cc["@mozilla.org/download-manager;1"] - .getService(Ci.nsIDownloadManager); - var WebBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] - .createInstance(Ci.nsIWebBrowserPersist); + httpGET(nicoWatchEndPoint + videoId,function(watchPage){ + try{ + var DownloadManager = Cc["@mozilla.org/download-manager;1"] + .getService(Ci.nsIDownloadManager); + var WebBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] + .createInstance(Ci.nsIWebBrowserPersist); - var sourceUri = makeURI(flvUrl,null,null); - var file = DownloadManager.userDownloadsDirectory; - file.appendRelativePath(title + ".flv"); - var fileUri = makeFileURI(file); + var sourceUri = makeURI(flvUrl,null,null); + var file = DownloadManager.userDownloadsDirectory; + file.appendRelativePath(title + ".flv"); + var fileUri = makeFileURI(file); - var download = DownloadManager.addDownload(0, sourceUri, fileUri, title + ".flv", - null, null, null, null, WebBrowserPersist); - WebBrowserPersist.progressListener = download; - WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file); - }catch(e){log(e);liberator.echoerr(e)} - }); + var download = DownloadManager.addDownload(0, sourceUri, fileUri, title + ".flv", + null, null, null, null, WebBrowserPersist); + WebBrowserPersist.progressListener = download; + WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file); + }catch(e){log(e);liberator.echoerr(e)} }); - }, - wait: 5000 - } - ] - LDRizeCooperation.convertHandlerInfo(NiconicoFlvFetcher); - LDRizeCooperation.handlerInfo.unshift(NiconicoFlvFetcher[0]); + }); + }, + wait: 5000 + } + this.convertHandlerInfo([NiconicoFlvFetcher]); + this.handlerInfo.unshift(NiconicoFlvFetcher); } if(liberator.plugins.LDRizeCooperation == undefined){ - liberator.plugins.watch('LDRizeCooperation',function(id,oldValue,newValue){ - liberator.plugins.unwatch('LDRizeCooperation'); - LDRizeCooperationNiconicoFlvFetcher(newValue); - return newValue; - }); + liberator.plugins.LDRizeCooperationPlugins = liberator.plugins.LDRizeCooperationPlugins || []; + liberator.plugins.LDRizeCooperationPlugins.push(LDRizeCooperationNiconicoFlvFetcher); }else{ - LDRizeCooperationNiconicoFlvFetcher(liberator.plugins.LDRizeCooperation); + LDRizeCooperationNiconicoFlvFetcher.apply(liberator.plugins.LDRizeCooperation); } function httpGET(uri,callback){ -- cgit v1.2.3