以编程方式单击 Gmail 的“显示原始内容” chrome 扩展中的按钮?

发布于 2024-11-29 11:20:20 字数 440 浏览 0 评论 0原文

我似乎无法找到一种方法在 Chrome 扩展程序中以编程方式单击 Gmail 的显示原始按钮,源代码中似乎没有任何链接。

然而,该 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

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

谢谢

I can't seem to find a way to click gmail's show original button programmatically in a chrome extension, there doesn't appear to be any link in the source.

However the url is similar to the formatted email and perhaps could be constructed, except it has some kind of user id which I have no way of obtaining:

regular mail view:

https://mail.google.com/mail/?shva=1#inbox/131bfc47a65cb2fe

show original:

https://mail.google.com/mail/?ui=2&ik=8b4b18b93a&view=om&th=131bfc47a65cb2fe

note the user id &ik=8b4b18b93a

is it possible to get a link to show original?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-12-06 11:20:20

当我在任何 Gmail 页面上单击“查看页面源代码”时,我会在 var GLOBALS=[...] 数组中看到此键。我会使用 XMLHttpRequest 从后台页面读取 gmail 页面源代码,然后用正则表达式解析它以找到它钥匙。

另一种方法是使用内容脚本将

When I click "View page source" on any gmail page I see this key inside var GLOBALS=[...] array. I would read gmail page source from a background page using XMLHttpRequest and then parse it with regular expressions to find this key.

Another way would be to inject <script> tag to gmail page using a content script, and then pass this GLOBALS array back to a content script using custom events (all this to break out of content script sandbox).

隱形的亼 2024-12-06 11:20:20
//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');
//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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文