Skip to content

Instantly share code, notes, and snippets.

@arlolra
Created June 6, 2014 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arlolra/ba1a0efe329952d09461 to your computer and use it in GitHub Desktop.
Save arlolra/ba1a0efe329952d09461 to your computer and use it in GitHub Desktop.
const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
Cu.import("resource:///modules/imServices.jsm");
let consoleService = Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService);
function log(msg) {
consoleService.logStringMessage(msg);
}
function rot13(aString)
aString.replace(/[a-zA-Z]/g, function(c)
String.fromCharCode(c.charCodeAt(0) + (c.toLowerCase() < "n" ? 1 : -1) * 13));
let rotTransform = {
observe: function(aSubject, aTopic, aData) {
switch(aTopic) {
case "sending-message":
aSubject.message = rot13(aSubject.message);
break;
case "receiving-message":
aSubject.originalMessage = rot13(aSubject.message);
break;
default:
log(aTopic);
}
}
};
let originalAddConversation;
function startup() {
let cs = Services.conversations.wrappedJSObject;
originalAddConversation = cs.addConversation;
cs.addConversation = function(prplIConvIM) {
prplIConvIM.addObserver(rotTransform);
originalAddConversation.call(cs, prplIConvIM);
};
}
function shutdown() {
if (reason === APP_SHUTDOWN)
return;
let cs = Services.conversations.wrappedJSObject;
for each (let prplIConvIM in cs.getUIConversations())
prplIConvIM.removeObserver(rotTransform);
cs.addConversation = originalAddConversation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment