Browser persist and dependencies

I have been looking at the files from a Mozilla Firefox
add-on that has the ability to save pages. I am trying to find a way to make it
save a file type that it does save, but Firefox uses. The format type is MAFF. I
got some idea of how to and that this could be done from the maker of the
add-on’s website here.
iMacros thread
Document suggesting MAFF usage
I have questions related to the JavaScript I am trying to manipulate. It has been a while since
I have worked with JavaScript but it all coming back fast. I have two pieces of
code are that related to my questions, one is the suggested way to make Firefox save
MAFF format (code 1), and the other is snippet the JavaScript from the add-on.
My questions are:

  1. I have notice the place where the add-on is accessing objects,
    Firefox’s objects via its own written code, How would (code 1) use
    the example (code 2) MAFF *.jsm information does it have to be
    include at the top? Does it even need it?

  2. I see how the simple example uses some of the same component
    classes, component interfaces ect. I have tracked them down in the
    add-on (code 1) they seem similar and all equally present. It seems
    as the MAFF (code block 2) is referring to its own use of the
    browser persist object so is there a way to set up something like a
    wbp variable that would use two of them at the same time? Or is
    there a better way to do that. Will MAFF not use the one that is
    there? The simpler example creates a new MafObject instance if there
    are two libraries how will this work? Or could this work? And I am
    not suggesting that from any point of know how I am asking how
    because know it needs to used but I don’t know how

  3. I have already tested just adding he code to the area I am showing
    here in the form it in something like if (type == “maff”) and all
    places where it needs to be replaced. After trying it only creates a
    file *.maff when really examined it was still a *.htm file, but how
    could it this be written taken in account for what needs to happen
    for this code to have what the MAFF format needs.

  4. There are files that I have tracked down that have dependent code in
    them. Everything the simpler example seems to have it is present in
    the add-on all over the place in different files. But can somebody
    think of places that they know of that are necessary to update if
    you are working with these dependencies like Mozilla’s component
    classes and *.jsm imports.

    MacroPlayer.prototype.ActionTable["saveas"] = function (cmd) {
        var folder = imns.unwrap(this.expandVariables(cmd[2]));
        var type = imns.unwrap(this.expandVariables(cmd[1])).toLowerCase();
        if (folder == "*") {
            folder = imns.Pref.getFilePref("defdownpath").path;
        try {
            var f = imns.FIO.openNode(folder);
        } catch (e) {
            throw new RuntimeError("Wrong path "+folder, 932);
        if (!f.exists())
            throw new RuntimeError("Path "+folder+" does not exists", 932);
        var file = imns.unwrap(this.expandVariables(cmd[3])), t;
        var __doc_name = function(win) {
            var name = win.location.pathname;
            if (/\/([^\/]*)$/.test(name))
                name = RegExp.$1;
            if (!name.length) {
                if (/^(?:www\.)(\S+)/.test(win.location.hostname))
                    name = RegExp.$1;
            if (!name.length)
                name = win.document.title;
            if (!name.length)
                return "unknown";
            if (/^(.*)\.(?:\w+)$/.test(name))
                return RegExp.$1;
            return name;
        var re = new RegExp('\\s*[:*?|<>\\"/]+\\s*', "g");
        if (type == "extract") {
            if (file == "*") {
                file = "extract.csv";
            } else if (t = file.match(/^\+(.+)$/)) {
                file = "extract"+t[1]+".csv";
            file = file.replace(re, "_");
            var data = this.getExtractData();
            data = data.replace(/\"/g, '""');
            data = '"'+data.replace(/\[EXTRACT\]/g, '","')+'"';
            f = imns.FIO.openNode(folder);
            imns.FIO.appendTextFile(f, data+"\r\n");
        } else {
            if (file == "*") {
                file = __doc_name(window.content);
            } else if (t = file.match(/^\+(.+)$/)) {
                file = __doc_name(window.content) + t[1];
            file = file.replace(re, "_");
            var wbp = null, doc = window.content.document;
            wbp = imns.Cc[';1'];
            wbp = wbp.createInstance(imns.Ci.nsIWebBrowserPersist);
            var flags = wbp.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
            wbp.persistFlags = flags;
            var f = imns.FIO.openNode(folder);
            if (type == "cpl") {
                if (!/html?$/.test(file))
                    file += ".htm";
                var files_dir = f.path.replace(/\.html?$/, "_files");
                files_dir = imns.FIO.openNode(files_dir);
                wbp.saveDocument(doc, f, files_dir, null, null, 0);
            } else if (type == "htm") {
                if (!/html?$/.test(file))
                    file += ".htm";
                wbp.saveDocument(doc, f, null, null, null, 0);
            } else if (type == "txt") {
                if (!/\.\w+$/.test(file))
                    file += ".txt";
                wbp.saveDocument(doc, f, null, "text/plain",
                                 wbp.ENCODE_FLAGS_FORMAT_FLOWED, 0);
            } else if (/^png|jpeg$/.test(type)) {
                this.savePageAsImage(window.content, file, f, type);
            } else {
                throw new BadParameter("iMacros for Firefox supports only "+
                                       "CPL|HTM|TXT|EXTRACT|PNG|JPEG SAVEAS types");
    var doc = gBrowser.contentDocument;
    var file = Components.classes[";1"].
    file.initWithPath("C:\\My Documents\\Test.maff");
    var format = "TypeMAFF";    
    var fileUri = Components.
    var persistObject = new MafObjects.MafArchivePersist(null, format);
    persistObject.saveDocument(doc, fileUri);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.