Created
May 15, 2012 04:30
-
-
Save XP1/2699143 to your computer and use it in GitHub Desktop.
Enhance Outlook Web App: Fixes XML request bodies. Allows refreshing or opening Outlook in new tabs. Fixes sender CSS.
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
// ==UserScript== | |
// @name Enhance Outlook Web App | |
// @version 1.00 | |
// @description Fixes XML request bodies. Allows refreshing or opening Outlook in new tabs. Fixes sender CSS. | |
// @author XP1 (https://github.com/XP1/) | |
// @namespace https://gist.github.com/2699143/ | |
// @include http*://outlook.com/* | |
// @include http*://*.outlook.com/* | |
// ==/UserScript== | |
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */ | |
(function (console, window) | |
{ | |
"use strict"; | |
var userScript = | |
{ | |
name: "Enhance Outlook Web App" | |
}; | |
function removeEventListenerAfterFiring(numberOfTimes, callback) | |
{ | |
var remaining = numberOfTimes; | |
return function listener(event) | |
{ | |
remaining -= 1; | |
if (remaining <= 0) | |
{ | |
var target = event.target; | |
var type = event.type; | |
target.removeEventListener(type, listener, false); | |
target.removeEventListener(type, listener, true); | |
} | |
callback(); | |
}; | |
} | |
var handleException = function handleException(theFunction) | |
{ | |
try | |
{ | |
theFunction(); | |
} | |
catch (exception) | |
{ | |
console.error("[" + userScript.name + "]: Exception: " + exception + "\n\nStack:\n" + exception.stack + "\n\nStacktrace:\n" + exception.stacktrace); | |
} | |
}; | |
function deleteFunctions(object) | |
{ | |
var name = null; | |
for (name in object) | |
{ | |
if (object.hasOwnProperty(name)) | |
{ | |
if (typeof object[name] === "function") | |
{ | |
delete object[name]; | |
} | |
} | |
} | |
} | |
/** | |
* Removes XML declarations from request bodies. Outlook servers reject request bodies with XML declarations. | |
* Prevents the following error when sending requests: | |
* | |
* An unexpected error occurred and your request couldn't be handled. | |
*/ | |
function removeXmlDeclaration() | |
{ | |
var XmlDocumentPrototype = window.Owa.Dom.XmlDocument.prototype; | |
var realGet_Xml = XmlDocumentPrototype.get_Xml; | |
XmlDocumentPrototype.get_Xml = function get_Xml() | |
{ | |
return realGet_Xml.call(this).replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/i, ""); | |
}; | |
} | |
/** | |
* Moves the `Cky` constructor functions to its prototype and disables the cookie-checking `IsLdd` function. | |
* Prevents the following error when refreshing or opening Outlook in new tabs. | |
* | |
* There was a problem opening your mailbox. You may have already signed in to Outlook Web App on a different browser tab. If so, close this tab and return to the other tab. If that doesn't work, you can try: | |
* - Closing your browser window and signing in again. | |
* - Deleting cookies from your browser and signing in again. | |
* | |
* The `createMasterWindowCookies` function uses the `Cky` method `IsLdd` to check the master window cookies and display the error. | |
*/ | |
function disableCookieCheck() | |
{ | |
var RealCky = window.Cky; | |
function Cky() | |
{ | |
RealCky.apply(this, arguments); | |
deleteFunctions(this); | |
return this; | |
} | |
Cky.prototype = new RealCky(); | |
Cky.prototype.IsLdd = function Cky$IsLdd() | |
{ | |
return false; | |
}; | |
window.Cky = Cky; | |
} | |
function fixSenderCss() | |
{ | |
var css = "#divSn span, #divSender span { display: inline-block; }"; | |
var document = window.document; | |
var head = document.getElementsByTagName("head")[0]; | |
var style = document.createElement("style"); | |
style.appendChild(document.createTextNode(css)); | |
head.appendChild(style); | |
} | |
function initialize() | |
{ | |
var functions = [removeXmlDeclaration, disableCookieCheck, fixSenderCss]; | |
var i = null; | |
var length = functions.length; | |
for (i = 0; i < length; i += 1) | |
{ | |
handleException(functions[i]); | |
} | |
} | |
window.addEventListener("DOMContentLoaded", removeEventListenerAfterFiring(1, initialize), false); | |
}(this.console, this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I posted this user JS in this thread:
Support Outlook Web App premium:
http://my.opera.com/community/forums/topic.dml?id=1316492
Related thread:
Outlook Web App Light:
http://my.opera.com/community/forums/topic.dml?id=949932