在Gmail邮件正文中运行Javascript

sat*_*urn 4 math gmail latex greasemonkey mathml

我想在我收到的gmail消息中显示LaTeX数学,因此例如$\mathbb P ^ 2 $将显示为一个很好的公式.现在,有几个Javascripts可用(例如,这个或MathJax可以完成这项工作,我只需要在合适的时间调用它们来操作gmail消息.

我知道这可以在"基本HTML"和"打印"视图中进行.是否可以在标准Gmail视图中执行此操作?我试图在"canvas_frame"iframe之前插入对javascript的调用,但这不起作用.

我怀疑,通过任何Javascript操纵Gmail邮件都是一个主要的安全漏洞(想想可以插入的所有恶意链接)以及Google会采取一切措施来防止这种情况发生.所以我的问题的答案可能是'不'.我是对的吗?

当然,只需在服务器上使用MathJax,Google就可以轻松实现LaTeX和MathML数学的查看.我做了相应的Gmail实验室请求,但没有答案,显然没有谷歌的兴趣.

那么,再一次:在客户端没有谷歌的合作可能吗?

小智 6

我认为,更好的方法之一可能是使用Google Charts API嵌入图片.

<img src="http://chart.apis.google.com/chart?cht=tx&chl=x=\frac{-b%20\pm%20\sqrt{b^2-4ac}}{2a}">
Run Code Online (Sandbox Code Playgroud)

要了解详情:https://developers.google.com/chart/image/ [注意,该API已被正式弃用,但有效期至2015年4月]

如果你真的必须使用LaTeX和一些js库,我认为你可以通过在iframe中注入脚本标记来实现这一目标.我希望这是一个很好的起点.

例:

// ==UserScript==
// @name           Test Gmail Alterations
// @version        1
// @author         Justen
// @description    Test Alter Email
// @include        https://mail.google.com/mail/*
// @include        http://mail.google.com/mail/*
// @license        GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==
(function GmailIframeInject() {

    GM_log('Starting GMail iFrame Injection');
    var GmailCode = function() {
        // Your code here;
        // The ':pd' (div id) changes, so you might have to do some extra work
        var mail = document.getElementById(':pd');
        mail.innerHTML = '<h1>Hello, World!</h1>';
    };

    var iframe = document.getElementById('canvas_frame');
    var doc = null;
    if( iframe ) {
        GM_log('Got iFrame');
        doc = iframe.contentDocument;
    } else {
        GM_log('ERROR: Could not get iframe with id canvas_frame');
        return
    }

    if( doc ) {
        GM_log('Injecting GmailCode');
        var code = "(" + GmailCode + ")();"
        doc.body.appendChild(doc.createElement('script')).innerHTML=code;
    } else {
        GM_log('ERROR: Could not get iframe content document');
        return;
    }
})();
Run Code Online (Sandbox Code Playgroud)