Making a content script that is to be injected in gmail compose page?

后端 未结 1 457
故里飘歌
故里飘歌 2021-01-17 05:15

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 succes

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 05:50

    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.

    0 讨论(0)
提交回复
热议问题