User:Sophivorus/ExcerptTree.js

/**

* ExcerptTree is a script to view and navigate excerpt trees in Wikipedia

* Author/Maintainer: Sophivorus

* Expected use will be via ?withJS links, so may not appear in what-links-here

*/

var ExcerptTree = {

/**

* Initialization script

*/

init: function () {

$( '.ExcerptTree' ).show();

$( '.ExcerptTree li' ).each( ExcerptTree.addChildren );

},

addChildren: function () {

var node = $( this ),

title = $( node ).children( 'a' ).attr( 'title' );

ExcerptTree.getChildren( title ).done( function ( data ) {

//console.log( data );

var content = data.query.pages[0].revisions[0].slots.main.content;

var matches = [...content.matchAll( /{{ *[Ee]xcerpt *\| *([^}]+) *}}/g )];

//console.log( matches );

if ( matches.length ) {

ExcerptTree.addButton( node );

var list = $( '