here is my main.js:
var widgets = require("sdk/widget");
var {Cc, Ci, Cu} = require("chrome");
var promptSvc = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
var stringtosave = 'secret information';
var widget = widgets.Widget({
id: "save_text_button",
label: "save text",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function() {
promptSvc.alert(null, "My Add-on", stringtosave + " saved! ");
}
});
It can alert the string using XPCOM.
How can I save the stringtosave in a textfile somewhere on the PC's harddrive?
Maybe there is a simple solution, that also makes use of XPCOM.
Assuming you want to use the profile directory
const { pathFor } = require('sdk/system');
const path = require('sdk/fs/path');
const file = require('sdk/io/file');
function saveText(name, str){
var filename = path.join(pathFor('ProfD'), name);
var textWriter = file.open(filename, 'w');
textWriter.write(str);
textWriter.close();
}
function readText(name){
var filename = path.join(pathFor('ProfD'), name);
if(!file.exists(filename)){
return null;
}
var textReader = file.open(filename, 'r');
var str = textReader.read();
textReader.close();
return str;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With