Posts Tagged greasemonkey

Why I Use Google Chrome

Google Chrome

For most of my Internet livelihood I have used Internet Explorer as my primary browser.  I started with version three, embraced version four, slowly downloaded the 20 MB installation for version five via dial-up, relied upon version six, and tolerated version seven.  Between version seven and version eight, Chrome whisked me away on its magical carpet.

My litmus test for new browsers is quite simple.  I use it a few times intentionally, I explore its new or different features, and then I simply let the circumstances take over.  If I use the browser, I use it.  If I don’t, I don’t.  If I find myself going back to familiar territory, it fails.  It doesn’t matter why. 

My rationale is this:  If the browser is faster, I don’t need to force myself to use it. I’ll want to use it.   If it’s better, I’ll have incentive to use it over worse browsers.  

I have used this test for Firefox (which I use mostly for Firebug), Opera (which I briefly liked but never used), and a few others. 

As a rule, I don’t jump on new browser offerings. I’m generally content with whatever I’m using, despite its flaws.  So when I heard Google was releasing a browser, I was very unmotivated to try it out.  Indeed I waited almost six months to download the Chrome beta from Google.  

A few months later, Chrome is practically the only browser I use for leisure browsing.  

Chrome makes every other browser feel bloated and slow.  Opening tabs is instantaneous.  Closing a window with dozens of tabs is also instantaneous.  If a plugin crashes, I get personal and somewhat humorous “Aw Snap!” error message and the rest of the browser remains intact.  

It's a pun.

It's a pun.

Additionally, Chrome truly embraces the idea of searching from the address bar with reckless abandon.  Firefox and IE have featured this sort of functionality for years, but not nearly as intuitively.  Chrome assumes everything you type in the address bar is a search term unless it is quite evidently an address.  By contrast, Firefox and IE seem to first assume your input is an address.  The status bar usually begins a decision tree where “red hats” is looked up as a URL: http://red hats  and, failing that, it takes you to search results.

Another gripe I have consistently had with every mainstream browser until Chrome is the inability to drag tabs around or to drag a tab out of a window into a new window.  This seems so obvious and I have found myself trying to do it time and time again even in the absence of the feature.  Firefox simply creates a shortcut on the desktop if you try it.  IE turns the cursor into a forboding circle with a slash through it.  Chrome, on the other hand, immediately pops out a miniturized, translucent thumbnail and allows you to drop the tab anywhere or even drag it back into the tab lineup in one motion.  Finally!

Finally a browser that allows you to drag tabs wherever you want them.

Finally a browser that allows you to drag tabs wherever you want them.

 

Interface wise, Chrome is like XP to Windows 2000.  At first glance it feels blue and a bit silly, but overtime you realize they have stripped it down to only the things you use most when browsing. It’s optimized for surfing. Everything else plays second string.

All of this said, the biggest reason I started using Chrome is simply because I found it to be the fastest browser to load after logging into Windows. While clicking IE and Firefox seemed to cripple the system as it continued to go through its initial startup routines, Chrome popped up immediately.  That edge made it a winner before I even realized how awesome its other features were.

There are some areas it is lacking…plugin support is spotty, but many are supported.  GreaseMonkey support is barely there.  Auto Complete has just arrived in version 2 (but I never use it anyway).   The remember password feature seems a bit agressive and I suspect it has rembered passwords I didn’t authorize it to. (Possibly my imagination.)

These issues will surely be addressed as development continues.  I believe Chrome will pose a serious threat to Firefox and Internet Explorer once Google puts its marketing machine behind it.

, , , ,

3 Comments

Using JavaScript to Scroll to a specific element/object.

This morning I continued working on my Greasemonkey script for our ticket system.  I decided I wanted a ticket to scroll to the relevant information on load. As this location varies depending on the ticket, it would be necccessary to pick a specific page element and scroll to it. This turned out being slightly more complicated than I originally thought.

I searched Google for “get object position+javascript“. Using the helpful information on this page, I did the following:

//Finds y value of given object
function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curtop];
	}
}
//Get object
var SupportDiv = document.getElementById('customer_info');
 
//Scroll to location of SupportDiv on load
window.scroll(0,findPos(SupportDiv));

It’s pretty easy and works just like I wanted it to.

,

3 Comments

Playing with Greasemonkey

Today I endeavored to do something I had not done before: write a Greasemonkey script. As it turns out, this is relatively simple to do, but I did run into several problems. This was mostly due to my inexperience with JavaScript and my inexperience with Greasemonkey.

But in case anyone else has the same problems, I’ll detail some of the issues I ran up against.

My goal was simple: In our helpdesk ticket system, we have a comment field that allows us to comment on a ticket. Typically, I write the following text after I complete the ticket:

Please let us know if we may further assist you.

Thanks,
Clifton Griffin

Pretty simple, but I often find myself annoyed while typing this repeatedly. Why not use copy/paste? Well, I use copy/paste for other things in the course of closing a ticket and, writing a script is more fun.

My final script is as follows:

function appendSig(theField) {
 var theField = document.getElementsByTagName('textarea');
 theField[0].value += '\n\nPlease let us know if we may be of further ' +
'assistance.\n\nThanks,\nClifton Griffin\nNetwork Operations Center';
}
 
var CommentBox = document.getElementsByTagName('textarea');
var newLink = document.createElement('a');
CommentBox[0].parentNode.insertBefore(newLink, CommentBox[0]);
newLink.innerHTML = '(Append Signature)';
newLink.addEventListener("click", appendSig, true);

Pretty simple, right?

I create a function to modify the first textarea on the page (well, the only textarea in this example).

I create a link and add an event listener that fires the function when it is clicked.

In the process of writing this script, I learned several things.

  1. document.getElementByName() does not seem to work reliably (though I may have made the same mistake as below–I honestly don’t remember. I gave up pretty early on).
  2. document.getElementsByTagName() returns an array. You might think that would be obvious but the specs do not actually use the word array. It does say it gets a list. This arguably implies an array, but they could have been more specific. (Considering the nature of the documentation)
  3. You cannot use onClick() to run functions with greasemonkey. This is because by the time the page asks for the function, it no longer exists. Instead, you must use addEventListener, as shown above.
  4. While it may be tempting to use innerHTML to modify a textarea (and indeed, many many sites recommend this), I found this to be problematic in Firefox.  It adds the text (you can see it do so in firebug), but the screen does not update.  I briefly worked around this by trying:
    CommentBox.styles.display = "none";
    CommentBox.styles.display = "block";

    This worked a little. It seemed to fix the problem briefly, but upon further inspection, a couple of things didn’t work. Mainly, clicking the link added the text as long as I hadn’t manually added any text to the field. Also, clicking the link again didn’t work. This is really weird behavior that I can only blame on Firefox.

So there you have it.  Four issues.  I hope they help someone else save some time.

, , ,

1 Comment