| 1 | var ucjsAgesageFlvDownloader = { |
|---|
| 2 | download: function(title, xml){ |
|---|
| 3 | var req = new XMLHttpRequest(); |
|---|
| 4 | req.onreadystatechange = function() { |
|---|
| 5 | if (req.readyState != 4) { |
|---|
| 6 | return; |
|---|
| 7 | } |
|---|
| 8 | if (req.status != 200) { |
|---|
| 9 | alert(req.status + " " + req.statusText); |
|---|
| 10 | return; |
|---|
| 11 | } |
|---|
| 12 | var location = req.responseXML.getElementsByTagName('movieurl')[0].textContent; |
|---|
| 13 | ucjsAgesageFlvDownloader.saveFLV(title, location); |
|---|
| 14 | }; |
|---|
| 15 | req.open('GET', xml, true); |
|---|
| 16 | req.send(''); |
|---|
| 17 | }, |
|---|
| 18 | |
|---|
| 19 | saveFLV: function(aTitle, aFlvURLSpec){ |
|---|
| 20 | const FLV_EXTENSION = "flv"; |
|---|
| 21 | var FLV_CONTENT_TYPE = "video/flv"; |
|---|
| 22 | |
|---|
| 23 | var flvName = aTitle + "." + FLV_EXTENSION; |
|---|
| 24 | |
|---|
| 25 | var flvURL = Components.classes["@mozilla.org/network/io-service;1"] |
|---|
| 26 | .getService(Components.interfaces.nsIIOService) |
|---|
| 27 | .newURI(aFlvURLSpec, null, null) |
|---|
| 28 | .QueryInterface(Components.interfaces.nsIURL); |
|---|
| 29 | var fileInfo = new FileInfo(flvName, flvName, aTitle, FLV_EXTENSION, flvURL); |
|---|
| 30 | |
|---|
| 31 | var fpParams = { |
|---|
| 32 | fpTitleKey: "", |
|---|
| 33 | isDocument: false, |
|---|
| 34 | fileInfo: fileInfo, |
|---|
| 35 | contentType: FLV_CONTENT_TYPE, |
|---|
| 36 | saveMode: GetSaveModeForContentType(FLV_CONTENT_TYPE), |
|---|
| 37 | saveAsType: 0, |
|---|
| 38 | file: null, |
|---|
| 39 | fileURL: null |
|---|
| 40 | }; |
|---|
| 41 | if(!getTargetFile(fpParams, true)){ |
|---|
| 42 | return; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | var fileURL = fpParams.fileURL || makeFileURI(fpParams.file); |
|---|
| 46 | |
|---|
| 47 | var persist = makeWebBrowserPersist(); |
|---|
| 48 | persist.persistFlags = Components.interfaces.nsIWebBrowserPersist |
|---|
| 49 | .PERSIST_FLAGS_REPLACE_EXISTING_FILES; |
|---|
| 50 | var transfer = Components.classes["@mozilla.org/transfer;1"] |
|---|
| 51 | .createInstance(Components.interfaces.nsITransfer); |
|---|
| 52 | transfer.init(fileInfo.uri, fileURL, "", null, null, null, persist); |
|---|
| 53 | persist.progressListener = transfer; |
|---|
| 54 | persist.saveURI(fileInfo.uri, null, null, null, null, fileURL); |
|---|
| 55 | } |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | (function(){ |
|---|
| 59 | var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); |
|---|
| 60 | var menuItem = document.createElement("menuitem"); |
|---|
| 61 | menuItem.setAttribute("label", "Download FLV"); |
|---|
| 62 | contentAreaContextMenu.appendChild(menuItem); |
|---|
| 63 | contentAreaContextMenu.addEventListener |
|---|
| 64 | ("popupshowing", |
|---|
| 65 | function() { |
|---|
| 66 | menuItem.hidden = true; |
|---|
| 67 | if(gContextMenu.target.id != "bookmarktitle") return; |
|---|
| 68 | var location = gContextMenu.target.ownerDocument.location; |
|---|
| 69 | if(location.host.indexOf("agesage.jp") < 0) return; |
|---|
| 70 | var xml = location.href.replace(/\.ht(?=ml\?)/, '.x'); |
|---|
| 71 | var title = gContextMenu.target.textContent; |
|---|
| 72 | menuItem.setAttribute("oncommand", "ucjsAgesageFlvDownloader.download('"+ title +"','"+ xml +"')"); |
|---|
| 73 | menuItem.hidden = false; |
|---|
| 74 | }, |
|---|
| 75 | false); |
|---|
| 76 | })(); |
|---|