summon muppets
Per petitionem et promissum,
vos voco, ex fibra et filo, tredecim.
Per petitionem et promissum,
vos voco, ex fibra et filo, tredecim.
The Muppet Wiki runs on MediaWiki, so it has the MediaWiki Action API at muppet.fandom.com/api.php. Every request includes origin=*, which lets a browser on another site call it without a login.
The first time you press 'summon muppets' the code sends action=query with list=categorymembers for Category:The_Muppets_Characters. It asks only for articles (cmnamespace=0), up to 500 per request. If the response includes a cmcontinue token, it asks for the next page until it has at least 500. It filters out disambiguation pages and keeps the title and page ID of each muppet. The list is saved in a variable, so the next time you press 'summon muppets' it skips the request; a page refresh clears it.
The code copies the list and shuffles it with a Fisher–Yates shuffle: it goes from the last item to the first and swaps each one with a random item at or before it, so every order is equally likely. Then it takes the first thirteen.
One action=query request asks for all thirteen pages at once. It joins their page IDs with | and uses prop=pageimages to get the main image of each page. Then the code sends one action=parse request per muppet for section 0, which is the start of the page. All thirteen requests run at the same time, with Promise.all. Each response is HTML. The code reads it with DOMParser, which builds a separate document that does not load images or run scripts, and takes the text of the first <p>.
For each muppet, the code builds a list item with a name, a description and an avatar. It changes the image URL to Fandom's scale-to-width-down/200 version, which gives an image 200 pixels wide. If that doesn't load it tries the full-size image.
Each time you press 'summon muppets', the code clears the list, shuffles again and shows thirteen new muppets.