Created
November 23, 2009 13:47
-
-
Save azu/241080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//改変元:リンク画像を保存.s.js http://loda.jp/script/?id=203 | |
/* | |
FireGesturesやKeyConfigなどに設定して実行するとページ内のjpegとpngをまとめて | |
zipにしてダウンロードする。 | |
保存場所は決めうちか毎回ダイアログで指定 | |
*/ | |
(function () { | |
// 保存ディレクトリのパスがない場合は毎回ダイアログで決める | |
//var path = "C:\\Users\\azu\\Downloads"; // エスケープしたディレクトリのパス | |
var path = ""; | |
if (!path) { | |
// ファイル保存ダイアログ | |
var nsIFilePicker = Ci.nsIFilePicker; | |
var FP = Cc['@mozilla.org/filepicker;1'].createInstance(nsIFilePicker); | |
FP.init(window, 'Choose save folder.', nsIFilePicker.modeGetFolder); | |
// ダイアログ表示 | |
if (FP.show() == nsIFilePicker.returnOK) { | |
path = FP.file.path; | |
} else { | |
return false; | |
} | |
} | |
// ダウンロードしたページを表示するために URI オブジェクト生成 | |
var hostURL = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService).newURI(location.href, null, null); | |
// ページに貼り付けられた画像を保存する | |
var links = content.document.images; | |
var pack = []; | |
for (var i = 0, length = links.length; i < length; i++) { | |
// JPEG と PNG を保存する | |
if (links[i].src.match(/\.jpe?g|\.png|img\.blogs\.yahoo(.*)folder[^thumb]/i)) { | |
pack.push([links[i].src.split("/").pop(), links[i].src]); | |
} | |
} | |
zipDeKure(pack, path); | |
function zipDeKure(urls, savePath) { | |
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); | |
const zipWriter = Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter"); | |
var uri = content.window.location.href; | |
var fileName = uri.substring(uri.lastIndexOf('://') + 3, uri.length); | |
fileName = fileName.split(".").join("_"); | |
fileName = fileName.split("/").join("_"); | |
fileName = fileName.split("?").join("_"); | |
var path = savePath + "\\" + fileName + ".zip"; | |
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); | |
file.initWithPath(path); | |
var zipW = new zipWriter(); | |
var ioFlag = 0x04 | 0x08 | 0x20; | |
zipW.open(file, ioFlag); | |
for (var i = 0, len = urls.length; i < len; i++) { | |
var[name, url] = urls[i]; | |
var ch = ioService.newChannel(url, "UTF-8", null); | |
var stream = ch.open(); | |
zipW.addEntryStream(name, Date.now() * 1000, Ci.nsIZipWriter.COMPRESS_DEFAULT, stream, false); | |
} | |
zipW.close(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment