aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormitsugu oyama2011-06-29 11:13:32 +0900
committermitsugu oyama2011-06-29 11:13:32 +0900
commit493641f0e1032f5d11c7bd4ed69069e52fbf12ef (patch)
tree1706c02ec0beba657deb4c47d6dc3c94d49804b1
parent2854dcd4dc995ae282c7b1c809d8167ad57a1708 (diff)
downloadvimperator-plugins-493641f0e1032f5d11c7bd4ed69069e52fbf12ef.tar.bz2
overwrite the image file?
-rw-r--r--simg.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/simg.js b/simg.js
index 0cb78ee..8100db0 100644
--- a/simg.js
+++ b/simg.js
@@ -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);