// -------- Odnoklassniki ---------
// @url http://www.odnoklassniki.ru
// @include http://*.odnoklassniki.ru*
// @name Odnoklassniki
// @desc Tray notifications of new messages.
// version 0.4
/**
* @author Simon Hanukaev
* Revision History:
* version 0.4
* - NEW: iframe preloading changed to xmlHttpRequest.
* version 0.3.1.2
* - NEW: Added icon blinking when new message arives.
* version 0.3.1
* - BUG: IE "Start Navigation" sound, the refresh of the iframe is changed to XHR.
* - BUG: IE "Start Navigation" on the odnoklassniki refresh (not related to the extension
* itself), there is a problem in gwt.js file.
* - NEW: Reloading iframe only when new event found on the page itself (Thanks to new AJAX
* interface of the odnoklassniki.ru)
* - NEW: New notification design with scrollable messages.
* - NEW: Added configuration parameter: isNotifyEnabled
* version 0.3
* - BUG: IE "Start Navigation" sound.
* - NEW: Context Menu Items.
* version 0.1
* - first release
*/
new function() {
//SSB.console.init("debug","iframe");
//SSB.console.init("debug","window");
//var reloadInterval = 60;
var reloadInterval = 30;
var hiddenContainer = null;
var isEventSidebarShown = false;
var currIcon = 0;
var bubblesTrckr = null;
SSB.setIcon("http://www.odnoklassniki.ru/favicon.ico");
// Check if user has logged in. The checking done by parsing URL.
var URL = window.location.href;
SSB.console.debug("The URL is: "+URL);
var isLoggedIn = /odnoklassniki\.ru\/dk/.test(URL);
isLoggedIn = isLoggedIn && !( /dk?st\.cmd=registration/.test(URL) );
if (!isLoggedIn) {
SSB.console.debug("Didn't found 'dk?st.cmd=' or found 'dk?st.cmd=registration'.");
SSB.console.debug("Exiting");
return;
}
// The prefix of the domain changes every time user logs in. To prevent restriction
// issues, need to remember the prefix and use it after for message checking.
var wwwPrefix = URL.match(/http:\/\/([\d\w]+)\.odnoklassniki/)[1];
SSB.console.debug("The www prefix is: "+wwwPrefix);
// Initialization of configurable parameters prefsPane.
// isNotifyEnabled is user configurable parameter, indicates if the user want to be
// notified on new emails arrival.
SSB.prefs.pane.init([{type:'bool', name:'isNotifyEnabled', defVal:true, title:'Notify when new message arrives'}]);
SSB.contextMenu.add("My Page","http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userMain");
SSB.contextMenu.add("My Friends","http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userFriend");
SSB.contextMenu.add("My Messages","http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userMessageIncomingNew");
SSB.contextMenu.add("People Search","http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userSearchFriends");
var incomingMessagesUrl = "http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userMessageIncomingNew";
SSB.console.debug("The incomingMessagesUrl is: "+incomingMessagesUrl);
var uploadingImageUrl = "http://"+wwwPrefix+".odnoklassniki.ru/dk?st.cmd=userAddPhoto";
SSB.console.debug("The uploadingImageUrl is: "+uploadingImageUrl);
createHiddenContainer();
createBubblesTrckr();
window.setInterval(checkForEvent, reloadInterval*1000);
// Uncomment to get messages immediatly without checking eventsidebar (runs once).
// sendXmlHttpRequest();
function checkForEvent() {
SSB.console.debug("Entered checkForEvent()");
var event_sidebar = document.getElementById("event_sidebar");
SSB.console.debug("event_sidebar = "+event_sidebar);
if (event_sidebar) {
SSB.console.debug("There is event_sidebar");
if (!isEventSidebarShown) {
isEventSidebarShown = true;
blinkIcon();
}
sendXmlHttpRequest();
} else {
SSB.console.debug("There is no event_sidebar");
isEventSidebarShown = false;
}
}
function blinkIcon() {
SSB.console.debug("currIcon: "+currIcon);
if (currIcon == 0) {
currIcon = 1;
SSB.setIcon("http://www.odnoklassniki.ru/favicon.ico");
}
else {
currIcon = 0;
SSB.setIcon("http://bubbleshq.com/client/icons/odnoklassniki_new_msg.ico");
}
if (isEventSidebarShown || currIcon == 1)
window.setTimeout(blinkIcon,2000);
}
function sendXmlHttpRequest() {
try {
SSB.console.debug("sendXmlHttpRequest()");
var xmlHttp = getXmlHttpObject();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
SSB.console.debug("xmlHttp.readyState == 4");
var responseHtml = xmlHttp.responseText;
var messagesTableOuterHtml = responseHtml.match(/\