Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Text editors and debugging: this was written in 2007; in 2024, any mainstream editor supports UTF-8
m Your first script: formatting
Line 40:
<syntaxhighlight lang="javascript">
// Qwikify
$( document ).ready( function () {
MODULE_CODE;
} );
</syntaxhighlight>
 
In <code>MODULE_CODE</code>, we want to add the "Wikify" tab, so we will use the [[mw:RL/DM#addPortletLink|<code>addPortletLink</code> function]] (which requires the <code>mediawiki.util</code> module). Replace <code>MODULE_CODE</code> with a call to this function. Then we'll bind an event handler so that when this link is clicked, we will call another function named <code>doQwikify()</code> that will actually execute the code. The <code>name</code> is what is shown on the tab, so set that to <code>'Wikify'</code>. Most tabs have an idID of "<code>ca-(their ''name)"''</code>, so set the idID to <code>"'ca-wikify"'</code>. The title (also known as [[mouseover]] or [[rollover]] text) should be something like <code>"'Mark for wikification"'</code>. Lastly, we use jQuery's [//api.jquery.com/click/ .click()] to listen for clicks on this link, and when that happens, execute a function. After we call <code>doQwikify()</code>, it says <code>event.preventDefault()</code>. Since we clicked on a link, we need to tell the browser to prevent its default behavior (which is going to a the url, <code>'#'</code>). We want the page to stay right where it's at, so to prevent the browser from following the link, we prevent that and do our own custom action.
 
Altogether, your new function should look like this: