Chapter 6 — Gmail and Greasemonkey 105
} catch (e) {
gd_dumpErr(e);
}
}
return;
}
//set the command index and fire the change event
command_box.selectedIndex=delete_index;
command_box.onchange();
//command_box.dispatchEvent(‘click’);
//var evt=createEvent();
}
function _gd_make_dom_button(id) {
var delete_button=window.document.createElement(‘button’);
delete_button.setAttribute(‘class’, ‘ab’);
delete_button.setAttribute(‘id’, ‘_gd_delete_button’+id);
delete_button.addEventListener(‘click’, _gd_gmail_delete,
false);
//uncomment (remove the two leading slashes) from the next
line for red text
//delete_button.style.color=’#EE3311’;
//this is a little hack-y, but we can find the code for
the language here
var lang=’’;
try {
var
urlToTest=window.top.document.getElementsByTagName(‘frame’)[1]
.src;
var
m=urlToTest.match(/html\/([^\/]*)\/loading.html$/);
if (null!=m) lang=m[1];
} catch (e) {
gd_dumpErr(e);
}
//now check that language, and find the right word!
var buttonText=’Delete’; //the default text for the
button, overriden
//in the switch below if we know
the right word
switch (lang) {
case ‘it’: buttonText=’Elimina’; break;
case ‘es’: buttonText=’Borrar’; break;
case ‘fr’: buttonText=’Supprimer’; break;
//case ‘pt-BR’: buttonText=’Supressão’; break;
Continued