Wikipedia:User scripts/Guide: Difference between revisions
Content deleted Content added
→Built-in scripts: Clarified some wording. |
→Userscript structure: Some wording fix and some code prettifying. |
||
Line 16:
== Userscript structure ==
<source lang="javascript">
Line 22:
function myScript(){
//... code ...
};
//Schedule it to run after the HTML page is rendered
addOnloadHook(myScript);
</source>
Since the function is called only once, many users prefer to shorten this code with an "anonymous function call":
<source lang="javascript">
addOnloadHook( function() {
//... code ...
} );
</source>
Many scripts use this function simply to add some script interface, such as a link in a leftside portlet. Then the main part of the code is executed after the user clicks on that link.
== Editing and loading the user script ==
|