Wikipedia:User scripts/Guide: Difference between revisions
Content deleted Content added
→Structure: Changed to show the new cleaner "addOnloadHook( function() {" approach we use nowadays. |
→Debugging: Adding section "Publishing your user script" and some other fixes. |
||
Line 231:
-->
== Editing and loading the user script ==
=== Previewing in /monobook.js ===
Line 252:
Then run any [[web server]] on your computer and create the <tt>wikipediatest.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>wikipediatest.js</tt> file with any text editor, perhaps with syntax highlighting and other convenient features, then save the file and simply reload any Wikipedia page to see the results. (You don't need to wait, and if your web server is nice or you set it right you don't even need to [[Wikipedia:Bypass your cache|bypass your browser cache]].)
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.
=== Publishing your user script ===
Once you have finished the user script code you either need to paste it into your <tt>/monobook.js</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.js|User:Yourname/yourscript.js]]. Then other users can import it by putting this line in their <tt>/monobook.js</tt>.
<source lang="javascript">
importScript( 'User:Yourname/yourscript.css' );
</source>
=== CSS files ===
Line 260 ⟶ 268:
Some user scripts also use some CSS code, or even are built with CSS only. Then you need to code and test CSS 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
<source lang="css">
@import "http://localhost/wikipediatest.css";
Line 269 ⟶ 277:
<source lang="javascript">
importStylesheetURI( 'http://localhost
</source>
=== Publishing a CSS file ===
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".
Line 286 ⟶ 296:
=== Other methods ===
You can also debug your scripts:
* in [[FireFox]] with [[Greasemonkey]]
Line 306 ⟶ 317:
* [http://blog.monstuff.com/archives/000287.html JavaScript Shell for IE]
However a full-blown Javascript debugger is much more
-->
|