在 Gmail 邮件正文上运行 Javascript

发布于 2024-09-01 12:45:23 字数 559 浏览 7 评论 0原文

我想在收到的 gmail 消息中显示 LaTeX 数学,这样 $\mathbb P^2$ 就会显示为一个很好的公式。现在,有几种可用的 Javascript(例如,这个,或者 MathJax 可以执行以下操作工作,我只需要在正确的时间调用他们来操作 Gmail 消息,

我知道这可以在“基本 HTML”和“打印”视图中完成,我尝试过吗?在“canvas_frame”iframe 之前插入对 javascript 的调用,但这不起作用,

我怀疑通过任何 Javascript 操作 Gmail 消息都将是一个重大安全缺陷(想想可以插入的所有恶意链接),并且Google 会尽一切努力来阻止这种情况,所以我的问题的答案可能是“否”。

当然,Google 只需使用 MathJax 即可轻松实现 LaTeX 和 MathML 数学的查看。我向他们的服务器提出了相应的 Gmail 实验室请求,但没有得到答复,而且 Google 显然也没有兴趣。

那么,如果没有 Google 的合作,这是否可以在客户端实现?

I want to display LaTeX math in the gmail messages that I receive, so that for example $\mathbb P^2$ would show as a nice formula. Now, there are several Javascripts available (for example, this one, or MathJax which would do the job, I just need to call them at the right time to manipulate the gmail message.

I know that this is possible to do in "basic HTML" and "print" views. Is it possible to do in the standard Gmail view? I tried to insert a call to the javascript right before the "canvas_frame" iframe, but that did not work.

My suspicion is that manipulating a Gmail message by any Javascript would be a major security flaw (think of all the malicious links one could insert) and that Google does everything to prevent this. And so the answer to my question is probably 'no'. Am I right in this?

Of course, it would be very easy for Google to implement viewing of LaTeX and MathML math simply by using MathJax on their servers. I made the corresponding Gmail Lab request, but no answer, and no interest from Google apparently.

So, again: is this possible to do without Google's cooperation, on the client side?

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

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

发布评论

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

评论(2

冷…雨湿花 2024-09-08 12:45:23

我认为更好的方法之一可能是使用 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}">

要了解详情: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;
    }
})();

I think one of the better ways to do this might be to embed images using the 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}">

To Learn more: https://developers.google.com/chart/image/ [note, the API has been officially deprecated, but will work until April 2015]

If you really must use LaTeX and some js library, I think one way you could accomplish this is by injecting a script tag into the iframe.
I hope this is a good starting point.

Example:

// ==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;
    }
})();
最初的梦 2024-09-08 12:45:23

嗯,据我所知,已经有一些 Greasemonkey 脚本可以对 GMail 执行操作(例如 这个)。这可能是一个安全漏洞吗?当然,您使用可执行代码执行的任何操作都存在这种风险。谷歌似乎在他们不感兴趣的事情上以极快的速度前进。他们确实似乎是基于内部对想法的支持而运作的,所以最好的方法是找到有同情心的谷歌用户,如果你希望他们将一些东西包含到GMail中。否则,请坚持使用 Greasemonkey,至少您将为其他希望看到相同功能的人提供一个简单的安装路径。

Well, there are already greasemonkey scripts that do things to GMail as far as i know (like this one). Is this a possible security hole? Of course, anything you'd do with executable code has that risk. Google seems to move a glacial speeds on things they're not interested in. They really do seem to function based on internal championing of ideas, so best way forward is to go find sympathetic googlers, if you want them to include something into GMail. Otherwise stick to Greasemonkey, at least you'll have an easy install path for other people who'd like to see the same functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文