Curiosity is bliss    Archive    Feed    About    Search

Julien Couvreur's programming blog and more

"MSDN Language Filter" user script

 

Just finished my MSDN Language Filter Greasemonkey user script. It removes the code samples for the languages you don't care about (say VB or JScript), on MSDN.
It lets you choose which language you want to filter out (see screenshot below) and remembers your preferences (using the new GreaseMonkey 0.3 data persistence APIs).

Here's a screenshot.


Update (2006-01-30): Updated the script to run in Greasmonkey 0.6.4 and Firefox 1.5.
Also included Ben Cartwright's fix for the SharePoint SDK (see comments below). Thanks Ben!

______________________________________

Hi Julien - Just installed this script and I'm not having much luck with it unfortunately. When I click on the language filter link, it just makes the bottom two frames completely disappear. For example when I go to the String class page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemStringClassTopic.asp

I click the C# link, and for some reason it redirects me to:
http://msdn.microsoft.com/library/shared/deeptree/asp/toolbar.asp?tbcfg=/library/toolbarconfig.xml#

Hmmm, any idea why this would be happening?

Cheers
Nick

Posted by: Nick Head (April 23, 2005 09:28 PM) ______________________________________

Hey Nick,

Couldn't repro the problem so far.
Do you see any javascript errors from this script when you open a MSDN
reference page?
If not, what platform (Firefox version, GM version and OS) are you using?

Thanks,

Posted by: Julien Couvreur (April 26, 2005 03:44 PM) ______________________________________

Hi Julien

My version no's are:
FF 1.0.3
GM 0.2.6
XP SP2

I just checked the JS console and I found this error message popped up about
10 times:

Error: GM_setValue is not defined
Source File:
http://msdn.microsoft.com/library/shared/deeptree/asp/toolbar.asp?tbcfg=/lib
rary/toolbarconfig.xml
Line: 100

Very weird - does that mean that GM_setValue doesn't exist in GM 0.2.6?

...I just investigated it and apparently GM_setValue isn't in the last
stable release 0.2.6, you need to upgrade to 0.3b. Installed latest version
and..... Ha haaaa - It works! :)

Thanks for your help
Nick

Posted by: Nick Head (April 26, 2005 03:46 PM) ______________________________________

Cool. I just fixed the script so that it alerts if you run it on an older version of GM.

Posted by: Julien (April 26, 2005 03:47 PM) ______________________________________

Nice user script, Julien. Thanks for sharing it!

For some reason, though, the SharePoint SDK on MSDN uses a different set of tags for its code samples that the xpath "//span[@class = 'lang']" won't match.

Example page from the SDK: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/tscSPWeb_SV01013607.asp

Here's a quick patch to your script that I came up with to handle this oddball case:

// In the FilterLanguages function, change:
var xpath = "//span[@class = 'lang']";

// To:
var xpath = "//span[@class = 'lang'] | //pre[@class = 'signature']/p";

// Then, at the end of the function, change:
if (!keepLang)
{
this.CleanSpan(res.snapshotItem(i), res.snapshotItem(i+1));
}

// To:
if (!keepLang)
{
if (spanElement.tagName == 'P')
{
var pre = res.snapshotItem(i).parentNode;
pre.parentNode.removeChild(pre);
}
else
{
this.CleanSpan(res.snapshotItem(i), res.snapshotItem(i+1));
}
}

Posted by: Ben Cartwright (November 10, 2005 08:37 PM)
comments powered by Disqus