Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
m Finding elements: <code> → <syntaxhighlight>
Line 263:
Many scripts are supposed to work only on some pages. You can check:
 
* The page type<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
if ( mw.config.get( 'wgAction' ) === 'history' ) { // Continue only on history pages.
</syntaxhighlight>
* [[:mw:Manual:Interface/JavaScript#mw.config|<kbd>wg</kbd> (Wikimedia global) variables]]; many of them have the same meaning as [[Help:Magic words|Magic words]]<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User_talk') { // Continue only on User_talk pages.
</syntaxhighlight><syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
if ( mw.config.get( 'wgPageName' ) === 'Article_name' ) { // Continue only for the article "Article name".
</syntaxhighlight>
 
* Presence of elements (only in second and third parts of the script)<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
function func_start() {
if ( $( '#editForm' ).length == 0 ) return; //No edit form ? exit