[Slogger] Trouble With Variable "$url"
mook at themook.net
mook at themook.net
Thu Feb 16 20:26:51 EST 2006
Hmm, okay - I feel like I'm so close, but now I'm having a new
problem. I did get some javascript that did exactly what I was
trying to do, from your original suggestion:
var a = sloggerGetVar("url");
alert(a);
a = a.replace(new RegExp(/\//gi), "_");
a = a.replace(new RegExp(/:/gi), "_");
a = a.replace(new RegExp(/\?/gi), "_");
alert(a);
sloggerSetVar("url",a);
When I test this script with the Slogger "test" button (on the
"Custom Script" tab), it works perfectly - the first alert box
shows:
http://www.site.com/article.html?id=001
In the second alert box, this becomes:
http___www.site.com_article.html_id=001
Perfect! I was excited at this point : ) However, when I
actually run the profile after clicking "OK" on the "Custom
Script" tab, it doesn't archive the page - it generates an error
box saying:
"Error running your custom script.
Check the javascrip console"
The error message in the javascript console is:
Error: uncaught exception: [Exception... "Component returned
failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsILocalFile.initWithPath]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "JS frame ::
chrome://slogger/content/slogger.js :: sloggerExecProfile :: line
627" data: no]
Also, when I go back to the "Custom Script" tab, my code has
been changed! It no longer contains the escaping slashes, for
example:
a = a.replace(new RegExp(/\//gi), "_");
... is now ...
a = a.replace(new RegExp(///gi), "_");
So close, yes? Maybe just a little tweak? : )
Mook
http://www.themook.net
On 16 Feb 2006 at 19:44, slogger at mozdev.org wrote:
> Hi again!
>
> That javascript produced two identical alert boxes, both with the
> unmodified URL of the page I was on - I tinkered a little bit (I
> don't actually know javascript, but found some example scripts
> here and there) and came up with:
>
> var a = sloggerGetVar("url");
> alert(a);
> a = a.replace(new RegExp(/:/), "_");
> alert(a);
> sloggerSetVar("url",a);
>
> When I "test" this code (within Slogger's pane) it opens an alert
> box with the unmodified URL, then opens a second alert box
> with the ":" changed to a "_" ... the problem is, if I change the ":"
> in that code to a "?", no alert boxes show at all, it's as if the code
> doesn't fire. Maybe the question mark "?" is protected in
> javascript.
>
> Anyway, thanks a bunch for trying to help me with this, I'm going
> to keep tinkering and see if I can figure this out. Feel free to
> throw any bones my way if you think of anything else : D
>
> By the way, I never actually mentioned in any of my posts, it
> was somewhat implied - but I think Slogger is a fantastic
> extension. It saved me literally hours and hours of laborious
> fiddling by automating site captures so easily. Nice job!
>
> Mook
> http://www.themook.net
>
>
>
> On 16 Feb 2006 at 16:29, Ken Schutte wrote:
> > For now, to at least get that information stored, you could make a log
> > file that maps filename to the url. for example, set the saved page to
> > be (like the default):
> > $year-$month-$day_$hour-$minute-$second-$millisecond.$typeext
> > and create log file with the content of:
> > $year-$month-$day_$hour-$minute-$second-$millisecond.$typeext $url
> >
> >
> > Or you can try entering something like this in the "Custom script" tab
> > (I haven't tried this...),
> >
> > var a = sloggerGetVar("url");
> > alert(a);
> > a.replace(/\:/g, "_");
> > a.replace(/\?/g, "_");
> > a.replace(/\//g, "_");
> > alert(a);
> > sloggerSetVar("url",a);
> >
> > the alert() lines will let you know if it's running and if the character
> > replacement works. Remove them if it does.
> >
> > Ken
> >
> >
> >
> > mook at themook.net wrote:
> > > Hi Ken,
> > >
> > > Thanks for the quick turnaround : )
> > >
> > > The pages I have archived in the past were saved along the
> > > lines of:
> > >
> > > Original Remote Site
> > > http://www.site.com/article.html?id=001
> > > http://www.site.com/article.html?id=002
> > > http://www.site.com/article.html?id=003
> > >
> > > Local Files
> > > http _www.site.com_article.html id=001.html
> > > http _www.site.com_article.html id=002.html
> > > http _www.site.com_article.html id=003.html
> > >
> > > Local Directories
> > > http _www.site.com__article.html id=001_files
> > > http _www.site.com__article.html id=002_files
> > > http _www.site.com__article.html id=003_files
> > >
> > > It looks like "/" became "_", and "?" became " ", etc. I'm afraid I
> > > have no idea how to recreate that with a custom javascript
> > > though - I have just enough knowledge to break things, but not
> > > enough to actually be competent : D
> > >
> > > The part of the URL I'm really trying to retain is the "id=00X"
> > > part - without that I have no idea what the article actually is (I
> > > have a spreadsheet that lists the names of the articles and their
> > > corresponding numbers). If I archive only based on a time-date
> > > stamp, it leaves me no way of knowing which article a particular
> > > file refers to. Is there another variable I might be able to use for
> > > that? (I've tried "$filename" and "$path" with no luck).
> > >
> > > Thanks!
> > >
> > > Mook
> > > http://www.themook.net
> > >
> > > On 16 Feb 2006 at 15:08, Ken Schutte wrote:
> > >
> > >>Hi,
> > >>
> > >>I believe the problem is that it's generating invalid filenames. The
> > >>$url variable holds the full url, which could be
> > >>"http://www.asdf.com/adsf?a=1;b=2" or something. From saved pages in
> > >>the past, what would the final filename be for something like this? Did
> > >>it escape some characters or just remove them?
> > >>
> > >>Some of the old Slogger code used to have a copy of some of Mozilla's
> > >>code for saving pages. In newer Slogger, some of these functions were
> > >>implemented differently, but I can try to find this part that cleaned up
> > >>the filename and put it back in there.
> > >>
> > >>In the meantime, it might be possible in the current version if you
> > >>change $url variable in a custom javascript, although it's a bit
> > >>complicated... somthing like:
> > >>
> > >>var a = sloggerGetVar("url");
> > >>// modify a, replacing bad chars
> > >>sloggerSetVar("url",a);
> > >>
> > >>Ken
> > >
> > >
> > >
> > > _______________________________________________
> > > Slogger mailing list
> > > Slogger at mozdev.org
> > > http://mozdev.org/mailman/listinfo/slogger
>
>
More information about the Slogger
mailing list