Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Finding elements: possessive ''its'' instead of contraction ''it's''
Call from Monobook.js: Adding explanation how to load CSS files from a local web server.
Line 239:
However it's not convinient and creates unnecessary load on WikiMedia servers.
 
=== CallLoad from Monobook.jsa localhost web server ===
 
The best and most recommended way is to insert into your <tt>monobook.js</tt>
 
<source lang="javascript">
importScriptURI( 'http://localhost/testwikipediatest.js');
</source>
 
Then run any [[webserverweb server]] on your computer and create the <tt>testwikipediatest.js</tt> file in the appropriate folder. The code inside this file will be executed as if it was inside your <tt>/monobook.js</tt>.
 
You can edit your <tt>testwikipediatest.js</tt> file with any text editor, perhaps with syntax highlighting and other convinientconvenient features, then save the file and simply updatereload any Wikipedia page to see the results.
 
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>testwikipediatest.js</tt> and any file <tt>index.html</tt> (required). Start TinyWeb with this shortcut; unload it with Task Manager.
 
==== CSS files ====
 
In the same way you can load a CSS file from your local web server. Put this string at the very top of your <tt>/monobook.css</tt> :
<source lang="css">
@import "http://localhost/wikipediatest.css";
</source>
Note that such <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 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>
 
=== Other methods ===