Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Text editors: Should code folding really count as a recommended feature in this guide? I can't speak for others, but let's say I never use it.
Line 121:
 
=== <code>mw.hook('wikipage.content').add(...)</code> ===
However, if your code works with the content part of the page (the <code>#mw-content-text</code> element), you should use the <code>[https://doc.wikimedia.org/mediawiki-core/master/js/Hooks.html#~event:'wikipage.content' 'wikipage.content']</code> [[Hooking|hook]] instead. This way your code will successfully reprocess the page when it is updated asynchronously and the hook is fired again. There are plenty of tools which do so, ranging from edit preview to watchlist autoupdate.
 
Be sure to only work with the descendants of the <code>$content</code> element that your handler function takes and not the whole page. Otherwise, you may end up running the same code for the same elements many times. Note that the <code>'wikipage.content'</code> hook may be fired ''really'' many times.