-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
58 lines (52 loc) · 1.41 KB
/
options.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
var devices = [];
$("#save").click(function(e) {
devices = [];
$(".devices").filter(':checked').each(function(index, element) {
devices.push($(element).val());
});
chrome.storage.sync.set({
refresh_interval: $("#refresh_interval").val(),
api_key: $("#api_key").val(),
devices: devices
});
PushBullet.APIKey = $("#api_key").val();
load_devices(devices);
});
chrome.storage.sync.get({
api_key: '',
devices:[],
refresh_interval:1000
}, function(items) {
$("#api_key").val(items.api_key);
$("#refresh_interval").val(items.refresh_interval);
PushBullet.APIKey = items.api_key;
devices = items.devices;
load_devices();
});
function load_devices()
{
$("#devices").empty().append(
$("<div>").append("DO NOT SELECT CHROME DEVICES OR YOU MAY END UP IN A NEVERENDING LOOP")
);
PushBullet.devices(function(err, res) {
if(err) {
throw err;
} else {
$.each(res.devices, function(index, device)
{
$("#devices").append(
$("<div>").append(
$("<input>").attr("type", "checkbox").addClass("devices").attr("id",device.iden).val(device.iden).prop('checked', devices.indexOf(device.iden) !== -1)
).append(
$("<label>").attr("for",device.iden).append(device.nickname)
)
);
});
}
});
}
$("#test").click(function(e){
$.each(devices, function(index, device_iden){
PushBullet.push("link", device_iden, null, {title: "I got you a Nexus 6", url: "https://www.google.com/"});
});
});