-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpopup.js
83 lines (75 loc) · 1.81 KB
/
popup.js
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
78
79
80
81
82
83
// Popup script for AWS AI Services Chrome Extension
// Ceyhun OZGUN
// August 2018
// https://github.com/ceyhunozgun/awsAIChromeExtension
function loadCredentials() {
chrome.runtime.sendMessage(
{
op: 'getCredentials',
dataKey: 'awsCredentials'
},
function (data) {
if (data.awsCredentials) {
$('#awsAccessKeyId').val(data.awsCredentials.awsAccessKeyId);
$('#awsSecretAccessKey').val(data.awsCredentials.awsSecretAccessKey);
$('#awsRegion').val(data.awsCredentials.awsRegion);
}
}
);
}
function checkCredentials(callback) {
chrome.runtime.sendMessage(
{
op: 'synthesizeSpeech',
voice: 'Joanna',
text: 'Welcome'
},
function (resp) {
callback(resp.err, resp.data);
}
);
}
function saveCredentials() {
var awsAccessKeyId = $('#awsAccessKeyId').val();
var awsSecretAccessKey = $('#awsSecretAccessKey').val();
var awsRegion = $('#awsRegion').val();
if (awsAccessKeyId !== '' && awsSecretAccessKey !== '' && awsRegion !== '') {
chrome.runtime.sendMessage({
op: 'saveCredentials',
data: {
awsCredentials: {
awsAccessKeyId: $('#awsAccessKeyId').val(),
awsSecretAccessKey: $('#awsSecretAccessKey').val(),
awsRegion: $('#awsRegion').val()
}
}
}, function (resp) {
if (resp.err)
alert('Error when testing credentials: ' + errorToString(resp.err));
else {
alert('Credentials validated and saved. You can use the extension on pages.');
window.close();
}
});
}
else
alert('Please enter your credentials');
}
$(function() {
var regions = [
"eu-west-1",
"eu-west-2",
"eu-west-3",
"eu-central-1",
"us-west-1",
"us-west-2",
"us-east-1",
"us-east-2"
];
$("#awsRegion").autocomplete({
source: regions
});
$('#saveBtn').click(saveCredentials);
$('#loadBtn').click(loadCredentials);
loadCredentials();
});