火狐浏览器插件下载

发布于 2024-09-16 19:38:07 字数 6341 浏览 6 评论 0原文

我正在尝试创建一个简单的插件,不需要界面,它将自动下载并保存到“桌面/MyFolder/”页面加载的所有内容。我的想法是做一个扩展 FireBug 的扩展,但这似乎相当具有挑战性。我让它做一些事情,但是在图像、flv 和 mp3 等内容上,内容似乎放置在文件中,但是当我尝试查看它们时,它们不是可查看/无效的格式。

我想我只需要做某种 MimeType 或文件格式的事情。看起来确实不错,但显然缺少了一些东西。

提前致谢!

FBL.ns(function() { with (FBL) { 

const Cc = Components.classes;
const Ci = Components.interfaces;

const dirService = Cc["@mozilla.org/file/directory_service;1"]
    .getService(Ci.nsIProperties);

// ************************************************************************************************
// Module implementation

Firebug.EverythingExportModule = extend(Firebug.Module,
{
    initialize: function(owner)
    {
        Firebug.Module.initialize.apply(this, arguments);

        // Register NetMonitor listener
        this.netListener = new EverythingExport();
        Firebug.NetMonitor.addListener(this.netListener);
    },

    shutdown: function()
    {
        Firebug.Module.shutdown.apply(this, arguments);

        // Unregister NetMonitor listener
        Firebug.NetMonitor.removeListener(this.netListener);
        this.netListener.outputStream.close();
    }
});

// ************************************************************************************************
// Net Panel Listener

function EverythingExport(outputStream)
{
    // Get unique file within user profile directory. 
    var file = dirService.get("ProfD", Ci.nsIFile);
    file.append("netlistener");
    file.append("netMonitor.txt");
    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);

    // Initialize output stream.
    this.outputStream =
        Cc["@mozilla.org/network/file-output-stream;1"]
        .createInstance(Ci.nsIFileOutputStream);

    // write, create, truncate
    this.outputStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
}

EverythingExport.prototype = 
{
    onRequest: function(context, file)
    {
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponse; " + (file ? file.href : ""));
    },

    onExamineResponse: function(context, request)
    {
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onExamineResponse;" + request.name);
    },

    onResponse: function(context, file)
    {
        return;
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponse; " + (file ? file.href : ""));

        try
        {
            var text = file.href + " (" + formatTime
                (file.endTime - file.startTime) + ")\n";
            this.outputStream.write(text, text.length);
        }
        catch (err)
        {
            if (FBTrace.DBG_NETLISTENER || FBTRace.DBG_ERRORS)
                FBTrace.sysout("netListener.onResponse; EXCEPTION", err);
        }
    },

    onResponseBody: function(context, file)
    {

        Firebug.Console.openGroup("EverythingDownloader", null, "group", null, false);
        Firebug.Console.log("Found File");
        Firebug.Console.log(file);
        Firebug.Console.log(context);
        Firebug.Console.log(this.transport);
        Firebug.Console.log(this);
        Firebug.Console.log(file.mimeType);
        savefile="C:\\Users\\MyUserName\\Desktop\\MyFolder\\" + file.startTime + "-music.mp3";
        //Yes I know that is not cross-platform friendly...
        var req = new XMLHttpRequest();
        req.onreadystatechange = function()
        {
            if(this.readyState == 4 && this.status == 200) {
                Firebug.Console.log(req);
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } catch (e) {
                    alert("Permission to save file was denied.");
                }
                var file = Components.classes["@mozilla.org/file/local;1"]
                    .createInstance(Components.interfaces.nsILocalFile);
                file.initWithPath( savefile );
                if ( file.exists() == false ) {
                    Firebug.Console.log( "Creating file... " );
                    file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
                }
                var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                    .createInstance( Components.interfaces.nsIFileOutputStream );
                /* Open flags 
                #define PR_RDONLY       0x01
                #define PR_WRONLY       0x02
                #define PR_RDWR         0x04
                #define PR_CREATE_FILE  0x08
                #define PR_APPEND      0x10
                #define PR_TRUNCATE     0x20
                #define PR_SYNC         0x40
                #define PR_EXCL         0x80
                */
                /*
                ** File modes ....
                **
                ** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
                ** The 'mode' argument may be ignored by PR_Open on other platforms.
                **
                **   00400   Read by owner.
                **   00200   Write by owner.
                **   00100   Execute (search if a directory) by owner.
                **   00040   Read by group.
                **   00020   Write by group.
                **   00010   Execute by group.
                **   00004   Read by others.
                **   00002   Write by others
                **   00001   Execute by others.
                **
                */
                outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
                var result = outputStream.write( this.responseText, this.responseText.length );
                Firebug.Console.log("Done!");
                outputStream.close();
                Firebug.Console.closeGroup();
            }
        }

        req.open("GET", file.href, true);
        req.send(null);
        return;
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponseBody; " + (file ? file.href : ""), file);
        //Firebug.Console.log(file);
        //
    }
};

var savefile="";
// ************************************************************************************************
// Registration

Firebug.registerModule(Firebug.EverythingExportModule);

// ************************************************************************************************
}});

I am trying to create a SIMPLE plugin, no interface is necessary, that will automatically download and save to "Desktop/MyFolder/" everything that the page loads. My thought was to make an extension that extends FireBug, but that seems to be rather challenging. I got it to do some things, however on things like images, flv's, and mp3s the content appears to be placed in the file, however when I try to view them they are not viewable/invalid formats.

I am thinking I need to just need to do some kind of MimeType or file format thing. It really looks good, however something is obviously missing.

Thanks in advance!

FBL.ns(function() { with (FBL) { 

const Cc = Components.classes;
const Ci = Components.interfaces;

const dirService = Cc["@mozilla.org/file/directory_service;1"]
    .getService(Ci.nsIProperties);

// ************************************************************************************************
// Module implementation

Firebug.EverythingExportModule = extend(Firebug.Module,
{
    initialize: function(owner)
    {
        Firebug.Module.initialize.apply(this, arguments);

        // Register NetMonitor listener
        this.netListener = new EverythingExport();
        Firebug.NetMonitor.addListener(this.netListener);
    },

    shutdown: function()
    {
        Firebug.Module.shutdown.apply(this, arguments);

        // Unregister NetMonitor listener
        Firebug.NetMonitor.removeListener(this.netListener);
        this.netListener.outputStream.close();
    }
});

// ************************************************************************************************
// Net Panel Listener

function EverythingExport(outputStream)
{
    // Get unique file within user profile directory. 
    var file = dirService.get("ProfD", Ci.nsIFile);
    file.append("netlistener");
    file.append("netMonitor.txt");
    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);

    // Initialize output stream.
    this.outputStream =
        Cc["@mozilla.org/network/file-output-stream;1"]
        .createInstance(Ci.nsIFileOutputStream);

    // write, create, truncate
    this.outputStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
}

EverythingExport.prototype = 
{
    onRequest: function(context, file)
    {
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponse; " + (file ? file.href : ""));
    },

    onExamineResponse: function(context, request)
    {
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onExamineResponse;" + request.name);
    },

    onResponse: function(context, file)
    {
        return;
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponse; " + (file ? file.href : ""));

        try
        {
            var text = file.href + " (" + formatTime
                (file.endTime - file.startTime) + ")\n";
            this.outputStream.write(text, text.length);
        }
        catch (err)
        {
            if (FBTrace.DBG_NETLISTENER || FBTRace.DBG_ERRORS)
                FBTrace.sysout("netListener.onResponse; EXCEPTION", err);
        }
    },

    onResponseBody: function(context, file)
    {

        Firebug.Console.openGroup("EverythingDownloader", null, "group", null, false);
        Firebug.Console.log("Found File");
        Firebug.Console.log(file);
        Firebug.Console.log(context);
        Firebug.Console.log(this.transport);
        Firebug.Console.log(this);
        Firebug.Console.log(file.mimeType);
        savefile="C:\\Users\\MyUserName\\Desktop\\MyFolder\\" + file.startTime + "-music.mp3";
        //Yes I know that is not cross-platform friendly...
        var req = new XMLHttpRequest();
        req.onreadystatechange = function()
        {
            if(this.readyState == 4 && this.status == 200) {
                Firebug.Console.log(req);
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } catch (e) {
                    alert("Permission to save file was denied.");
                }
                var file = Components.classes["@mozilla.org/file/local;1"]
                    .createInstance(Components.interfaces.nsILocalFile);
                file.initWithPath( savefile );
                if ( file.exists() == false ) {
                    Firebug.Console.log( "Creating file... " );
                    file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
                }
                var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                    .createInstance( Components.interfaces.nsIFileOutputStream );
                /* Open flags 
                #define PR_RDONLY       0x01
                #define PR_WRONLY       0x02
                #define PR_RDWR         0x04
                #define PR_CREATE_FILE  0x08
                #define PR_APPEND      0x10
                #define PR_TRUNCATE     0x20
                #define PR_SYNC         0x40
                #define PR_EXCL         0x80
                */
                /*
                ** File modes ....
                **
                ** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
                ** The 'mode' argument may be ignored by PR_Open on other platforms.
                **
                **   00400   Read by owner.
                **   00200   Write by owner.
                **   00100   Execute (search if a directory) by owner.
                **   00040   Read by group.
                **   00020   Write by group.
                **   00010   Execute by group.
                **   00004   Read by others.
                **   00002   Write by others
                **   00001   Execute by others.
                **
                */
                outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
                var result = outputStream.write( this.responseText, this.responseText.length );
                Firebug.Console.log("Done!");
                outputStream.close();
                Firebug.Console.closeGroup();
            }
        }

        req.open("GET", file.href, true);
        req.send(null);
        return;
        if (FBTrace.DBG_NETLISTENER)
            FBTrace.sysout("netListener.onResponseBody; " + (file ? file.href : ""), file);
        //Firebug.Console.log(file);
        //
    }
};

var savefile="";
// ************************************************************************************************
// Registration

Firebug.registerModule(Firebug.EverythingExportModule);

// ************************************************************************************************
}});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2024-09-23 19:38:07

好吧,我无法弄清楚这一点,所以我所做的就是让一个 C# 程序执行 FileSystem Watch(Google 一下),当它看到我正在寻找的文件大小范围内的文件时,它会将其复制并重命名为我所在的位置需要。它不是 FireBug 插件,但它确实有效。

Alright, well I could not figre that out, so all I did was have a C# program do a FileSystem Watch (Google it) and when it saw a file within the filesize bounds I was looking for, it copied and renamed it to where I needed. It isn't a FireBug plugin, but it did work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文