Thursday, July 03, 2008

Firefox Greasemonkey Outlook Web Access Extension Part II

Other posts on OWAX: [ Part I | Part III ]

Small addition to my Greasemonkey Outlook Web Access Extension -- now the enter key submits the search on the find names form.


Code shown below and as a download here.

// ==UserScript==
// @name Outlook Web Access Extensions
// @namespace http://www2.hawaii.edu/~dburger
// @description Extensions to using the bastard child Outlook Web Access
// @include https://mail.camber.com/exchange/*
// ==/UserScript==
(
function() {
// look for the toolbar and if found all 'Select All' to it
var tables = document.getElementsByTagName('table');
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
if (table.className === 'trToolbar') {
var row = table.tBodies[0].rows[0];
var newCell = row.insertCell(row.cells.length - 1);
newCell.setAttribute('valign', 'middle');
newCell.setAttribute('nowrap', 'nowrap');
var font = document.createElement('font');
font.setAttribute('size', '2');
font.appendChild(document.createTextNode('Select All'));
var nobr = document.createElement('nobr');
nobr.appendChild(font);
var a = document.createElement('a');
a.href = 'javascript:void(0);';
a.addEventListener('click', function() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
var evt = document.createEvent('MouseEvents');
if (input.type == 'checkbox' && !input.checked) {
// this won't fire the events to color the row
// input.checked = true;
// so dispatch as an event instead
evt.initEvent('click', true, false);
input.dispatchEvent(evt);
}
}
}, true);
a.appendChild(nobr);
newCell.appendChild(a);
}
}
// if this is the find names popup form let <enter> work as submit
var forms = document.getElementsByTagName('form');
if (forms.length == 1 && forms[0].name == 'galfind') {
var form = forms[0];
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.type == 'text') {
input.addEventListener('keypress', function(evt) {
if (evt.keyCode == 13) form.submit();
}, true);
}
}
}
}
)();
view raw gistfile1.js hosted with ❤ by GitHub