-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
77 lines (65 loc) · 2.08 KB
/
popup.js
File metadata and controls
77 lines (65 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(function() {
var qry = { active: true, currentWindow:true, windowType: "normal" };
function Environment(name, address) {
var that = this;
this.name = ko.observable(name || "");
this.address = ko.observable(address || "");
}
function ApiKey(publicKey, privateKey) {
var that = this;
this.publicKey = ko.observable(publicKey || "");
this.privateKey = ko.observable(privateKey || "");
}
function loadDefaultEnvironments() {
return [
new Environment("devapi", "https://devapi.takecarehealth.com/testharness"),
new Environment("dev-qa", "http://phl-qa-web01.hwwin.local:3000/"),
new Environment("bpo1", "http://bna-os-qa02.bpohwwin.com:3000/testharness"),
new Environment("bpo2", "http://tch-s8mp-3wb.bpohwwin.com:443/testharness"),
new Environment("api", "https://api.takecarehealth.com/testharness")
];
}
function initEnvironments() {
var loaded = localStorage.getItem("environments");
if (loaded) {
vm.environments = ko.mapping.fromJSON(loaded);
} else {
vm.environments = new ko.observableArray(loadDefaultEnvironments());
}
}
function setApiKey(key) {
chrome.tabs.query(qry, function (tabs) {
if (tabs && tabs.length > 0){
var tab = tabs[0];
var script = "document.getElementById('uxPublicKey').value = '" + key.publicKey() + "';" +
"document.getElementById('uxPrivateKey').value = '" + key.privateKey() + "';";
chrome.tabs.executeScript(tab.id, { code: script }, function(results) {
window.close();
});
}
});
}
function initApiKeys() {
var loaded = localStorage.getItem("apiKeys");
if (loaded) {
vm.apiKeys = ko.mapping.fromJSON(loaded);
} else {
vm.apiKeys = new ko.observableArray([]);
}
vm.setApiKey = setApiKey;
}
var vm = {
optionsUrl: chrome.extension.getURL("options.html")
};
initEnvironments();
initApiKeys();
$(document).ready(function() {
chrome.tabs.query(qry, function (tabs) {
if (tabs && tabs.length > 0){
var tab = tabs[0];
vm.showApiKeys = !!tab.url.match(/static\/s3\/S3FromJavascript\.htm/);
ko.applyBindings(vm);
}
});
});
}());