我似乎找不到在Chrome扩展程序中以编程方式点击gmail的show原始按钮的方法,但源中似乎没有任何链接。
然而,url类似于格式化的电子邮件,也许可以构建,除非它有某种用户ID,我无法获取:
普通邮件视图:
https://mail.google.com/mail/?shva=1#inbox/131bfc47a65cb2fe
显示原文:
https://mail.google.com/mail/?ui=2&ik=8b4b18b93a&view=om&th=131bfc47a65cb2fe
注意用户ID &ik=8b4b18b93a
是否可以获得显示原始内容的链接?
感谢
答案 0 :(得分:4)
当我在任何gmail页面上点击“查看页面源”时,我在var GLOBALS=[...]
数组中看到了这个键。我会使用XMLHttpRequest
从后台页面读取gmail页面源代码,然后使用正则表达式解析它以找到此密钥。
另一种方法是使用内容脚本将<script>
标记注入gmail页面,然后使用custom events将此GLOBALS
数组传递回内容脚本(所有这一切都要打破内容脚本沙箱)。
答案 1 :(得分:1)
//Inject the following Script from contentScript to Page Script
//Allow firing an event [http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click]
function fireEvent(node, eventName) {
// Make sure we use the ownerDocument from the provided node to avoid cross-window //problems
var doc;
if (node.ownerDocument) {
doc = node.ownerDocument;
} else if (node.nodeType == 9) {
// the node may be the document itself, nodeType 9 = DOCUMENT_NODE
doc = node;
} else {
throw new Error("Invalid node passed to JSUtil.fireEvent: " + node.id);
}
if (node.fireEvent) {
// IE-style
var event = doc.createEventObject();
event.synthetic = true; // allow detection of synthetic events
node.fireEvent("on" + eventName, event);
} else if (node.dispatchEvent) {
// Gecko-style approach is much more difficult.
var eventClass = "";
// Different events have different event classes.
// If this switch statement can't map an eventName to an eventClass,
// the event firing is going to fail.
switch (eventName) {
case "click":
// Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
case "mousedown":
case "mouseup":
eventClass = "MouseEvents";
break;
case "focus":
case "change":
case "blur":
case "select":
eventClass = "HTMLEvents";
break;
default:
throw "JSUtil.fireEvent: Couldn't find an event class for event '" + eventName + "'.";
break;
}
var event = doc.createEvent(eventClass);
var bubbles = eventName == "change" ? false : true;
event.initEvent(eventName, bubbles, true); // All events created as bubbling and cancelable.
event.synthetic = true; // allow detection of synthetic events
node.dispatchEvent(event);
}
}
//Then select the element
var xx = document.query(showOriginalSelector);
//Fire mouseUp and mouseDown Events simultaneously
fireEvent(xx, 'mousedown');
fireEvent(xx, 'mouseup');