User:Dickvl: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
No edit summary
((* added enhanced psw javascript code *))
Line 163: Line 163:


function TD(string) {return (string.length < 2) ? "0" + string : string ;}
function TD(string) {return (string.length < 2) ? "0" + string : string ;}
function FD(number){return (number < 1000) ? number + 1900 : number;}
function FD(number){return (number < 1000) ? number + 2000 : number;}


var now = new Date();
var now = new Date();
Line 199: Line 199:
makeTABLE("Extensions",thead,tdivE) + makeTABLE("Themes",thead,tdivT)+'
makeTABLE("Extensions",thead,tdivE) + makeTABLE("Themes",thead,tdivT)+'
</body></html>',"", "menubar=yes,toolbar=no,resizable=yes,scrollbars=yes,width=1000,height=700");
</body></html>',"", "menubar=yes,toolbar=no,resizable=yes,scrollbars=yes,width=1000,height=700");
})();
</pre>
Here is an enhanced version of the Password printing code from [[Password Manager]] to show all the fields, may be helpful for troubleshooting issues.
<pre>/*
* Paste this file into Firefox's JavaScript Console and evaluate it to display the saved names and passwords - dickvl@kb.mozillazine.org
*/
(function(){
function tdigs(str) {return (str.length < 2) ? "0" + str : str;}
function fdigs(num){return (num < 1000) ? num + 2000 : num;}
var now = new Date();
var hrs = tdigs(now.getHours() + "") ;
var mins = tdigs(now.getMinutes() + "") ;
var secs = tdigs(now.getSeconds() + "") ;
var tValue = " | At  " + hrs + ":" + mins + ":" + secs;
var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var mons = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
var today =  "On " + days[now.getDay()] + ", " + date + " " + mons[now.getMonth()] + " " +    (fdigs(now.getYear())) + tValue ;
var Cc = Components.classes;
var Ci = Components.interfaces;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var tokendb = Cc["@mozilla.org/security/pk11tokendb;1"]
                .createInstance(Ci.nsIPK11TokenDB);
var token = tokendb.getInternalKeyToken();
try {token.login(true);} catch (e) {}
if (token.isLoggedIn()) {
var passwordmanager = Cc["@mozilla.org/login-manager;1"]
                      .getService(Ci.nsILoginManager);
var names="",signons = passwordmanager.getAllLogins({});
for (i=0;i<signons.length;i++) {
  try {
  var host = signons[i].hostname;
  var realm = signons[i].httpRealm;
  var user = signons[i].username;
  var usrf = signons[i].usernameField;
  var psw = signons[i].password;
  var pswf = signons[i].passwordField;
  var surl = signons[i].formSubmitURL;
  if (user == ""){ user = "<br>"; }
  names+="<tr>\n<td>"+host+"</td>\n<td>"+realm+" </td>\n<td>"+usrf+"</td>\n<td>"+user+"</td>\n<td>"+pswf+"</td>\n<td>"+psw+"</td>\n<td>"+surl+"</td>\n</tr>\n";
  } catch(e) {}
}
void(window.open('data:text/html,
<html><head>
<meta http-equiv=content-type" content="text/html; charset=ISO-8859-1">
<title>Exported Mozilla Passwords</title>
<style type="text/css">
td {
  font-family: "Trebuchet MS", Arial, Helvetica, Geneva, Verdana, Sans-Serif;
  font-size: 85%;
  padding: 1px 2px 1px 2px;
}
</style>
</head><body style="margin: 1em 3em; background-color: rgb(255, 221, 221);">
<b>MOZILLA PASSWORD INFORMATION</b>
<p>Produced by <i>Pasting Code in the "Tools > Error Console: Code field"</i> (by "ernie" - Andrew Poth - Ed Mullen - adapted by dickvl@kb.mozillazine.org to run in the Error Console)<br>'+today+
'</p><p>
<table style="empty-cells: show; background-color: rgb(221, 255, 221);" border="1" cellspacing="0">
<tbody><tr style="background-color: rgb(204, 204, 255);">
<td>
<b>Host</b>
</td>
<td>
<b>Realm</b>
</td>
<td>
<b>User Field</b>
</td>
<td>
<b>User Name</b>
</td>
<td>
<b>Psw Field</b>
</td>
<td>
<b>Password</b>
</td>
<td>
<b>Submit URL</b>
</td>
</tr>'+names+'</tbody></table>
</p></body></html>',"","menubar=yes,resizable=yes,scrollbars=yes,width=1000,height:600"));
}
})();
})();
</pre>
</pre>

Revision as of 17:37, 5 December 2009

Sometime ago I noticed the Mozilla's Places Stats Project thread with the possibility to display a list of installed extensions in JSON notation by using the Error Console. That gave me an idea to do the same for the printing passwords code in the Password Manager article.

I have also taken the opportunity to create a similar file for displaying the installed extensions. So here are two versions.
The first version shows the name and version number and the second version has the possibility to select which additional columns you wish to see.

/*
 * Paste this file into Firefox's JavaScript Console and evaluate it to display the installed extensions and themes - dickvl@kb.mozillazine.org
*/
(function () {
var Cc = Components.classes;
var Ci = Components.interfaces;
var EMP = "http://www.mozilla.org/2004/em-rdf#";
var rv = {}; rv.ext = []; rv.the = [];

var ds =
    Cc["@mozilla.org/extensions/manager;1"].
    getService(Ci.nsIExtensionManager).
    datasource;
var rdf =
    Cc["@mozilla.org/rdf/rdf-service;1"].
    getService(Ci.nsIRDFService);
var elts =
    Cc["@mozilla.org/rdf/container-utils;1"].
    getService(Ci.nsIRDFContainerUtils).
    MakeSeq(ds, rdf.GetResource("urn:mozilla:item:root")).
    GetElements();

function rdfGS(elt,res){
 try{
     return(ds.GetTarget(elt,rdf.GetResource(EMP+res),true).QueryInterface(Ci.nsIRDFLiteral).Value);
 } catch(e){return("")}
}

function makeRV(elt,rv){
 var nam = rdfGS(elt,"name");
 var ver = rdfGS(elt,"version");
 var dis = rdfGS(elt,"isDisabled");
 var hom = rdfGS(elt,"homepageURL");
 rv.push({name:nam,id:elt.Value.replace(/^urn:mozilla:item:/,""),vers:ver,dis:dis,home:hom});
return(rv);
}

function makeLIST(rv){
 var list="",i,RV;
 for (i=0;RV=rv[i];i++) {
  var name = RV.name;
  var vers = RV.vers;
  var disab = (RV.dis=="true")?"(disabled)":"";
  var home = RV.home;
  list+="<a href=" + home + "><span>" + name + " </span><span> " + vers + " </span></a><span> " + disab + " </span></br>";
 }
return(list);
}

while (elts.hasMoreElements()) {
 var elt = elts.getNext().QueryInterface(Ci.nsIRDFResource);
 if (ds.HasAssertion(elt,rdf.GetResource(EMP+"type"),rdf.GetIntLiteral(2),true)){
  makeRV(elt,rv.ext); 
 }
 if (ds.HasAssertion(elt,rdf.GetResource(EMP+"type"),rdf.GetIntLiteral(4),true)){
  makeRV(elt,rv.the);
 }
}

var extList="<p><b>Extensions:</b><br>"+makeLIST(rv.ext)+"</p>";
var theList="<p><b>Themes:</b><br>"+makeLIST(rv.the)+"</p>";

window.open('data:text/html,
<html><head>
<meta http-equiv=content-type" content="text/html; charset=ISO-8859-1">
<title>Mozilla Extensions</title>
</head><body style="margin: 1em 3em; background-color: rgb(255, 221, 221);">
' + extList + theList + '
</body></html>',
"", "menubar=yes,toolbar=no,scrollbars=yes,resizable=yes,width=1000,height=600");
})();
/* 
 *To display the installed extensions and themes paste this file into Firefox's JavaScript Console and evaluate it - dickvl@kb.mozillazine.org
*/
(function () {
var Cc = Components.classes;
var Ci = Components.interfaces;
var EMP = "http://www.mozilla.org/2004/em-rdf#";
var EMT = 2; /* Extensions: EMT = 2;  Themes: EMT = 4; */
var rv = {}; rv.ext = []; rv.the = [];

/* columns - 0:space  1:name  2:version  3,4:disabled  5:id  6:description  7:homepage  8:compatible  9:install location */
var THEAD = ["","Name","Version","Disabled","(-)","ID","Description","Home Page","Comp.","Inst.Loc"];
var TCONT = (prompt("Columns:\n\n1:Name\n2:Version\n3:Disabled  4:(U|A)\n5:ID\n6:Description\n7:Home Page\n","1 2 3"));
TCONT=((TCONT==null || TCONT=="")?"1 2 3":TCONT).split(" ");

var ds =
    Cc["@mozilla.org/extensions/manager;1"].
    getService(Ci.nsIExtensionManager).
    datasource;
var rdf =
    Cc["@mozilla.org/rdf/rdf-service;1"].
    getService(Ci.nsIRDFService);
var elts =
    Cc["@mozilla.org/rdf/container-utils;1"].
    getService(Ci.nsIRDFContainerUtils).
    MakeSeq(ds, rdf.GetResource("urn:mozilla:item:root")).
    GetElements();

function rdfGS(elt,res){
 try{
  return(ds.GetTarget(elt,rdf.GetResource(EMP+res),true).QueryInterface(Ci.nsIRDFLiteral).Value);
 }catch(e){return("")}
}

function makeTD(rv){
var i,j,DV,RV,TC,td="";
for (i=0;RV=rv[i];i++) {
  td+="<tr>";
 for(j=0;TC=TCONT[j];j++){
  switch(parseInt(TC)){
   case 1: DV=RV.name;break;
   case 2: DV=RV.vers;break;
   case 3: DV=(RV.dis=="true")?"(disabled)":"";break;
   case 4: DV=((RV.adis=="true")?"(A)":"")+((RV.udis=="true")?"(U)":"");break;
   case 5: DV=RV.id;break;
   case 6: DV=RV.descr;break;
   case 7: DV=RV.home;break;
   case 8: DV=(RV.comp=="true")?"Yes":((RV.comp=="false")?"No":"");break;
   case 9: DV=RV.inst;break;
   default: DV="";break;
  } td+="<td>"+DV+"</td>";
 }
 td+="</tr>";
}
return(td);
}

function makeRV(elt,rv){
 var nam = rdfGS(elt,"name");
 var ver = rdfGS(elt,"version");
 var des = rdfGS(elt,"description");
 var dis = rdfGS(elt,"isDisabled");
 var ads = rdfGS(elt,"appDisabled");
 var uds = rdfGS(elt,"userDisabled");
 var hom = rdfGS(elt,"homepageURL");
 var com = rdfGS(elt,"compatible");
 var ins = rdfGS(elt,"installLocation");
 rv.push({name:nam,id:elt.Value.replace(/^urn:mozilla:item:/,""),vers:ver,descr:des,adis:ads,udis:uds,home:hom,dis:dis,inst:ins,comp:com});
return(rv);
}

while (elts.hasMoreElements()){
 var elt = elts.getNext().QueryInterface(Ci.nsIRDFResource);
 if(isExt=ds.HasAssertion(elt,rdf.GetResource(EMP+"type"),rdf.GetIntLiteral(2),true)){
  makeRV(elt,rv.ext);
 }
 if(isExt=ds.HasAssertion(elt,rdf.GetResource(EMP+"type"),rdf.GetIntLiteral(4),true)){
  makeRV(elt,rv.the);
 }
}

var thead="";
for(j=0;TC=TCONT[j];j++){thead+="<td><b>"+(THEAD[(TC<THEAD.length)?TC:0])+"</b></td>";}

var tdivE = makeTD(rv.ext);
var tdivT = makeTD(rv.the);

function TD(string) {return (string.length < 2) ? "0" + string : string ;}
function FD(number){return (number < 1000) ? number + 2000 : number;}

var now = new Date();
var hrs = TD(now.getHours() + "");
var min = TD(now.getMinutes() + "");
var sec = TD(now.getSeconds() + "");

var timeValue = " | At  " + hrs + ":" + min + ":" + sec;
var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

var today =  "On " + days[now.getDay()] + ", " + date + " " + months[now.getMonth()] + " " +    (FD(now.getYear())) + timeValue;

function makeTABLE(label,thead,tcont){
return('<p><b>'+label+':</b><br>
<table style="empty-cells: show; background-color: rgb(221, 255, 221);" border="1" cellspacing="0">
<tbody><tr style="background-color: rgb(204, 204, 255);">'+thead+'</tr>'+
tcont+'</tbody></table></p>');
}

window.open('data:text/html,
<html><head>
<meta http-equiv=content-type" content="text/html; charset=ISO-8859-1">
<title>Mozilla Extensions & Themes</title>
<style type="text/css">
 td {
  font-family: "Trebuchet MS", Arial, Verdana, Sans-Serif;
  font-size: 85%;
  padding: 1px 2px 1px 2px;
}
</style>
</head><body style="margin: 1em 3em; background-color: rgb(255, 221, 221);">
<b>MOZILLA ADD-ONS INFORMATION (by dickvl@kb.mozillazine.org)</b><p>'+today+'</p>'+
makeTABLE("Extensions",thead,tdivE) + makeTABLE("Themes",thead,tdivT)+'
</body></html>',"", "menubar=yes,toolbar=no,resizable=yes,scrollbars=yes,width=1000,height=700");
})();

Here is an enhanced version of the Password printing code from Password Manager to show all the fields, may be helpful for troubleshooting issues.

/*
 * Paste this file into Firefox's JavaScript Console and evaluate it to display the saved names and passwords - dickvl@kb.mozillazine.org
*/

(function(){
function tdigs(str) {return (str.length < 2) ? "0" + str : str;}
function fdigs(num){return (num < 1000) ? num + 2000 : num;}

var now = new Date();
var hrs = tdigs(now.getHours() + "") ;
var mins = tdigs(now.getMinutes() + "") ;
var secs = tdigs(now.getSeconds() + "") ;

var tValue = " | At  " + hrs + ":" + mins + ":" + secs;
var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var mons = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

var today =  "On " + days[now.getDay()] + ", " + date + " " + mons[now.getMonth()] + " " +    (fdigs(now.getYear())) + tValue ;

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

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

var tokendb = Cc["@mozilla.org/security/pk11tokendb;1"]
                .createInstance(Ci.nsIPK11TokenDB);
var token = tokendb.getInternalKeyToken();

try {token.login(true);} catch (e) {}

if (token.isLoggedIn()) {
 var passwordmanager = Cc["@mozilla.org/login-manager;1"]
                       .getService(Ci.nsILoginManager);
 var names="",signons = passwordmanager.getAllLogins({});

 for (i=0;i<signons.length;i++) {
  try {
   var host = signons[i].hostname;
   var realm = signons[i].httpRealm;
   var user = signons[i].username;
   var usrf = signons[i].usernameField;
   var psw = signons[i].password;
   var pswf = signons[i].passwordField;
   var surl = signons[i].formSubmitURL;
   if (user == ""){ user = "<br>"; }
   names+="<tr>\n<td>"+host+"</td>\n<td>"+realm+" </td>\n<td>"+usrf+"</td>\n<td>"+user+"</td>\n<td>"+pswf+"</td>\n<td>"+psw+"</td>\n<td>"+surl+"</td>\n</tr>\n";
   } catch(e) {}
 }

 void(window.open('data:text/html,
<html><head>
<meta http-equiv=content-type" content="text/html; charset=ISO-8859-1">

<title>Exported Mozilla Passwords</title>
<style type="text/css">
 td {
  font-family: "Trebuchet MS", Arial, Helvetica, Geneva, Verdana, Sans-Serif;
  font-size: 85%;
  padding: 1px 2px 1px 2px;
}
</style>
</head><body style="margin: 1em 3em; background-color: rgb(255, 221, 221);">
<b>MOZILLA PASSWORD INFORMATION</b>
<p>Produced by <i>Pasting Code in the "Tools > Error Console: Code field"</i> (by "ernie" - Andrew Poth - Ed Mullen - adapted by dickvl@kb.mozillazine.org to run in the Error Console)<br>'+today+
'</p><p>
<table style="empty-cells: show; background-color: rgb(221, 255, 221);" border="1" cellspacing="0">
<tbody><tr style="background-color: rgb(204, 204, 255);">
<td>
<b>Host</b>
</td>
<td>
<b>Realm</b>
</td>
<td>
<b>User Field</b>
</td>
<td>
<b>User Name</b>
</td>
<td>
<b>Psw Field</b>
</td>
<td>
<b>Password</b>
</td>
<td>
<b>Submit URL</b>
</td>
</tr>'+names+'</tbody></table>
</p></body></html>',"","menubar=yes,resizable=yes,scrollbars=yes,width=1000,height:600"));
}
})();