Wednesday, March 26, 2008

Using Greasemonkey to "fix" a webpage

Do you use a webpage that doesn't quite get the job done? Is there just something missing? Greasmonkey to the rescue. Greasemonkey is an addon for Firefox that allows you to "fix/hack" web pages. You add different scripts to Greasemonkey that hack the page you are visiting. When the page loads, the Greasemonkey script that goes with that page is run. The script doesn't actually hack the web page on the server, it alters the way you see the web page on your computer. You can find Greasemonkey scripts here. These scripts do such varied things as adding a currency converter to eBay, a auto save for web text boxes, a bunch of stuff for Facebook (get rid of adds/spam all your friends/change page colors/make peoples profile pictures larger), etc. Heres a good run down of some good scripts.Lifehacker lists some good ones too. The July 2007 ABA Journal lists Greasemonkey as number 43 of 101 tips, tricks and tools to make you a more productive, less stressed-out lawyer.

For example,I do a lot of case research using Lexis. Aside from noting passages using Google Notebook, I like to download cases onto my hard drive so I can read the later and make notes on them using Acrobat Professional or Foxit. One annoyance I ran into was naming cases and articles I downloaded. Usually I am downloading tons of cases that I've found during a search. Its faster if I simply copy the title into the filename box. However, my friendly Nexis page tersely tells me "Filename should not contain spaces! Try again."

Try again? What is this, a guess the right filename contest? Now, I know what you are thinking, why can't I just delete the spaces? Well, you try doing that with 50 cases. So my solution was to create a Greasemonkey script that adds a "Strip Spaces" button to Lexis that replaces spaces with underscores.

For those interested, heres the code (this is Javascript, but see this post for a little better understanding of code generally):
// This script will add a Strip Spaces button to the Lexis download page.
// ==UserScript==
// @name ReplaceWUnderscore
// @namespace
// @description Adds a Strip Spaces button to Lexis
// @include*
// ==/UserScript==

var eltAfter, newElement;
eltAfter = document.getElementById('delDwnldName');
if (!eltAfter)
eltAfter=document.getElementsByName('fileName')[0];//for some reason the getdocument is dift that the search
//add the script
newScript = document.createElement('script');
newScript.innerHTML="function stripspaces (){obj=document.getElementById('delDwnldName');if(!obj) obj=document.getElementsByName('fileName')[0];str= obj.value;str=str.replace(/ /g,'_');obj.value=str;};"
scriptAfter.parentNode.insertBefore(newScript, scriptAfter.nextSibling);

//add the button
newElement = document.createElement('input');
newElement.setAttribute("value","Strip Spaces");

eltAfter.parentNode.insertBefore(newElement, eltAfter.nextSibling);


Post a Comment