Boilerplate code:
mw.hook( 'wikipage.content' ).add( $content => console.log( $content ) );
What element $content contains:
- When viewing a page: #mw-content-text
- When editing a page - no preview: #mw-content-text
- When editing a page - during a regular preview: #mw-content-text
- When editing a page - during a live preview: .mw-content-ltr ⚠️
This should be made consistent. Case in point, a bug varying whether live preview is enabled or not, would be quite unexpected and hard to spot.
Note that on edit pages, #mw-content-text also contains the edit interface, whereas .mw-content-ltr contains only the wiki page content. Though, I think we should unify to #mw-content-text, if we consider that on an edit page, the "page content" is actually the edit interface, which may include a page preview. Also, that's what the regular previews (probably much more widespread) already do.
By the way, there is still no element designed for getting just the wiki page content… So far, I'm mainly using $content / #mw-content-text, but have already encountered several, quite unexpected issues (for example on diff pages), that I solved by adding a .find( '.mw-parser-output' ) (and $( '.mw-parser-output' ) can't be used directly, as .mw-indicators also contains an occurrence of it).
Some refs: