【问题标题】:window.GLOBALS[17] is null in the new Gmail UI while it is present for the old Gmail UIwindow.GLOBALS[17] 在新的 Gmail 用户界面中为空,而在旧的 Gmail 用户界面中存在
【发布时间】:2018-11-18 07:56:05
【问题描述】:
我有一个 Chrome 扩展程序,它使用一个名为 gmail.js 的库,它有点依赖于 Gmail 窗口中的 window.GLOBALS[17] 对象,但是在 gmail 的新 UI 中,Gmail 似乎已经删除了 GLOBALS[ 17] 现在等于 null,现在我无法访问 GLOBALS[17] 对象中存在的数据,我已经搜索、查看并尝试了所有内容,但似乎没有替代 GLOBALS[17]对象
GLOBALS[17] 在旧版 Gmail 用户界面上仍然可用
并且在新的 Gmail 用户界面中为 null
没有这个,我无法知道重要信息,例如电子邮件是否在对话视图中等等
为什么要删除它?有其他选择吗?
【问题讨论】:
标签:
google-chrome-extension
gmail
gmail-api
gmail-addons
【解决方案2】:
多年来,我一直在为客户端维护一个 Chrome 扩展程序,该扩展程序通过使用加密智能卡的 S/MIME 支持功能扩展了 Gmail 功能。在旧版 Gmail 用户界面中,我们从 GLOBAL[17] 获取了大量信息,包括:
- ike参数
- 是邮箱委托切换
- 委派电子邮件
- 用户界面语言
- 电子邮件签名开关(打开/关闭)
- 电子邮件签名 - 附加在所有外发邮件的末尾
以上所有信息都可以在 GLOBALS 或 Gmail DOM 中的其他地方找到。但是,我在查找有关签名和电子邮件签名开关的信息时遇到了问题(在旧 UI 中,它位于 GLOBALS[17][4][1]、属性 sx_mrsp_*、bx_se 中)。我注意到新的 Gmail UI 从包含一些带有 JSON 参数的 JavaScript _GM_setData 的页面下载此信息,其中包含非常相似的信息,例如 GLOBALS。下载数据中的部分以字符串 '_GM_setData({"w43KIf":["sdpc"..' 开头。也许这个 JSON 可以用来完全替代 GLOBALS。这里是 sn -p 我为此目的实现的 JS 代码 - 如果您正在解决类似的问题,您可以使用它来获得灵感(代码需要 JQuery 和 sprintf 的任何实现):
console.log(
"Going to download Gmail config to check for signature and signature switch.");
$.ajax(sprintf(
"https://mail.google.com/mail/ca/u/0/?ui=2&ik=%s&view=cm&fs=1&tf=1",
gmailConfig_ike), {
"type": "GET",
"accept": "html",
"error": function (response,
statusText1,
jqXHR1)
{
console.log("error getting config data (signature will be unavailable)):" + statusText1);
sendResponse(false);
},
"success": function (response,
statusText1,
jqXHR1)
{
// console.log("Data obtained: " + response);
var dom = $(response);
dom.filter('script').each(function ()
{
var myscript = this.text || this.textContent || this.innerHTML || '';
// console.log("script: " + myscript);
if (myscript.indexOf('["bx_se"') !== -1) {
console.log("bx_se found.");
//console.log(myscript);
var startToken = '_GM_setData({"';
var endToken = '"}); ';
var subscript = myscript.substring(myscript.indexOf(startToken) + startToken.length - 2);
// console.log("subscript: " + subscript);
var finalJSONString = subscript.substring(0,
subscript.indexOf(endToken) + 2);
// console.log("finalJSONString: " + finalJSONString);
var finalJSON = JSON.parse(finalJSONString);
//console.log(finalJSON);
// this locates the interesting information in the JSON object
var configArr = finalJSON.sBEv4c[2][1];
// console.log(configArr);
for (var k = 0; k < configArr.length; k++) {
var param = configArr[k];
if (param && param[0].indexOf("sx_mrsp_") == 0) {
console.log("Signature located: " + param[1]);
gmailConfig_signature = param[1];
}
if (param && param[0].indexOf("bx_se") == 0) {
console.log("Signature switch located: " + param[1]);
gmailConfig_signSwitch = param[1];
}
// if (param && param[0].indexOf("sx_dl") == 0) {
// console.log("Language located: " + param[1]);
// // gm_lang = param[1];
// }
}
}
});
sendResponse(true);
}
});