You need to be logged in to post in the forums. If you do not have an account, please sign up first.
text-replacement-utf-8.jsAnd again, few month after publishing on russian operafan.net forum I eventually decided to publish here few of my scripts. Some decent ones I'm not ashamed of.
text-replacement-utf-8.js (discussion on operafan).
Script is encoded in UTF-8, and that is necessary for correct interpetation of non-ASCII and Unicode symbols. First 'unneeded' semicolon is necessary too. Don't change it.
You can add your own replacements like (to replace 'foo' to 'bar'):
You can make some formatting in replaced text:
But it is recommended to make formatting with CSS in 'replacedText' tag:
There are more advanced examples in script.
And make sure that replacement doesn't contain replaced text or you will face recursive and infinite cycle.
It uses DOM iterators to traverse text nodes, so speed is better that it might be, but still is an issue if you have are viewing big pages (>1Mb).
You can do something like:
But speed... Especially in case when you have many replacements...
I've squashed few bugs and tried to improve functionality:
Fixes, to make it work on any page.
Script won't do replacements on a big pages to prevent lags.
Ignoring contents of PRE tags.
Thanks everyone for feedback.
Now, next part is for js-geeks.
To filter some branches from the DOM-tree (to properly ignore all contents of PRE, STYLE, SCRIPT nodes), first i've converted script to TreeWalker but speed degraded by visible extent, so i decided to keep on with NodeIterator, but i had to use data directly attached to DOM nodes, to hash hiearchy information and it's kinda obtrusive...
Those interested may have a look to a TreeWalker version.
Originally posted by xErath:
How about a xpath snapshot ?
I am writting this script mostly for myself, and i still use 8.52 for my everyday browsing.
But i may add this, even if i won't use it for now...
Not for me
I save it on my Profile\UserJS folder and restarted Opera, but it seems not working :´(
I created a UserJS folder into my own profile folder (C:\Documents and Settings\<MyUserName>\Application Data\Opera\Opera\profile\UserJS\)
Then I copied the text-replacement-utf-8.js file into that folder.
It's the one file into that folder.
I restarted Opera.
Then I go to the sample page at http://my.opera.com/profiT/homes/files/logotyps.htm but nothing happens! I don't see the text translated into logos
I looked the logs of my VirusScan and appears it is NOT blocking me :O
I didn't read the UserJS tutorial, but I guessed it was as easy as the steps I did. I'm wrong?
Opera 9.1 final, WinXP SP2
Have you tried relocating your userJS folder (to make it "c:\userJS", for example)?
And your error console (Tools -- Advanced -- Error console)? Does it say anything?
Or maybe site-preferences for my.opera.com?
By the way, i've just updated script a bit. Nothing really useful, just added few embedded images in two logos ('Google', 'Firefox') and support for them to script.
But then I copied the script into my profile again, and setted this folder as the userJS folder (again). After the weekend, I turned ON my PC and it works too!!!
As stated in my post in the thread "[Req] my.opera.com emoticons everywhere":
I'm using the Opera's IRC client + BitlBee ( http://bitlbee.org - an IRC to other chat networks gateway) for my chat needs.
But then I can't see the smilies I send/receive (besides the few supported by M2)!
So I'm making a custom menu with all the smilies used in MSN messenger and the MyOpera forums. I already got the images, put them into a test skin, and created the menu. I click on the smiley and the menu inserts the proper text.
But then I need a way to also interpret a received text and translate it into a smiley! This is why I want this UserJS working
But seems this JS don´t works on M2 or the IRC client I did send a mail to myself with the string "^_^" and it wasn´t translated into a smile.
See the replys of philry4n to my post.
Can you help? Thank you!
How about using the IM.CSS file for this?
22. February 2007, 15:53:53 (edited)
I changed a skin, creating a MSN folder into the smilies folder and putting into it all the MSN emoticons.
In the skin.ini file I have a line like this:
Emoticon MSN_embarrassed = smilies/MSN/embarrassed.png
Then I zipped again the skin and make it the current skin.
Then I changed the script to translate '^_^' to the MSN's embarrassed emoticon
'^_^', '<replacedText style=\'display:inline-block; width: -o-skin; height: -o-skin; background-image: -o-skin("Emoticon MSN_embarrassed")\'></replacedText>',
Then I opened a test .htm page with the '^_^' string and it was translated to the correct emoticon!!
But when I see a mail I send to myself with the same string, it wasn't translated.
So IT IS possible to use addittional emoticons, but not into M2 (and I guess into the IRC client too)
- Now replacements have pop-up hints with original text.
- Clicking on replacement will disable them (all of them on the page), click again -- and they will show up again.