views:

507

answers:

1

well, since greasemonkey cant read/write files from local hard disk. I've heard people suggesting Google gears but i've no idea obout gears :(

So, what i've decided is to add a

script type="text/javascript" src="file:///c:/test.js">/script>

Now, this test will use FileSystemObject to read/write file. Since, the "file:///c:/test.js" is a javascript file from local hard disk, so it should probable be able to read/write file on my local hard disk. I tried it but firefox prevented the "file:///c:/test.js" script to read/write files from local diak :(

What i want to know is: Is there any setting in firefox about:config where we can specify to let a particular script, say from localfile or xyz.com, to have read/write permission on my local disk files??

+3  A: 

You can use these within chrome scope.

var FileManager =
{
Write:
    function (File, Text)
    {
        if (!File) return;
        const unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);

        unicodeConverter.charset = "UTF-8";

        Text = unicodeConverter.ConvertFromUnicode(Text);
        const os = Components.classes["@mozilla.org/network/file-output-stream;1"]
          .createInstance(Components.interfaces.nsIFileOutputStream);
        os.init(File, 0x02 | 0x08 | 0x20, 0700, 0);
        os.write(Text, Text.length);
        os.close();
    },

Read:
    function (File)
    {
        if (!File) return;
        var res;

        const is = Components.classes["@mozilla.org/network/file-input-stream;1"]
            .createInstance(Components.interfaces.nsIFileInputStream);
        const sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
            .createInstance(Components.interfaces.nsIScriptableInputStream);
        is.init(File, 0x01, 0400, null);
        sis.init(is);

        res = sis.read(sis.available());

        is.close();

        return res;
    },
}

Example:

var x = FileManager.Read("C:\\test.js");

See Also

BrunoLM