From ab7c43f21078380f055296b7403b4cccc7a2cd59 Mon Sep 17 00:00:00 2001 From: mitsugu oyama Date: Sun, 31 Oct 2010 20:13:18 +0900 Subject: add pixiv.js --- pixiv.js | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 pixiv.js (limited to 'pixiv.js') diff --git a/pixiv.js b/pixiv.js new file mode 100644 index 0000000..12ec7d5 --- /dev/null +++ b/pixiv.js @@ -0,0 +1,164 @@ +// INFO // +var INFO = + + Mitsugu Oyama + MIT + +

+ You can save image from pixiv by this plugin. +

+ + 'pixiv' + :pixiv + +

You can save image from pixiv by this plugin.

+

You must login pixiv.

+
+
+
; + +commands.addUserCommand( + ['pixiv'], + 'Save Image File from pixiv', + function(){ + let contents=gBrowser.selectedBrowser.contentDocument; + if(contents.domain!="www.pixiv.net"){ + liberator.echoerr('This page is not pixiv.'); + return false; + } + if(contents.URL.search(/medium&illust_id=/i)==-1){ + liberator.echoerr("This page is not pixiv's image page."); + return false; + } + + let Cc=Components.classes; + let Ci=Components.interfaces; + const baseInfo="http://www.pixiv.net/member_illust.php?mode=big&illust_id="; + let id=contents.URL.substr(contents.URL.lastIndexOf('=')+1); + let cookie=contents.cookie; + + 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(); + switch(result){ + case Ci.nsIFilePicker.returnOK: + path=fp.file.path; + break; + default: + case Ci.nsIFilePicker.returnCancel: + return ''; + } + return path; + }; + let savePath=directoryPicker(); + if(savePath.length<1) return; + + let getDOMHtmlDocument=function(str){ + let doc; + let range; + try{ + if(document.implementation.createHTMLDocument){ + doc=document.implementation.createHTMLDocument(''); + range=doc.createRange(); + range.selectNodeContents(doc.documentElement); + range.deleteContents(); + doc.documentElement.appendChild(range.createContextualFragment(str)); + }else{ + doc=document.implementation.createDocument(null,'html',null); + range=document.createRange(); + range.selectNodeContents(document.documentElement); + let content=doc.adoptNode(range.createContextualFragment(str)); + doc.documentElement.appendChild(content); + } + }catch(e){ + doc=null; + } + return doc; + }; + + let getImageUrl=function(pageContents){ + let url; + let htmldoc=getDOMHtmlDocument(pageContents); + if(htmldoc){ + if(0