我试图找到一种方法,无论何时打开撰写窗口或更改“发件人:”字段,都可以使用Google Apps脚本(或某些其他方法附件)在GMail的网络应用程序中运行Javascript代码段。这样做的目的是使“新邮件” div进行颜色编码,以防止我使用错误的别名发送电子邮件。
我已经将Javascript编码(如下)并且在将其粘贴到控制台中时可以正常工作,现在只需要找到一种部署它的方法,这样它就可以通过上述事件的触发自动运行,或者每隔几秒钟连续运行一次。有什么想法吗?
var menuClass = "nH wKggEb";
var fromClass = "J-JN-M-I J-J5-Ji az2 az4 L3";
var menuItems = document.getElementsByClassName(menuClass);
Array.prototype.forEach.call(menuItems, element => {
var fromElementParent = element.parentElement;
while(fromElementParent.className != "AD"){
fromElementParent = fromElementParent.parentElement;
}
var fromElement = fromElementParent.getElementsByClassName(fromClass);
var menuColor = "#383838";
if(fromElement.length == 1){
var fromVal = fromElement[0].innerText;
switch(fromVal){
case "XXX-PERSONAL-XXX":
var menuColor = "#00911d";
break;
case "XXX-WORK1-XXX":
var menuColor = "#ffe100";
break;
case "XXX-WORK2-XXX":
var menuColor = "#00e1ff";
break;
case "XXX-SCHOOL-XXX":
var menuColor = "#002eff";
break;
}
}
element.style.backgroundColor = menuColor;
});