if (window.getSelection) {
   text = window.getSelection();
} 
... else if (window.getSelection().text) {
   text = window.getSelection().text;
}

is it at all possible for `getSelection` to be falsy yet `getSelection().text` be truthy? I don't think so. It seems to me that last else will never be entered.
(Note however that in Chrome `document.all` is falsy while `document.all['someId']` works as `getElementById` to provide backward compat for old IEs; but I think it's not the case here).

Anyway, in code like this, I think it's always good to put comments next to the `if`s and write for which browsers this is meant to be used.

Also, I think it's better to write `text = window.getSelection().toString()` instead of assigning object to a `text` variable and appending an empty string later.