Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Finding elements: capitialization
Checking the page: New mw.config usage
Line 187:
Many scripts are supposed to work only on some pages. You can check:
 
* The page address
<source lang="javascript">
if (document mw.URLconfig.indexOfget( 'action=historywgAction' ) !=== 'history' -1) {
//continue only on history pages
</source>
* <tt>wg</tt> variables; many of them have the same meaning as [[Help:Magic words|Magic words]]
<source lang="javascript">
if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User_talk') {
//continue only on User_talk pages
</source>
* presensePresence of elements (only in 2nd and 3rd parts of the script)
<source lang="javascript">
function func_start () {
if (!document $( '#editForm' ).editformlength == 0 ) return; //no edit form → exit
//
</source>