diff options
3 files changed, 128 insertions, 8 deletions
diff --git a/chrome/common/extensions/docs/examples/extensions/gmail/background.html b/chrome/common/extensions/docs/examples/extensions/gmail/background.html index f0c9b6a..a897333 100644 --- a/chrome/common/extensions/docs/examples/extensions/gmail/background.html +++ b/chrome/common/extensions/docs/examples/extensions/gmail/background.html @@ -5,9 +5,6 @@ var animationFrames = 36; var animationSpeed = 10; // ms var canvas; var canvasContext; -var gmail = "https://mail.google.com/"; -var gmailAtomRef = "https://mail.google.com/mail/feed/atom"; -var gmailRe = /https?\:\/\/mail.google.com\/(?!a\/)/; var loggedInImage; var pollIntervalMin = 1000 * 60; // 1 minute var pollIntervalMax = 1000 * 60 * 60; // 1 hour @@ -17,6 +14,30 @@ var rotation = 0; var unreadCount = -1; var loadingAnimation = new LoadingAnimation(); +function getGmailUrl() { + var url = "https://mail.google.com/"; + if (localStorage.customDomain) + url += localStorage.customDomain + "/"; + else + url += "mail/" + return url; +} + +function getFeedUrl() { + return getGmailUrl() + "feed/atom"; +} + +function isGmailUrl(url) { + // This is the Gmail we're looking for if: + // - starts with the correct gmail url + // - doesn't contain any other path chars + var gmail = getGmailUrl(); + if (url.indexOf(gmail) != 0) + return false; + + return url.length == gmail.length || url[gmail.length] == '?' || + url[gmail.length] == '#'; +} // A "loading" animation displayed while we wait for the first response from // Gmail. This animates the badge text with a dot that cycles from left to @@ -62,7 +83,7 @@ LoadingAnimation.prototype.stop = function() { chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) { - if (changeInfo.url && gmailRe.test(changeInfo.url)) { + if (changeInfo.url && isGmailUrl(changeInfo.url)) { console.log("saw gmail! updating..."); getInboxCount(function(count) { updateUnreadCount(count); @@ -76,6 +97,7 @@ function init() { loggedInImage = document.getElementById('logged_in'); canvasContext = canvas.getContext('2d'); + chrome.browserAction.setBadgeBackgroundColor({color:[208, 0, 24, 255]}); chrome.browserAction.setIcon({path: "gmail_logged_in.png"}); loadingAnimation.start(); @@ -168,7 +190,7 @@ function getInboxCount(onSuccess, onError) { handleError(); } - xhr.open("GET", gmailAtomRef, true); + xhr.open("GET", getFeedUrl(), true); xhr.send(null); } catch(e) { console.log("ex: " + e); @@ -237,12 +259,12 @@ function drawIconAtRotation() { function goToInbox() { chrome.tabs.getAllInWindow(undefined, function(tabs) { for (var i = 0, tab; tab = tabs[i]; i++) { - if (tab.url && gmailRe.test(tab.url)) { + if (tab.url && isGmailUrl(tab.url)) { chrome.tabs.update(tab.id, {selected: true}); return; } } - chrome.tabs.create({url: gmail}); + chrome.tabs.create({url: getGmailUrl()}); }); } diff --git a/chrome/common/extensions/docs/examples/extensions/gmail/manifest.json b/chrome/common/extensions/docs/examples/extensions/gmail/manifest.json index 002b9a8..fab4c55 100644 --- a/chrome/common/extensions/docs/examples/extensions/gmail/manifest.json +++ b/chrome/common/extensions/docs/examples/extensions/gmail/manifest.json @@ -1,8 +1,9 @@ { "name": "Google Mail Checker", "description": "Displays the number of unread messages in your Google Mail inbox. You can also click the button to open your inbox.", - "version": "1.3", + "version": "2", "background_page": "background.html", + "options_page": "options.html", "permissions": [ "tabs", "http://*.google.com/", "https://*.google.com/" ], diff --git a/chrome/common/extensions/docs/examples/extensions/gmail/options.html b/chrome/common/extensions/docs/examples/extensions/gmail/options.html new file mode 100644 index 0000000..5613c72 --- /dev/null +++ b/chrome/common/extensions/docs/examples/extensions/gmail/options.html @@ -0,0 +1,97 @@ +<html> +<head> +<title>Google Mail Checker - Options</title> +<style> +body { + font-family:helvetica, arial, sans-serif; + font-size:80%; + margin:10px; +} + +#header { + padding-bottom:1.5em; + padding-top:1.5em; +} + +#header h1 { + font-size: 156%; + display:inline; + padding-bottom:43px; + padding-left:75px; + padding-top:40px; + background:url(icon_128.png) no-repeat; + background-size:67px; + background-position:1px 18px; +} + +.section-header { + background:#ebeff9; + border-top:1px solid #b5c7de; + font-size:99%; + padding:3px 0 2px 5px; + font-weight:bold; + margin-bottom:1em; + margin-top:4em; +} + +.section-header.first { + margin-top:1em; +} + +#custom-domain { + width:300px; + margin-left:2px; +} + +#footer { + margin-top:4em; +} +</style> +</head> +<body> + +<div id="header"><h1>Google Mail Checker Options</h1></div> + +<div class="section-header first">Custom Domain</div> +<p>To use Google Mail checker with Google Apps for Your Domain, enter the domain here. +<p> + https://mail.google.com/<input type="text" id="custom-domain" oninput="markDirty()"> + <em>(eg a/mydomain.com)</em> + +<div id="footer"> + <button id="save-button" style="font-weight:bold" onclick="save()" + >Save</button> + <button onclick="init()">Cancel</button> +</div> + +<script> +var customDomainsTextbox; +var saveButton; + +init(); + +function init() { + customDomainsTextbox = document.getElementById("custom-domain"); + saveButton = document.getElementById("save-button"); + + customDomainsTextbox.value = localStorage.customDomain || ""; + markClean(); +} + +function save() { + localStorage.customDomain = customDomainsTextbox.value; + markClean(); + + chrome.extension.getBackgroundPage().init(); +} + +function markDirty() { + saveButton.disabled = false; +} + +function markClean() { + saveButton.disabled = true; +} +</script> +</body> +</html> |