Join objects with same material

Hello people,

I almost use this script for a year:
http://blenderartists.org/forum/showthread.php?t=51586&highlight=3dre

Can someone help me to turn it in to a script that joins the objects with the same material, instead of moving them to another layer?

Cheers

can nobody help me?