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?
Saturday, 3. March 2007, 20:16:28
Sunday, 8. April 2007, 08:25:46
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, 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
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
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, 15:35:11
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
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
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.
Friday, 27. July 2007, 18:19:04
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
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
Saturday, 28. July 2007, 16:00:00
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
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'
Friday, 31. October 2008, 23:29:10
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
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, 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.
Forums » Opera Community » General Opera topics » User JavaScript
