制作一个要在gmail中注入的内容脚本撰写页面? [英] Making a content script that is to be injected in gmail compose page?

查看:72
本文介绍了制作一个要在gmail中注入的内容脚本撰写页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



到目前为止,我已经有了这个url-pattern: [ *://mail.google.com/*] 。脚本在加载gmail时成功注入,但之后在点击收件箱或撰写链接时不会重新注入脚本。我希望 [*://mail.google.com/*compose] 可以轻松完成,但不会。



这个模式可能就我所能得到的,然后我必须创建一个监听器来检查页面的哪一部分被重新加载?



什么是确定合成页面何时被加载的最直接的方式?解析方案

解析方案

是真正的加载。

如果你想运行特定散列的代码,在URL中注入脚本而不使用散列,并使用 hashchange 来检测变化。
$ b $ pre $ function checkHash(){
if(/ ^#(撰写草稿)\ b / .test(location.hash)){
//做任何你想做的事
}
}
window.addEventListener('hashchange',checkHash);
checkHash();

代替监视位置散列值,使用 setInterval可能会更有效连续检查DOM中是否存在所需的元素。当您想要读取或写入特定DOM节点的值时,这特别有用。


I'd like to write a script that injects in the compose-page of gmail.

So far I've got this url-pattern: ["*://mail.google.com/*"]. The script successfully gets injected when loading gmail, but after that it doesn't get re-injected when clicking links like inbox or compose. I was hoping ["*://mail.google.com/*compose"] would do it easily, but no.

Is this pattern perhaps as far as I can get, and I'll then have to create a listener that checks when that part of the page is reloaded?

What is the most straightforward way to determine when the compose-page is loaded?

解决方案

Content script only run when a page is truly loaded.
If you want to run code for a specific hash, inject the script at the URL without the hash, and use the hashchange to detect changes.

function checkHash() {
    if (/^#(compose|drafts)\b/.test(location.hash)) {
        // Do whatever you want
    }
}
window.addEventListener('hashchange', checkHash);
checkHash();

Instead of monitoring the location hash, it might be more effective to use setInterval to continuously check whether the desired element exists in the DOM. This is particularly useful when you want to read or write the value of a specific DOM node.

这篇关于制作一个要在gmail中注入的内容脚本撰写页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆