small Wikipedia text for inlining

Reddit Enhancement Sweet has a neat feature where if someone links to a Wikipedia article you can click on an expando button and a div pops up showing just a small bit of the Wikipedia article right on top of the page, a sort of quick preview. Here’s the code for it.

It works by using the Wikipedia API, specifically the “parse” method. (So named because it parses Wikimedia source data and returns JSON, the article contents). This URL is a sample query for the JSON contents of the Round-robin DNS page. There’s a zillion options for configuring what it returns, section=0 seems like a useful one to only get the first section of an article, typically the summary. And here’s how to get only the first paragraph.

The Wikipedia API has a sandbox for designing queries.

BTW I’m having a hard time with Chrome Developer Tools lately. I can’t find that Reddit page + RES loading this JSON anywhere. Maybe because it’s happening in a Chrome extension, out of site in a background page or something? Dunno.

One thought on “small Wikipedia text for inlining

  1. You have to bring up a dev tools window specifically for the extension. It’s a little bit out of the way, follow the red arrows in the pic.

Comments are closed.