繁体   English   中英

以编程方式在 Chrome 扩展程序中单击 Gmail 的“显示原始”按钮?

[英]programmatically click Gmail's “show original” button in a chrome extension?

我似乎找不到在 chrome 扩展程序中以编程方式单击 gmail 的显示原始按钮的方法,源中似乎没有任何链接。

然而 url 类似于格式化的 email 并且也许可以构造,除了它有某种我无法获得的用户 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

是否可以获得显示原始链接的链接?

谢谢

当我在任何 gmail 页面上单击“查看页面源代码”时,我在var GLOBALS=[...]数组中看到了这个键。 我会使用XMLHttpRequest从背景页面读取 gmail 页面源,然后使用正则表达式对其进行解析以找到此键。

另一种方法是使用内容脚本将<script>标记注入 gmail 页面,然后使用自定义事件将此GLOBALS数组传递回内容脚本(所有这些都是为了突破内容脚本沙箱)。

//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');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM