Sign up | Lost password? | Help

[ advanced search ]

Convert2PHF.js script -- saving in single htm file

Forums » Opera Community » General Opera topics » User JavaScript

Sunday, 10. December 2006, 10:58:46

Convert2PHF.js script -- saving in single htm file

I think, i've (at last!.. worked on it for year already) made idea about JS PHF-converter to something almost usable.

UserJS: Convert2PHF.js.

And the button button (they are supposed to work together).

After you pressed the button script will start converting, it can take some amount of time. When it will be done you'll see the save dialog.

If you want saved pages to have extension, you can change it in Alt-P, Advanced -- Download, typing "htm" in "Extension" field for "text/phf" MIME-type.

It saves the page, its images, styles and scripts into one single page you can save to local disc.

Images are converted to "data:" base64 format using canvas and toDataURL() function. There were (and are) issues with transparency i tried to workaround, but it works as expected on most pages i tested. If you will try to get the contents of an image from different domain with toDataURL() it will start to grumble saying "security error", so script saves images only from current server.

Styles are converted and injected to the page too. Alternate styles are destroyed to save size, but it is not very hard to save'em too.

Issues so far:

1. Test encoding. Especially <TITLE> text.
2. Images with transparency.
3. Looks like that saving with MIME-type is not robust enough: sometimes it just stops on some place.
4. It is really, really slow. Whether on saving or on opening saved page.
5. Only Opera and Firefox are capable to open such pages. IE is off. Hey!.. That's not problem, for me at least.

So, what do you think?

Monday, 11. December 2006, 05:16:32

xErath

javascript guru

avatar

Posts: 6404

Norway

Opera Software

Originally posted by profiT:

4. It is really, really slow. Whether on saving or on opening saved page.


It's Opera's base64 decoder/encoder that is slow, from my experiences.

Saturday, 3. March 2007, 20:16:28

I've updated script, and now it works much more reliable -- no more saving half-pages. And i've tried to work around images with transparency. But encoding troubles still persists.

Sunday, 8. April 2007, 08:25:46

Mikivanch have heavily updated script (with my little assistance) to the version 2.64:

Convert2PHF.js script.

Draggable button: button.

[img]http://www.puzzleclub.ru/files/convert2phf_2.64.png

As you can see from screenshot now you can choose to save all images or images only from current domain. Also, you may choose not to save flash-<object>'s and embed in result PHF-page. The same is for scripts.

Numerous bugs i was too lazy to fix in old script, were successfully squashed by Mikivanch. Saving is much more reliable and accurate now. Script catches security-exceptions, when Opera thinks that you gone too far. It doesn't break fonts anymore (we had to write special workaround for this, since it was Opera's CSS-treatment bug), it processes all background-images in CSS.

As a bonus of fact, that script's saving live DOM-snapshot of the page, buttons like Kill-button or MyPage bookmarklet starts to have much more sense in Opera now, because now we can save the results.

Sunday, 8. April 2007, 18:13:01

Krake

avatar

Posts: 1382

Germany

I like this script :smile:
It has 3 major advantages over Opera's implementation of MHT format.
1. You can open the saved file in every browser.
2. Easy editing of the saved file.
3. It works on sites where Opera's MHT fails (absolute/relative URL)

Sunday, 8. April 2007, 19:13:23 (edited)

Originally posted by Krake:

1. You can open the saved file in every browser.


You probably meant to say: 'in every decent browser'. IE can't handle data: images.

And there is another advantage: script doesn't use any external programs or libraries or hooks. Just a 'mere' JS. This should give cross-platformness to script, but we haven't tested it in Linux yet.

Wednesday, 16. May 2007, 12:59:30

We have worked on script for a quite a while since the last announcement in this thread. Few users from russian operafan.net forum have tested and gave feedback. So i decided show something in here too:

Convert2PHF.js test version 3.20

This version sports an interesting (at least for some of you, i believe) feature -- saving pages to MHT.

1. Why not? (main reason, i have to admit). To implement saving to MHT in pure JS -- isn't it the challenge?..
2. Opera's saving to MHT is not perfect (yet?..). See: 1, 2, 3, 4 and many other threads.

Button hasn't changed: button.

Preferences you made are now saved (using cross-document cookies).

Dialog with a new options:
[img]http://www.puzzleclub.ru/files/convert2phf_2.71.png

"Remove inline frames" -- remove from DOM-tree all <iframe> elements, so the won't be in resulting PHF or MHT.
"Remove embedded content" -- the same as with iframes, bit this tick removes <embed> and <object> elements.
"Clean web page" (doesn't work on local pages) -- is used to get rid of 'panels' that was created by UserJSs and other garbage or modifications we don't want to see in saved file. Additional XMLHTTPRequest is made to get the original source without affecting UserJS or UserCSS.

Saturday, 19. May 2007, 18:03:36

One of the good things about making save capability on JS is that is doesn't depend on Opera's internal decisions what to save and what to leave as external link.

For example, if you have page with images (DTF.RU, for example) whose 'src' attribute looks like: 'http://dtf.ru/articles/image.php?id=24938', this images won't get it to the saved html page. While convert2PHF.js will treat this pictures as external and save them as well as other pictures.

Sunday, 20. May 2007, 13:10:25

Krake

avatar

Posts: 1382

Germany

Thanks for the heads-up!

Sunday, 20. May 2007, 15:35:11

thanks profiT
your script is almost perfect, but i think using the page title as default name will not be hard for guru like you

Sunday, 20. May 2007, 19:51:11

Originally posted by Khaled Khalil:

thanks profiT
your script is almost perfect, but i think using the page title as default name will not be hard for guru like you



Unfortunately, there is nothing i can do here. There was a little tricko-hack when you could choose a name for file, you were saving with data: URI but it is blocked since Opera 9 versions. Now Opera always chooses 'default' as.. ehm.. default name for saved file.

You can only set extension to 'html' or 'htm', in 'text/phf' content-type properties.

Probably it can be done using VBS or with some other method (resident external program, dll-hook like in OBook), but i just don't like it.

Monday, 21. May 2007, 19:18:06

The script doesn't work for me if also have Link Alert installed, the save dialog simply doesn't come up.

If you don't have the time I can probably get around to finding the cause eventually, but I'm posting here with the hope it can be found faster.

Monday, 21. May 2007, 19:34:47

While i don't usually use link-alert regularly, right now it is plugged on due to an other issue which i'm trying to overcome now.

And yes, yesterday i noticed that that convert2PHF.js just stops after you press 'OK', doing nothing. Needs to be examined (gotta sleep now).

By the way, the reason i don't use link-alert is that it is very obtrusive and troublesome. If you're not getting problems with link-alert itself it spoils some other scripts' work.

Tuesday, 22. May 2007, 14:18:42

BtEO, here it is:

Convert2PHF.js 3.21.

Thanks for feedback.

Friday, 27. July 2007, 18:19:04

GreyWyvern

Here there be puffins...

avatar

Posts: 282

Canada

Wow profiT, this is an incredible script! Works very well! :smile:

However, I am wary about how it seems to send a portion of the document.cookie to bce20b24-afdf-4482-b379-737f29497fa0.com further down in the script. What exactly is the reason for this? Saving preferences? I changed the domain above to "example.com" and the script still seemed to work.

Is there some other way you can manage what you're trying to do without sending the cookies to a frame at another domain? Until then I will always be worried about keeping this UserJS installed, despite how useful it could be.

Cheers.

Friday, 27. July 2007, 23:29:36

I presume by the use of a GUID it's designed to be a domain that will never exist and the cookies will never be readable by anything except this script.

Saturday, 28. July 2007, 10:11:00

Originally posted by GreyWyvern:

Is there some other way you can manage what you're trying to do without sending the cookies to a frame at another domain? Until then I will always be worried about keeping this UserJS installed, despite how useful it could be.


Until Opera won't add persistent storage we have to use this hack. For now, you can set 'preferenceParams' to this:

...
  preferenceParams : new Array(),
...


to forbid script sending the cookies to another domain.

Saturday, 28. July 2007, 14:46:58

GreyWyvern

Here there be puffins...

avatar

Posts: 282

Canada

Yesh, what with the recent goings on at userscripts.org, any userjs that handles cookies makes me more than a little nervous. I hope they implement persistent storage in an upcoming release.

Saturday, 28. July 2007, 16:00:00

GreyWyvern

Here there be puffins...

avatar

Posts: 282

Canada

I have a suggestion. :smile: How about inserting a <base href="..."> element so all the links point to the same URIs as the page you copied? Currently they all point to the local machine, where their targets obviously don't exist.

Saturday, 28. July 2007, 19:33:50

Originally posted by GreyWyvern:

Currently they all point to the local machine, where their targets obviously don't exist.


Mikivanch and i were planning to cycle through all links (<a>, <link>) turning them from relative to absolute. Neither of us have thought of <base>-tag. Thanks!..

Tuesday, 28. October 2008, 19:15:49

sergey-feo

avatar

Posts: 9

I have a problems with convert2phf 3.22 + opera 9.61 + Slackware 12.1.
This is contents of opera's errors console that pops up when opera starting:

JavaScript
User JS compilation
Syntax error /home/sergey_feo/.opera/user_js/convert2phf.js: line 1958 of User JS script :
Expected token: '}'
this.deleteCookie
-------------------^

This message repeated in errors console 4 times.

Then when pressing button for saving page as phf:

JavaScript - http://my.opera.com/community/forums/topic.dml?id=169593
Javascript URL thread: "javascript:(function(){opera.convert2PHF()})()"
Error:
name: TypeError
message: Statement on line 1: Type mismatch (usually non-object value supplied where object required)
Backtrace:
Line 1 of unknown script
function(){opera.convert2PHF()}
Line 1 of unknown script
(function(){opera.convert2PHF()})()
stacktrace: n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'

Wednesday, 29. October 2008, 10:51:15

I did an update for work in the last versions.

Friday, 31. October 2008, 23:29:10

cscat

avatar

Posts: 54

Canada

It doesn't work for me. I used the last version i.e. that created by Lex1:

I did an update for work in the last versions.



Although I have turned "open on console error" on but when I click on the (button made by ProfiT) it doesn't show any errors; it shows downloading/refreshing progress bar on my status bar and then does nothing, no save dialog appers.

I tested this simply on Google page.

my specs are:
Version 9.52
Build10108
PlatformWin32
SystemWindows XP
Java Sun Java Runtime Environment version 1.7

I don't have any other userjs installed so no conflict like link-alert.js issue and etc.

please help.

Saturday, 1. November 2008, 15:17:54

Did you create mime-type "text/phf"?

Also you can use the button Save snapshot. It don't support saving of images, but more safe.

Version 9.52


This version has critical vulnerability

Thursday, 6. November 2008, 15:15:39

cscat

avatar

Posts: 54

Canada

yes I added text/phf mime type. I wanted the ver. with image-saving feature!

Thursday, 6. November 2008, 17:01:28

I tested this simply on Google page.


It's work for me with latest Opera. Maybe, do try on other page?

with image-saving feature


Unfortunately, it non usable. Very slow and work only for the current domain. It's only concept.

Sunday, 28. December 2008, 11:24:08

JPushkarH

avatar

Posts: 73

Does this work on Opera 10 ?

It seams to be not working Here at

Version
10.00 alpha
Build
1139

Sunday, 28. December 2008, 19:34:35

Krake

avatar

Posts: 1382

Germany

Nope.
Let's hope the script will be updated till Opera 10 gets final.

Tuesday, 25. August 2009, 12:07:10

Nickko

Ergonome

avatar

Posts: 131

Belgium

Hi,

What is the difference with the Opera "save as" / "single archive" ?

Nickko

Forums » Opera Community » General Opera topics » User JavaScript