Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Reverting edit by Alex Smotrov. You must have done some mistake, it works fine in my Opera 9.02 on WinME. But please add the way you load your localhost .js just in case.
CSS files: Reworking this section. More explanation, more examples.
Line 253:
For example you could use [http://www.ritlabs.com/en/products/tinyweb/ TinyWeb] which is less than 100kbyte on disk and doesn't require installation. Save and unzip <tt>tinyweb.zip</tt> for example into <tt>c:\Program Files\Tinyweb</tt>, then create a shortcut to <tt>tiny.exe</tt>, in shortcut properties add an argument — path to your folder with <tt>wikipediatest.js</tt> and any file <tt>index.html</tt> (required). Start TinyWeb with this shortcut; unload it with Task Manager.
 
==== CSS files ====
 
InSome theuser samescripts wayalso youuse cansome loadCSS acode, CSSor fileeven fromare yourbuilt localwith webCSS serveronly. PutThen thisyou stringneed atto thecode veryand toptest ofCSS code. That can be done in your <tt>/monobook.css</tt>, :but that is slow and messy.
 
Instead you can load a CSS file from your local web server. (See previous section for an easy to install web server.) Put this string at the very top of your [[Special:Mypage/monobook.css|/monobook.css]]:
<source lang="css">
@import "http://localhost/wikipediatest.css";
</source>
'''Note!''' that suchSuch <code>@import</code> statements must come before any other declarations in your <tt>/monobook.css</tt>. But there can be <code>/* comments */</code> above them.
 
Once you have finished the CSS code you either need to paste it into your <tt>/monobook.css</tt> if it is only for personal use. Or if it is for use by others then you should upload it to for instance [[Special:Mypage/yourscript.css|User:Yourname/yourscript.css]]. Then other users can import it by putting this line in their <tt>/monobook.js</tt>. Note, that is in their ".js", not their ".css".
 
Once you have finished the CSS code you need to upload it to for instance [[Special:Mypage/yourscript.css|User:Yourname/yourscript.css]]. If it should be used together with a user script written in JavaScript then from the JavaScript you can load the CSS file with this line of code:
<source lang="javascript">
importStylesheet( 'User:Yourname/yourscript.css' );
</source>
 
If the CSS should be used together with a user script written in JavaScript then you can make it easy for the users. Simply put the line above in the JavaScript code for your user script, then the users only need to "install" your JavaScript.
 
For completeness, in case someone wonders. You can import your <tt>User:Yourname/yourscript.css</tt> from your <tt>/monobook.css</tt> too, although that takes this rather messy line of code:
<source lang="css">
@import "/w/index.php?title=User:Yourname/yourscript.css&action=raw&ctype=text/css";
</source>