Wikipedia:User scripts/Guide: Difference between revisions
Content deleted Content added
m Reverted edits by Shahroozmontana to last revision by Zvn (HG) |
update |
||
Line 11:
* More than 30 project-, page- and user-specific variables at the top of the rendered HTML page.
* [{{SERVER}}/skins-1.5/common/wikibits.js wikibits.js]
* [[MediaWiki:Common.js]] (as [{{SERVER}}{{SCRIPTPATH}}/index.php?title=-&
* The user's own [[Special:MyPage/
== Userscript structure ==
The personal <tt>/
<source lang="javascript">
Line 39:
== Editing and loading the user script ==
=== Previewing in /
You can edit your script directly on your [[Special:MyPage/
=== Saving in /
If required elements are missing on the preview page (for example, your script does something on history pages), you will have to save the script in order to test it.
Line 61:
=== Load from a localhost web server ===
The best and most recommended way is to load a JavaScript file from your local web server. (See below for an easy way to install a web server.) Put this string in your [[Special:Mypage/
<source lang="javascript">
Line 67:
</source>
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>/
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]].)
Line 97:
=== Publishing your user script ===
Once you have finished the user script code you either need to paste it into your <tt>/
<source lang="javascript">
Line 105:
== CSS files ==
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>/
Instead you can load a CSS file from your local web server. (See previous section for an easy to install web server.) Put this line at the very top of your [[Special:Mypage/
<source lang="css">
@import "http://localhost/wikipediatest.css";
</source>
'''Note!''' Such <code>@import</code> statements must come before any other declarations in your <tt>/
An alternative way is to put this line anywhere in your <tt>/
<source lang="javascript">
Line 121:
=== Publishing a CSS file ===
Once you have finished the CSS code you either need to paste it into your <tt>/
<source lang="javascript">
Line 129:
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. Users can import your <tt>User:Yourname/yourscript.css</tt> from their <tt>/
<source lang="css">
@import "/w/index.php?title=User:Yourname/yourscript.css&action=raw&ctype=text/css";
Line 242:
<source lang="javascript">
//Example: add the link into «toolbox» portlet
addPortletLink ('p-tb', '/wiki/Special:MyPage/
</source>
Line 260:
<source lang="javascript">
//Example: using innerHTML to create a new portlet
document.getElementById('p-
'</div>'+
'<div id=
'<h5>mine</h5>'+
'<div class=
'<li><a href=
</div>'; </source>
Line 284 ⟶ 285:
</source>
This is easier with [[Special:Mypage/
== Edit page ==
|