Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading firefox history file:ascii conversion API

Status
Not open for further replies.

newbiegalore

Programmer
Apr 12, 2008
8
US
Hello all :),
I am learning JS and extension programming and so am facing a few hurdles. I would greatly appreciate any pointers/code-samples/links to possible solutions.

My extension needs to read the history.dat file from the user's profile. I am trying to read the data stream and will need to extract the URLs from the file. Is there some easy/standard command/API to do this? I guess it must be a commonly implemented feature.

I have tried using String.fromCharCode(a-decimal-number); and written some functions based on code I saw on prodigynet.co.uk, they are listed at the very end of this post. I have not come across an API which could extract the URLs from the firefox history file. It would be great if someone could please point me in the right direction. All I can get using an alert on the read buffer is 61,104,116,116, ... etc.. which stands for =http:... . I tried to using alerts on String.fromCharCode for each character position via charAt, but it didn't work :-( .

Thanks again,
-A

=====================================================================
aResult is obtained from within

var ffhistobserver = {
onStreamComplete : function(aLoader, aContext, aStatus, aLength, aResult)
{

}};

and contains the actual data in the history file..next I tried to convert that to text..alas!!

var fftexti = clean_numstr(aResult, 16);
var fftexto = "" ;
for(jloop1=0; jloop1 < fftexti.length; jloop1+=2)
{
fftexto+=byteToChar(parseInt(fftexti.substring(i, i+2), 16));
}

function byteToChar(histnum)
{
if(histnum < 32 || histnum > 255) return " ";
return charArray[histnum-32];
}

function clean_numstr(raw_str, histbase)
{
var ret_str = "";
var histc = "";
var histi;
for(histi=0; histi < raw_str.length; histi++) {
histc = raw_str.charAt(histi);
if(histc == "0" || parseInt(histc, histbase) > 0) {
ret_str += histc;
}
}
return ret_str;
}

var charArray = new Array(
' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '', 'Ç', 'ü',
'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å',
'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', 'ø', '£', 'Ø',
'×', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '®', '¬', '½',
'¼', '¡', '«', '»', '_', '_', '_', '¦', '¦', 'Á', 'Â', 'À', '©', '¦',
'¦', '+', '+', '¢', '¥', '+', '+', '-', '-', '+', '-', '+', 'ã', 'Ã',
'+', '+', '-', '-', '¦', '-', '+', '¤', 'ð', 'Ð', 'Ê', 'Ë', 'È', 'i',
'Í', 'Î', 'Ï', '+', '+', '_', '_', '¦', 'Ì', '_', 'Ó', 'ß', 'Ô', 'Ò',
'õ', 'Õ', 'µ', 'þ', 'Þ', 'Ú', 'Û', 'Ù', 'ý', 'Ý', '¯', '´', '­', '±',
'_', '¾', '¶', '§', '÷', '¸', '°', '¨', '·', '¹', '³', '²', '_', ' ');
 
All I can get using an alert on the read buffer is 61,104,116,116, ... etc.. which stands for =http:... . I tried to using alerts on String.fromCharCode for each character position via charAt, but it didn't work

What result did you get? Using String.fromCharCode individually on those numbers should work - it does for me, anyway:

Code:
var theNums = [61, 104, 116, 116];
var theStr = '';

for (var loop=0; loop<theNums.length; loop++) {
   theStr += String.fromCharCode(theNums[loop]);
}

alert(theStr);

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan, I was trying something like decimalascii.charAt(offset).. and it was not working, while the array [] notation worked properly.

Thanks again,
-A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top