aboutsummaryrefslogtreecommitdiffstats
path: root/pixiv.js
diff options
context:
space:
mode:
authormitsugu oyama2012-12-30 16:20:19 +0900
committermitsugu oyama2012-12-30 16:20:19 +0900
commitc6ffe4e8d3747535e4a2a03d469696001efacc0b (patch)
tree05dce2d064a88c0d72ec6eef79c57b492b306406 /pixiv.js
parent0bd08d43a1334f101a92af0c9c0466f6afef150f (diff)
downloadvimperator-plugins-c6ffe4e8d3747535e4a2a03d469696001efacc0b.tar.bz2
change to open method from show method
Diffstat (limited to 'pixiv.js')
-rw-r--r--pixiv.js81
1 files changed, 43 insertions, 38 deletions
diff --git a/pixiv.js b/pixiv.js
index ba34834..35490bc 100644
--- a/pixiv.js
+++ b/pixiv.js
@@ -43,6 +43,12 @@ commands.addUserCommand(
let cookie=contents.cookie;
// }}}
+ let fp;
+ let url;
+ let type;
+ let saveDirectory;
+ let xhrImgInfo;
+
// {{{ convert to DOM Document from text
let getDOMHtmlDocument=function(str){
let doc;
@@ -163,21 +169,6 @@ commands.addUserCommand(
},false);
// }}}
-// {{{ directory picker
- let directoryPicker=function() {
- let path;
- let fp=Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
- fp.init(window,'Select Directory',Ci.nsIFilePicker.modeGetFolder);
- let result=fp.show();
- if(result==Ci.nsIFilePicker.returnOK){
- return fp.file;
- }
- return null;
- };
- let saveDirectory=directoryPicker();
- if(saveDirectory==null) return false;
-// }}}
-
// {{{ send request save image
let saveImage=function(imgUrl,savePath,referer,cookie){
let objMessage={
@@ -282,19 +273,7 @@ commands.addUserCommand(
};
// }}}
-// {{{ first XMLHttpRequest
- let url;
- let type=contents.getElementsByClassName('works_display')
- .item(0).firstChild.getAttribute('href');
- if(-1!=type.search(/big&illust_id=/i)){
- url=contents.documentURI.replace('medium','big');
- }else if(-1!=type.search(/manga&illust_id=/i)){
- url=contents.documentURI.replace('medium','manga')+'&type=scroll';
- }else{
- liberator.echoerr("This page is not image page and not manga page.");
- return false;
- }
-
+// {{{ trueImgINfo
let trueImgInfo=function(){
if(-1!=type.search(/big&illust_id=/i)){
saveImageFile();
@@ -305,23 +284,49 @@ commands.addUserCommand(
return false;
}
};
+// }}}
+// {{{ falseImgInfo
let falseImgInfo=function(){
liberator.echo("Image Infomation page accept error.");
return false;
};
+// }}}
- let xhrImgInfo;
- xhrImgInfo=Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
- xhrImgInfo.QueryInterface(Ci.nsIDOMEventTarget);
- xhrImgInfo.addEventListener("load",trueImgInfo,false);
- xhrImgInfo.addEventListener("error",falseImgInfo,false);
- xhrImgInfo.QueryInterface(Ci.nsIXMLHttpRequest);
- xhrImgInfo.open("GET",url,true);
- xhrImgInfo.setRequestHeader('Referer',contents.URL);
- xhrImgInfo.setRequestHeader('Cookie',cookie);
- xhrImgInfo.send(null);
+// {{{ fpCallback
+ let fpCallback = {
+ done : function (aResult) {
+ if ( aResult == fp.returnOK ) {
+ saveDirectory = fp.file;
+ xhrImgInfo = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance();
+ xhrImgInfo.QueryInterface( Ci.nsIDOMEventTarget );
+ xhrImgInfo.addEventListener( "load", trueImgInfo, false );
+ xhrImgInfo.addEventListener( "error", falseImgInfo, false );
+ xhrImgInfo.QueryInterface( Ci.nsIXMLHttpRequest );
+ xhrImgInfo.open( "GET", url, true);
+ xhrImgInfo.setRequestHeader( 'Referer', contents.URL );
+ xhrImgInfo.setRequestHeader( 'Cookie', cookie );
+ xhrImgInfo.send( null );
+ }
+ }
+ };
// }}}
+
+ type = contents.getElementsByClassName('works_display')
+ .item(0).firstChild.getAttribute('href');
+ if(-1!=type.search(/big&illust_id=/i)){
+ url=contents.documentURI.replace('medium','big');
+ }else if(-1!=type.search(/manga&illust_id=/i)){
+ url=contents.documentURI.replace('medium','manga')+'&type=scroll';
+ }else{
+ liberator.echoerr("This page is not image page and not manga page.");
+ return false;
+ }
+
+ fp = Cc["@mozilla.org/filepicker;1"].createInstance( Ci.nsIFilePicker );
+ fp.init( window, 'Select Directory', fp.modeGetFolder );
+ let result=fp.open( fpCallback );
},
{},
true