Most web pages use something called cascading style sheets (CSS) to control the way the page looks (the colours, the positioning, the fonts used and so on). Normally the web page author has complete control over how the page looks; Opera however has a very powerful mechanism (UserCSS) for changing the styling on any page — it allows layering your styles onto the page, or replacing the authors styles completely. Thus if you prefer only your paragraph font size to be larger for all pages, then Opera allows you to do this. You can toggle such user styles on and off too. This means you can start to take control of the way you view information on the web.
One problem with this was being able to specify changes to parts of just one web site. With the release of Opera 8 this situation has improved. Using user javascript (UserJS), we can rewrite each page to include a signature; a unique identifier that then allows our styles to have ultimate control. As an exercise, we will restyle the Google search page.
To start with, we need to install our user javascript (you don't need to understand how this works) that adds a unique signature to each page. The javascript code is shown below (many thanks to Moose and Tarquin who wrote the code):
// ==UserScript==
// @exclude http://mail.google.com
// ==/UserScript==
function myRootSignature() {
var d=document.documentElement;
var locHost = location.hostname.replace(/^www\./g,'').replace(/\./g,' ');//replaces dots with space
locHost = locHost.replace(/[^\w- ]/g,'');//removes IDN characters
locHost = locHost.replace(/\b(\d)/g,'_$1');//prepends leading numbers with underscore
d.className = (d.className?(d.className+' '):'') + 'mycss' + ' ' + locHost;
//alert(document.documentElement.className);
}
var myDoneNums = 0;
var myCheckNode = setInterval('myDoneNums++;if(document.documentElement){clearInterval(myCheckNode);myRootSignature();}else if(myDoneNums>6){clearInterval(myCheckNode);document.addEventListener("load",myRootSignature,false);}',200);
To install this in a fresh install of Opera 8 we need to do the following:
To test that this is working, you can edit the rootsig.js file and remove the comment in front of the alert line:
//alert(document.documentElement.className);
into
alert(document.documentElement.className);
Now if we load up a page, we should see an alert box showing us the signature for the page (once we have confirmed the script is working, we can add back the // to that line, otherwise we will get annoying alerts on every page we visit!)
The next part requires us to install a user CSS file, and this file will be able to hook into the signature our pages now have.
As you may notice, the script adds the domain name seperated by spaces as CSS classes to the HTML element of each web page. So if we vist google.com the assigned classes become mycss google com; and if we visit gmail.google.com they become mycss gmail google com. Therefore we can use the following syntax to target the pages specifically:
html.mycss.google {background-color: red !important; padding: 50px;}
html.mycss.google body {background-color: yellow !important;}
html.mycss.gmail.google {background-color: green !important; padding: 50px;}
html.mycss.gmail.google body {background-color: blue !important;}
This will make the background of google.com red/yellow, but gmail.google.com will go green/blue.
Very Nice.
-RE
82.123.103.209 (2005-04-27 11:16:20)
Really nice this thing! Great Work guys.
Olaf
213.196.221.127 (2005-04-29 02:45:11)
The stylesheet doesn't appear in the menu with the others css. I'm under Linux with Opera 8.02, does this only work with Windows ?
82.121.202.193 (2005-08-01 07:52:02)
Ok, i've found the solution by myself.
If the tutorial above doesn't work for Linux users (or maybe others) do this :
copy the file userstyle.ini in /usr/share/opera/styles/user in your profile directory .opera/ Then, add your stylesheet in this file like showed above.
82.121.64.210 (2005-08-03 11:54:52)
In the section "Setting up the User Javascript" on this page, when does it need? How much is it useful? I think it is useless, annoying alerts.
Of course I know of removing the comment in front of the alert line.
222.108.60.62 (2005-08-19 17:14:44)
Without the User JS this technique will not work. There is no point complaining about the popup - just comment that line out (which it is by default!)
NonTroppo (2005-08-23 07:07:01)
I am having the same problem as the previous poster in Linux. The custom styles just don't show up in the menu. His solution works for me. It seems kinda dirty, though.
dakira
213.39.212.192 (2005-10-16 20:32:09)
Has anyone been able to adapt the mystyles.css file and adapt it to work with the new site specific stylesheet options available on Opera 9?
I can't quite get it to look right.
12.33.93.190 (2005-10-31 11:58:15)
I am using Mac OSX and I can't find 'opera6.ini' anywhere.
Is there another name I could search for? I looked in Opera Preferances and Opera 6 Prefs.
I used the OS search function to look for 'opera6'
No luck.
Now what?
Thanks
Jon
220.112.58.16 (2006-05-05 18:52:36)
comment6, <a href= www.atfreeforum.com/freeamateursext > try amateur casero de foto gratis sexo </a>, [url=www.atfreeforum.com/freeamateursext]try amateur casero de foto gratis sexo[/url], www.atfreeforum.com/freeamateursext try amateur casero de foto gratis sexo, pip, <a href= www.phpbber.com/phpbb/adultamateurcou.html > try amateur sex video clip </a>, [url=www.phpbber.com/phpbb/adultamateurcou.html]try amateur sex video clip[/url], www.phpbber.com/phpbb/adultamateurcou.html try amateur sex video clip, >:DDD, <a href= www.setbb.com/amateursexphoto > try amateur sexy models.com </a>, [url=www.setbb.com/amateursexphoto]try amateur sexy models.com[/url], www.setbb.com/amateursexphoto try amateur sexy models.com, >:-P, <a href= www.makephpbb.com/phpbb/amateurhomemade.html > free amateur home sex pic </a>, [url=www.makephpbb.com/phpbb/amateurhomemade.html]free amateur home sex pic[/url], www.makephpbb.com/phpbb/amateurhomemade.html free amateur home sex pic, 539, <a href= www.freeyabb.com/phpbb/amateurgangbang.html > free amateur british movie sex </a>, [url=www.freeyabb.com/phpbb/amateurgangbang.html]free amateur british movie sex[/url], www.freeyabb.com/phpbb/amateurgangbang.html free amateur british movie sex, cuo, <a href= s8.createphpbb.com/amateurrealsexs > try amateur sex photo gallery </a>, [url=s8.createphpbb.com/amateurrealsexs]try amateur sex photo gallery[/url], s8.createphpbb.com/amateurrealsexs try amateur sex photo gallery, :-((, <a href= www.makephpbb.com/phpbb/amateurmatchsex.html > try amateur fuck sexy </a>, [url=www.makephpbb.com/phpbb/amateurmatchsex.html]try amateur fuck sexy[/url], www.makephpbb.com/phpbb/amateurmatchsex.html try amateur fuck sexy, 1094,
205.178.184.113 (2008-08-05 20:57:27)
uIHWFe It`s really useful! Looking through the Internet you can mostly observe watered down information, something like bla bla bla, but not here to my deep surprise. It makes me happy..!!
193.105.210.170 (2012-02-10 23:09:42)
An impressive share, I just given this onto a colealgue who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!
184.169.141.213 (2012-07-10 09:06:28)
Hey! Thanks for the great tutorials!
Just found a small typo, which made me scratch my head for a sec.
In the section "Adding a User stylesheet" on this page, it shows the text to be inserted into opera6.ini:
File 12=PATH\TO\mystles.css
which should be
File 12=PATH\TO\mystyles.css
(missing y)
I copy&pasted, changed the path and wondered why it didnt work ;)
134.176.204.74 (2005-04-26 09:09:41)