Changeset 8555
- Timestamp:
- 03/31/08 12:30:36 (8 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/ldrize_cooperation.js
r8532 r8555 1 1 // Vimperator plugin: 'Cooperation LDRize Mappings' 2 // Version: 0.1 03 // Last Change: 3 0-Mar-2008. Jan 20082 // Version: 0.11 3 // Last Change: 31-Mar-2008. Jan 2008 4 4 // License: Creative Commons 5 5 // Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid 6 6 // 7 7 // Cooperation LDRize Mappings for vimperator0.6.* 8 // 9 // Mappings: 10 // replace for captureMapppings 11 // default: 'j','k','p','o' 12 // Commands: 13 // 'm' or 'mb' or 'minibuffer': 14 // Execute args as Minibuffer Command 15 // usage: :minibuffer pinned-link | open | clear-pin 16 // 'pin': 17 // View pinned link list 18 // usage: :pin 19 // 'pindownload': 20 // Download View pinned link by handler function or outer promgram. please see 'handlerInfo' also 21 // usage: :pindownload 22 // 'ldrc' or 'toggleldrizecooperation': 23 // Toggle LDRize Cooperation 24 // usage: :toggleldrizecooperation 25 // Options: 26 // 'ldrc' 27 // Enable LDRize Cooperation 28 // usage: :set ldrc 29 // 'noldrc' 30 // Disable LDRize Cooperation 31 // usage: :set noldrc 8 32 (function(){ 9 var scrollCount = 3;33 var captureMappings = ['j','k','p','o']; 10 34 //pattern: wildcard 11 35 //include: [regexp, option] or regexp … … 17 41 // wait: 5000 18 42 //}, 43 //Niconico Downloader 44 { 45 pattern: 'http://www.nicovideo.jp/watch/*', 46 handler: function(url,title){ 47 const nicoApiEndPoint = "http://www.nicovideo.jp/api/getflv?v="; 48 const nicoWatchEndPoint = "http://www.nicovideo.jp/watch/"; 49 plugins.title = title; 50 var videoId = url.match(/\wm\d+/)[0]; 51 httpGET(nicoApiEndPoint + videoId,function(apiResult){ 52 var flvUrl = decodeURIComponent(apiResult.match(/url=(.*?)&/)[1]); 53 54 httpGET(nicoWatchEndPoint + videoId,function(watchPage){ 55 try{ 56 var DownloadManager = Cc["@mozilla.org/download-manager;1"] 57 .getService(Ci.nsIDownloadManager); 58 var WebBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] 59 .createInstance(Ci.nsIWebBrowserPersist); 60 61 var sourceUri = makeURI(flvUrl,null,null); 62 var file = DownloadManager.userDownloadsDirectory; 63 file.appendRelativePath(title + ".flv"); 64 var fileUri = makeFileURI(file); 65 66 var download = DownloadManager.addDownload(0, sourceUri, fileUri, title + ".flv", 67 null, null, null, null, WebBrowserPersist); 68 WebBrowserPersist.progressListener = download; 69 WebBrowserPersist.saveURI(sourceUri, null, null, null, null, file); 70 }catch(e){log(e);liberator.echoerr(e)} 71 }); 72 }); 73 }, 74 wait: 5000 75 }, 19 76 //{ 20 77 // handler: ['C:\\usr\\irvine\\irvine.exe',['%URL%']], 21 78 //}, 22 79 ]; 23 var captureMappings = ['j','k','p','o'];24 80 25 81 handlerInfo.forEach(function(x){ … … 115 171 function getPinnedItems(){ 116 172 var linkXpath = LDRize.getSiteinfo()['link']; 117 var viewXpath = LDRize.getSiteinfo()['view'] ;118 return LDRize.getPinnedItems().map(function(i){return [i.XPath(linkXpath),i.XPath(viewXpath) ]});173 var viewXpath = LDRize.getSiteinfo()['view'] || linkXpath + "/text()"; 174 return LDRize.getPinnedItems().map(function(i){return [i.XPath(linkXpath),i.XPath(viewXpath).textContent]}); 119 175 } 120 176 function downloadLinksByProgram(links){ 121 177 var count = 0; 122 links.forEach(function([ link,title]){178 links.forEach(function([url,title]){ 123 179 for each(let x in handlerInfo){ 124 if(x.include.test( link)){180 if(x.include.test(url)){ 125 181 setTimeout(function(){ 126 182 if(typeof x.handler == "object"){ 127 var args = x.handler[1].map(function(s){ return s.replace(/%URL%/g, link).replace(/%TITLE%/g,title); });183 var args = x.handler[1].map(function(s){ return s.replace(/%URL%/g,url).replace(/%TITLE%/g,title); }); 128 184 liberator.io.run(x.handler[0],args,false); 129 185 }else if(typeof x.handler == "string"){ 130 liberator.io.run(x.handler,[ link],false);186 liberator.io.run(x.handler,[url],false); 131 187 }else if(typeof x.handler == "function"){ 132 x.handler( link,title);188 x.handler(url.toString(),title); 133 189 } 134 190 },x.wait != undefined ? x.wait * count++ : 0); … … 138 194 liberator.echoerr("LDRize Cooperation: download pattern not found!!"); 139 195 }); 196 } 197 198 function httpGET(uri,callback){ 199 var xhr = new XMLHttpRequest(); 200 xhr.onreadystatechange = function(){ 201 if(xhr.readyState == 4){ 202 if(xhr.status == 200) 203 callback.call(this,xhr.responseText); 204 else 205 throw new Error(xhr.statusText) 206 } 207 }; 208 xhr.open("GET",uri,true); 209 xhr.send(null); 140 210 } 141 211
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)