2014-11-09 11:17:26 +01:00
|
|
|
/*global chrome*/
|
2014-05-21 04:21:07 +02:00
|
|
|
/* vim: ts=4:sw=4
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-11-09 11:17:26 +01:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
2014-11-16 22:19:51 +01:00
|
|
|
// Browser specific functions for Chrom*
|
2014-11-09 11:17:26 +01:00
|
|
|
window.extension = window.extension || {};
|
2014-05-21 04:21:07 +02:00
|
|
|
|
2014-11-09 11:17:26 +01:00
|
|
|
window.extension.navigator = (function () {
|
|
|
|
var self = {},
|
|
|
|
tabs = {};
|
|
|
|
tabs.create = function (url) {
|
|
|
|
chrome.tabs.create({url: url});
|
|
|
|
};
|
|
|
|
self.tabs = tabs;
|
2014-05-27 23:12:14 +02:00
|
|
|
|
2014-11-09 11:17:26 +01:00
|
|
|
self.setBadgeText = function (text) {
|
|
|
|
chrome.browserAction.setBadgeText({text: String(text)});
|
|
|
|
};
|
2014-05-27 23:12:14 +02:00
|
|
|
|
2014-11-09 11:17:26 +01:00
|
|
|
return self;
|
|
|
|
}());
|
2014-05-21 04:21:07 +02:00
|
|
|
|
2014-11-16 22:19:51 +01:00
|
|
|
window.extension.trigger = function (name, object) {
|
|
|
|
chrome.runtime.sendMessage(null, { name: name, data: object });
|
|
|
|
};
|
|
|
|
|
2014-12-19 22:59:18 +01:00
|
|
|
window.extension.on = function (name, callback) {
|
|
|
|
// this causes every listener to fire on every message.
|
|
|
|
// if we eventually end up with lots of listeners (lol)
|
|
|
|
// might be worth making a map of 'name' -> [callbacks, ...]
|
|
|
|
// so we can fire a single listener that calls only the necessary
|
|
|
|
// calllbacks for that message name
|
2014-11-16 22:19:51 +01:00
|
|
|
chrome.runtime.onMessage.addListener(function(e) {
|
|
|
|
if (e.name === name) {
|
|
|
|
callback(e.data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-05-21 04:21:07 +02:00
|
|
|
|
2015-01-22 09:21:37 +01:00
|
|
|
extension.windows = {
|
|
|
|
open: function(options, callback) {
|
|
|
|
chrome.windows.create(options, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
focus: function(id, callback) {
|
|
|
|
chrome.windows.update(id, { focused: true }, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
onClosed: function(callback) {
|
|
|
|
chrome.windows.onRemoved.addListener(callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
getCurrent: function(callback) {
|
|
|
|
chrome.windows.getCurrent(callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function(windowId) {
|
|
|
|
chrome.windows.remove(windowId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getBackground: function() {
|
|
|
|
return chrome.extension.getBackgroundPage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extension.browserAction = function(callback) {
|
|
|
|
chrome.browserAction.onClicked.addListener(callback);
|
|
|
|
};
|
|
|
|
|
2014-11-14 00:38:09 +01:00
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.registration = {
|
|
|
|
done: function () {
|
|
|
|
localStorage.setItem("chromiumRegistrationDone", "");
|
2014-12-19 22:59:18 +01:00
|
|
|
extension.trigger('registration_done');
|
2014-11-14 00:38:09 +01:00
|
|
|
window.location = '/index.html';
|
|
|
|
},
|
2014-11-10 21:42:51 +01:00
|
|
|
|
2014-11-14 00:38:09 +01:00
|
|
|
isDone: function () {
|
|
|
|
return localStorage.getItem("chromiumRegistrationDone") !== null;
|
|
|
|
},
|
|
|
|
};
|
2014-11-09 11:17:26 +01:00
|
|
|
}());
|