我正在使用Gmail.js库的gmail.observe.before("send_message", function(){...});
功能。在这里我添加了一个事件监听器,它监听包含要包含在电子邮件正文中的新主体的消息。但是,首先发送消息并稍后接收新字符串,如何在侦听器获取新字符串之前等待其余代码等待?
gmail.observe.before('send_message', function(url, body, data, xhr) {
console.log('sent the message');
window.addEventListener('message', function(event) {
if (event.data.type && (event.data.type == "FROM_PAGE")) {
console.log(event.data.text);
var newstring = (event.data.text);
console.log(newstring);
var oldCmml = xhr.xhrParams.url.cmml;
var body_params = xhr.xhrParams.body_params;
if (newstring.length > oldCmml) {
xhr.xhrParams.url.cmml = newstring.length;
} else {
while (newstring.length < oldCmml) {
newstring += ' ';
}
xhr.xhrParams.url.cmml = newstring.length;
}
body_params.body = newstring;
}
});
console.log("sent");
});
在控制台中记录新字符串之前,会记录“已发送”。我需要在“已发送”之前记录新字符串。我非常感谢你对此事的任何帮助