Created
July 28, 2010 21:35
-
-
Save kovrov/496398 to your computer and use it in GitHub Desktop.
OWA extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script> | |
var firstTime = true; | |
var countSet = false; | |
var updaterSet = false; | |
var user = ""; | |
var pass = ""; | |
var scheduled = false; | |
var m = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | |
m += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "; | |
m += "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"; | |
m += "<soap:Body>"; | |
m += "<GetFolder xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" "; | |
m += "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"; | |
m += "<FolderShape>"; | |
m += "<t:BaseShape>Default</t:BaseShape>"; | |
m += "</FolderShape>"; | |
m += "<FolderIds>"; | |
m += "<t:DistinguishedFolderId Id=\"inbox\"/>"; | |
m += "</FolderIds>"; | |
m += "</GetFolder>"; | |
m += "</soap:Body>"; | |
m += "</soap:Envelope>"; | |
function trim(str, chars) | |
{ | |
return ltrim(rtrim(str, chars), chars); | |
} | |
function ltrim(str, chars) | |
{ | |
chars = chars || "\\s"; | |
return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); | |
} | |
function rtrim(str, chars) | |
{ | |
chars = chars || "\\s"; | |
return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); | |
} | |
if (localStorage.customDomain) | |
{ | |
updateCount(); | |
} | |
function updateCount(nos) | |
{ | |
var noSchedule = nos || false; | |
var smsPacket = trim(m); | |
var req = new XMLHttpRequest(); | |
req.onreadystatechange = function () | |
{ | |
try | |
{ | |
if (req.readyState == 4) | |
{ | |
xmlDoc = req.responseXML; | |
var unread = xmlDoc.getElementsByTagName("UnreadCount")[0].childNodes[0].nodeValue; | |
if (unread == "0") | |
unread = ""; | |
chrome.browserAction.setBadgeText( { text: unread } ); | |
countSet = true; | |
if (countSet && !updaterSet) | |
{ | |
chrome.tabs.onUpdated.addListener( | |
function (tabId, changeInfo) | |
{ | |
if (changeInfo.url && isOWAUrl(changeInfo.url)) | |
updateCount(true); | |
}); | |
updaterSet = true; | |
} | |
} | |
} | |
catch (ex) | |
{ | |
// just ignore. | |
alert("We could not get a value out of the xml packet. " | |
+"Could be the wrong version. Could be no internet connection."); | |
user = ""; | |
pass = ""; | |
scheduled = false; | |
firstTime = true; | |
countSet = false; | |
} | |
} | |
try | |
{ | |
if (user.length > 0) | |
{ | |
if (user.length > 0 && firstTime) | |
{ | |
req.open("post", localStorage.customDomain + "/ews/Exchange.asmx", true, user, pass); | |
firstTime = false; | |
} | |
else if (!firstTime) | |
{ | |
req.open("post", localStorage.customDomain + "/ews/Exchange.asmx", true); | |
// just to be safe. | |
pass = ""; | |
} | |
req.setRequestHeader("Content-Type", "text/xml"); | |
req.setRequestHeader("translate", "F"); | |
req.send(smsPacket); | |
} | |
else | |
{ | |
chrome.browserAction.setBadgeText( { text: "?" } ); | |
} | |
} | |
catch (ex) | |
{ | |
alert("Something went wrong with the request. " | |
+ "Probably a domain/user/password. Whish I could tell you more."); | |
user = ""; | |
pass = ""; | |
firstTime = true; | |
countSet = false; | |
} | |
if (user.length > 0 && !noSchedule && !scheduled) | |
{ | |
window.setInterval(updateCount, (localStorage.delay || 30) * 1000); | |
scheduled = true; | |
} | |
} | |
function isOWAUrl(url) | |
{ | |
var owa = getOWAUrl(); | |
if (owa.indexOf("options.html") > -1) | |
return false; | |
if (url.indexOf(owa) != 0) | |
return false; | |
return true; | |
} | |
function getOWAUrl() | |
{ | |
if (localStorage.customDomain) | |
url = localStorage.customDomain + "/owa"; | |
else | |
url = chrome.extension.getURL('options.html'); | |
return url; | |
} | |
function goToInbox() | |
{ | |
chrome.tabs.getAllInWindow( | |
undefined, | |
function (tabs) | |
{ | |
for (var i = 0, tab; tab = tabs[i]; i++) | |
{ | |
if (tab.url && isOWAUrl(tab.url)) | |
{ | |
chrome.tabs.update(tab.id, { selected: true }); | |
return; | |
} | |
} | |
chrome.tabs.create( { url: getOWAUrl() } ); | |
}); | |
} | |
</script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"update_url": "http://clients2.google.com/service/update2/crx", | |
"name": "OWA extension", | |
"version": "1.1", | |
"description": "Check exchange email from owa.", | |
"icons": { | |
"128": "icon.png" | |
}, | |
"browser_action": { | |
"default_icon": "icon.png", | |
"popup": "popup.html" | |
}, | |
"options_page": "options.html", | |
"background_page": "background.html", | |
"permissions": [ | |
"tabs", | |
"https://*/ews", | |
"http://*/ews" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>OWA 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; | |
} | |
#delay-text { | |
width:40px; | |
margin-left:2px; | |
} | |
#custom-domain { | |
width:300px; | |
margin-left:2px; | |
} | |
#footer { | |
margin-top:4em; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="header"><h1>OWA Mail Checker Options</h1></div> | |
<p>To use OWA checker you must have EWS enabled. Enter the domain here without /owa or /ews | |
It will be assumed that /owa and /ews are the names of the folders. | |
If you need an option for these values email owachecker@gmail.com and make you case :) | |
<br/><br/> | |
After hitting save click the icon. You will be prompted for a user name and password. This user name | |
is asked each time and is not stored. | |
<br/><br/> | |
After that clicking the button will take you to the OWA main page. This will also ask | |
you for your password once per session if using private computer settings. | |
<br/><br/> | |
</p> | |
<input type="text" id="custom-domain" oninput="markDirty()">/ews | |
<br/> | |
<em>(eg http(s)://owa.mycompany.com)</em> | |
<br/><br/> | |
Check interval:<br/><input type="text" id="delay-text" oninput="markDirty()"> | |
<br/><br/> | |
<!-- These are hidden for now...we might support this later if Google supports | |
some sort of protection for these values. | |
--> | |
<div style="display:none"> | |
User: (must include domain\)<br/> | |
<input type="text" id="user-text" oninput="markDirty()"> | |
<br/><br/> | |
Password:<br/> | |
<input type="password" id="password-text" oninput="markDirty()"> | |
</div> | |
<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 delayTextbox; | |
var userTextbox; | |
var passwordTextbox; | |
var saveButton; | |
init(); | |
function init() | |
{ | |
customDomainsTextbox = document.getElementById("custom-domain"); | |
saveButton = document.getElementById("save-button"); | |
delayTextbox = document.getElementById("delay-text"); | |
userTextbox = document.getElementById("user-text"); | |
passwordTextbox = document.getElementById("password-text"); | |
customDomainsTextbox.value = localStorage.customDomain || ""; | |
delayTextbox.value = localStorage.delay || "30"; | |
userTextbox.value = localStorage.user || ""; | |
passwordTextbox.value = localStorage.password || ""; | |
markClean(); | |
} | |
function save() | |
{ | |
/* disabled for now | |
if ( !userTextbox.value || !passwordTextbox.value) | |
{ | |
alert ('must set user name and password'); | |
return; | |
} | |
*/ | |
localStorage.customDomain = customDomainsTextbox.value; | |
localStorage.delay = delayTextbox.value; | |
localStorage.user = userTextbox.value; | |
localStorage.password = passwordTextbox.value; | |
markClean(); | |
chrome.extension.getBackgroundPage().init(); | |
} | |
function markDirty() | |
{ | |
saveButton.disabled = false; | |
} | |
function markClean() | |
{ | |
saveButton.disabled = true; | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var bg = chrome.extension.getBackgroundPage(); | |
if (!localStorage.customDomain) | |
{ | |
chrome.tabs.create( { url: bg.getOWAUrl() }); | |
window.close(); | |
} | |
if (bg.countSet) | |
{ | |
window.close(); | |
bg.goToInbox(); | |
} | |
else | |
{ | |
bg.firstTime = true; | |
bg.user = ""; | |
bg.pass = ""; | |
} | |
function saveButtonPopup() | |
{ | |
user = document.getElementById('user-text-box').value; | |
pass = document.getElementById('pass-text-box').value; | |
bg.user = user; | |
bg.pass = pass; | |
bg.updateCount(); | |
window.close(); | |
} | |
</script> | |
<body > | |
User:<br/> | |
<input type="text" id="user-text-box" value=""> | |
<br/><br/> | |
Password:<br/> | |
<input type="password" id="pass-text-box" value=""> | |
<br/> | |
<input type="button" value="Save" onclick="saveButtonPopup();"> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment