如何仅在一种情况下打开chrome扩展弹出窗口

How do I open a chrome-extension popup only under a single circumstance?

本文关键字:chrome 扩展 窗口 情况下 一种 何仅      更新时间:2023-09-26

我正试图在工具栏上制作一个chrome扩展,当单击该扩展时,它将把当前页面变成该页面的谷歌缓存版本。如果我已经在一个页面的谷歌缓存上,我想打开一个小弹出窗口,说:"你已经在这个页面的谷歌高速缓存版本上了!"

我得到的是:

manifest.json:

{
  "name": "gCache",
  "version": "1.1.5",
  "description": "View the Google Cache of a page",
  "background_page": "redirect.html",
  "browser_action": {
    "default_icon": "icon.png",
    "default_text": "Google Cache version of this page"
  },
  "permissions": [
    "tabs"
  ]
}

重定向.html:

<script>
chrome.browserAction.onClicked.addListener(function(tab) {
    if (tab.url.substring(0, 38) == "http://webcache.googleusercontent.com/")
        //Popup saying user is already on a webcache page
    else if(tab.url.substring(0, 5) == "http:")
        chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(7) });
    else if(tab.url.substring(0,6) == "https:")
        chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(8) });
});
</script>

感谢您的阅读和帮助!

您无法通过打开弹出窗口来混合和匹配browserAction onClick事件。您可能需要使用桌面通知API。