O'Reilly logo

Greasemonkey Hacks by Mark Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #44. Filter Code Examples on MSDN

Display only the MSDN code samples and APIs for the languages you care about.

One thing has always bugged me about the MSDN reference pages. Viewing them locally within Visual Studio allows you to hide the code snippets for languages you're not interested in, but viewing them online always displays code examples in every language. If you're a VB programmer, you probably don't care about C# snippets, and vice versa.

This hack allows you to choose which language you care about and hides other code samples in the online MSDN documentation.

The Code

This user script runs on http://msdn.microsoft.com. The biggest question for overlaying the feature on top of MSDN is, "How structured is the content? How easy is it to identify sections showing a specific language?" Even though the markup isn't as clean as I had hoped, it is barely regular enough that I was able to filter code examples by language.

When I looked at the source of some MSDN reference pages, the markup for code snippets read something like this:

	              <grouping>
		<span class="lang">C#</span> …many nodes…
		<span class="lang">JScript</span> …many nodes…
	</grouping>

The grouping tag varies from page to page. Sometimes it's a <div>, but I also found <pre> elements on some pages. Although this markup is good enough for styling the page, it doesn't lend itself to easy filtering. Each language section doesn't have its own container, which makes it difficult to identify all the DOM nodes for the code sample. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required