You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/popup.js

51 lines
1.5 KiB
JavaScript

11 years ago
$('#inbox_link').onclick = function() {
11 years ago
$('#inbox').show();
$('#send').hide();
11 years ago
}
$('#send_link').onclick = function() {
11 years ago
$('#inbox').hide();
$('#send').show();
11 years ago
}
11 years ago
if (storage.getUnencrypted("number_id") === undefined) {
11 years ago
chrome.tabs.create({url: "options.html"});
11 years ago
} else {
function fillMessages() {
var MAX_MESSAGES_PER_CONVERSATION = 4;
var MAX_CONVERSATIONS = 5;
var conversations = [];
var messageMap = getMessageMap();
for (conversation in messageMap) {
var messages = messageMap[conversation];
messages.sort(function(a, b) { return b.timestamp - a.timestamp; });
conversations[conversations.length] = messages;
}
conversations.sort(function(a, b) { return b[0].timestamp - a[0].timestamp });
var ul = $('#messages');
ul.html('');
for (var i = 0; i < MAX_CONVERSATIONS && i < conversations.length; i++) {
var conversation = conversations[i];
ul.append('<li>');
11 years ago
for (var j = 0; j < MAX_MESSAGES_PER_CONVERSATION && j < conversation.length; j++) {
var message = conversation[j];
ul.append("From: " + message.sender + ", at: " + timestampToHumanReadable(message.timestamp) + "<br>");
ul.append("Message: " + message.message + "<br><br>");
11 years ago
}
ul.append('</li>');
}
}
11 years ago
$(window).bind('storage', function(e) {
console.log("Got localStorage update for key " + e.key);
if (event.key == "emessageMap")//TODO: Fix when we get actual encryption
fillMessages();
11 years ago
});
11 years ago
fillMessages();
11 years ago
storage.putUnencrypted("unreadCount", 0);
chrome.browserAction.setBadgeText({text: ""});
11 years ago
}