I’m trying to make a chrome extension on my toolbar that, when clicked, will turn the current page into the google cached version of that page. If I am already on a google Cache of a page, I want to open a little popup saying, “You’re already on the google cache version of this page!”
Here’s what I got:
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>
Thank you for reading and for helping!
You can’t mix and match
browserActiononClickevents with opening a popup. You may want to use the Desktop Notifications API instead.