Skip to content

Instantly share code, notes, and snippets.

@mozfreddyb
Created April 16, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozfreddyb/f22e1f1787a96391a5c1c141c473284b to your computer and use it in GitHub Desktop.
Save mozfreddyb/f22e1f1787a96391a5c1c141c473284b to your computer and use it in GitHub Desktop.
// for use within chrome://passwordmgr/content/passwordManager.xul
// this is the title of the CSV data
var csv = `"hostname", "username", "password"`;
// the signons variable already exists when the document is loaded.
// looping through all entries, called e.
for (var e of signons) {
// JSON.stringify properly adds quotes, regardless of what characters the entries.
// so for every entry, take e.hostname, e.username, e.passwowrd and turn them into a quoted string
// end with a newline
csv += `${JSON.stringify(e.hostname)}, ${JSON.stringify(e.username)}, ${JSON.stringify(e.password)}\n`
}
// get a clipboard object
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
// and copy the csv data into the clipboard
clipboard.copyString(csv);
@mozfreddyb
Copy link
Author

Without comments

var csv = `"hostname", "username", "password"`;
for (var e of signons) {
    csv += `${JSON.stringify(e.hostname)}, ${JSON.stringify(e.username)}, ${JSON.stringify(e.password)}\n`
}
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
                                   .getService(Components.interfaces.nsIClipboardHelper);
clipboard.copyString(csv);```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment