我试图在我的工具栏上制作镀铬扩展程序,点击后,会将当前页面转换为该页面的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>
感谢您的阅读和帮助!