我试图在我的工具栏上添加一个Chrome扩展,当点击它时,会将当前页面转换为该页面的Google缓存版本。如果我已经在一个页面的Google缓存中,我想打开一个小小的弹出窗口,说:“你已经在这个页面的Google缓存版本!”如何仅在单一情况下打开镀铬扩展弹出窗口?
这里就是我的了:
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"
]
}
将redirect.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>
谢谢您的阅读和帮助!
您可以使用内容脚本来显示JS'alert()' - 我认为使用桌面通知是用户更好的用户体验。 – 2012-03-07 03:55:33
@JasonHall我不会使用JS alert(),因为它很烦人。我想使用Chrome扩展的弹出功能。但是,它开始看起来像我想要做的功能不存在 – Dbz 2012-03-07 03:58:46
它确实存在,我只是不确定有时候只显示弹出窗口是一种好方法。你可以尝试让弹出窗口总是显示,然后立即关闭,它可以做得足够快,它可以工作,但我有点怀疑它。或者,您可以将您的扩展程序设为页面操作而不是浏览器操作,因此图标将不会显示在这些页面上。 – 2012-03-07 04:07:24