diff options
author | mitsugu oyama | 2011-06-29 11:13:32 +0900 |
---|---|---|
committer | mitsugu oyama | 2011-06-29 11:13:32 +0900 |
commit | 493641f0e1032f5d11c7bd4ed69069e52fbf12ef (patch) | |
tree | 1706c02ec0beba657deb4c47d6dc3c94d49804b1 /simg.js | |
parent | 2854dcd4dc995ae282c7b1c809d8167ad57a1708 (diff) | |
download | vimperator-plugins-493641f0e1032f5d11c7bd4ed69069e52fbf12ef.tar.bz2 |
overwrite the image file?
Diffstat (limited to 'simg.js')
-rw-r--r-- | simg.js | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1,6 +1,6 @@ // INFO // var INFO = -<plugin name="simg.js" version="0.2" +<plugin name="simg.js" version="0.3" summary="Save image on contents area" href="http://github.com/vimpr/vimperator-plugins/blob/master/simg.js" xmlns="http://vimperator.org/namespaces/liberator"> @@ -45,19 +45,29 @@ commands.addUserCommand( return path; }; - let savePath=directoryPicker(); - if(savePath.length<1) return; + let saveDirectory=directoryPicker(); + if(saveDirectory.length<1) return; let imgURL=contents.URL; + let savePath; let trueCurrntImg=function(){ let fileName=imgURL.substr(imgURL.lastIndexOf('/')); if (-1!=fileName.indexOf('?')){ fileName=fileName.substr(0,fileName.indexOf('?')); } - savePath=savePath+fileName; + savePath=saveDirectory+fileName; let instream=xhrImg.responseText; let aFile=Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); aFile.initWithPath(savePath); + if(true===aFile.exists()){ + let value=window.prompt('すでに同じ名前のファイルがあります。デフォルトファイル名を変更してください。',fileName.substr(1)); + if(null===value){ + return false; + } + fileName='/'+value; + savePath=saveDirectory+fileName; + aFile.initWithPath(savePath); + } let outstream=Cc["@mozilla.org/network/safe-file-output-stream;1"] .createInstance(Ci.nsIFileOutputStream); outstream.init(aFile,0x02|0x08|0x20,0664,0); |