| Author |
Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
I'm trying to build a Firefox extension that fetches part of the contents of a certain webpage (something like blog posts) and save them as local files.
My plan is to place a little "save" button on either context menu or status bar, enabling users to click and save the contents to their computers.
I know how to fetch and process data from a webpage (Timed challenges, right?) but to tell the truth, I don't know how to create local files out of acquired data. This is where I need help the most.
Suggesting me useful websites, or even keywords to Google is just fine.
Regards,
SQuirreL
P.S. I already Googled the following string: "firefox extension download save" but it only showed existing extensions such as DownloadHelper.
I also decompiled a few extensions for resources (as many Japanese martial arts encourage to "steal" techniques from seniors) but I failed to read through them because they were too complicated for me.
This account is no longer used. |
|
| Author |
RE: Firefox extension help |
elmiguel
Member

Posts: 132
Location: Your Computer
Joined: 12.12.07 Rank: God |
|
I have only decompiled a few extensions myself (manly to make them work for the lastest FF ver.) They are written in javascblockedript, correct? Don't have time to look now. Anyway, you want to look up on how to read and write files. I will research it at work then I get back to you.
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
Edited by elmiguel on 05-08-09 12:43 |
|
| Author |
RE: Firefox extension help |
korg
Admin from hell

Posts: 1704
Location: ENDING YOUR ONLINE EXPERIENCE!
Joined: 01.01.06 Rank: The Master |
|
Google "saving data locally" you'll get some examples real quick.
This is easy to do in javascblockedript think of how firefox saves it's temp. files.
I deal in pain, All life I drain, I dominate, I seal your fate.
|
|
| Author |
RE: Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
Thanks for the replies. I'll try the suggested Google keywords and research for temp-file creation.
@Moshbat
Well, let's just say I didn't have enough brain to think of the Google keywords myself and thus needed suggestions. That's why I posted this thread.
This account is no longer used. |
|
| Author |
RE: Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
Well, I found someone has made a way to store data locally by combining Flash and Javascblockedript.
Googled "saving data locally javascblockedript" and it was there!
All I had to type in was what I was trying to do...
Anyway, thanks for the assist.
This account is no longer used. |
|
| Author |
RE: Firefox extension help |
korg
Admin from hell

Posts: 1704
Location: ENDING YOUR ONLINE EXPERIENCE!
Joined: 01.01.06 Rank: The Master |
|
|
SQuirreL wrote:
Googled "saving data locally javascblockedript" and it was there!
Yes Virginia it's really that easy.
I deal in pain, All life I drain, I dominate, I seal your fate.
|
|
| Author |
RE: Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
OK, I've built something like this with help of some snippets available online.
Here's the "core.js"
var x = document.getElementsByTagName('table');
var y = x[20].innerHTML;
var savefile = &savepath;
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("Permission to save file was denied.");
}
function save() {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("Permission to save file was denied.");
}
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( savefile );
if ( file.exists() == false ) {
alert( "Creating file... " );
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
}
var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance( Components.interfaces.nsIFileOutputStream );
/* Open flags
#define PR_RDONLY 0x01
#define PR_WRONLY 0x02
#define PR_RDWR 0x04
#define PR_CREATE_FILE 0x08
#define PR_APPEND 0x10
#define PR_TRUNCATE 0x20
#define PR_SYNC 0x40
#define PR_EXCL 0x80
*/
outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
var result = outputStream.write( y, y.length );
outputStream.close();
}
The user triggers the save() function via an entry in the context menu.
But it doesn't seem to work. I tried to study how other extensions save their data locally but I couldn't make it. I Googled only to find somebody saying "Local file manipulation with Javascblockedript is not allowed."
What I'm supposed to do?
This account is no longer used. |
|
| Author |
RE: Firefox extension help |
454447415244
Member
Posts: 156
Location:
Joined: 20.04.08 Rank: God |
|
|
SQuirreL wrote:
I know how to fetch and process data from a webpage (Timed challenges, right?)
No. Not right.
As for writing to a file, take a look at Mozilla official documentation about File I/O => https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO
For any further help, contact me on my email.
Awesome! |
|
| Author |
RE: Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
Boy! That really helped!! I just can't believe I couldn't reach that site myself!!
Pretty much thanks ;)
OK, there's another thing.
I'm trying to capture part of the page being shown, so I tried to use this way but no use.
function save() {
var x = document.getElementsByTagName('table');
var string = x[20].innerHTML;
------OMMITION-------
outputStream.write(string, string.length);
outputStream.flush();
outputStream.close();
fileStream.close();
I don't see it working.
When I hardcore the string to "Hello world" it works.
I guess it's not accepting the element from the page.
Could you point me the problem?
EDIT: Self solved.
XUL doesn't seem to support innerHTML methods
This account is no longer used.
Edited by SQuirreL on 12-08-09 02:29 |
|
| Author |
RE: Firefox extension help |
SQuirreL
Member
Posts: 24
Location:
Joined: 17.08.06 Rank: God |
|
Sorry for posting yet again.
Firefox extension DOES support innerHTML method. My mistake was I should have used "content.document.getElementsBy....." instead of "document.getElementsBy....."
So at last, I'm able to release this add-on (privately) !! Yay!!!
Many thanks to everyone!!
This account is no longer used. |
|