forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
59 lines (54 loc) · 1.62 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
59
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function playSound(id) {
console.log(id);
chrome.extension.getBackgroundPage().playSound(id, false);
}
function stopSound(id) {
chrome.extension.getBackgroundPage().stopSound(id);
}
function soundChanged(event) {
var key = event.target.name;
var checked = event.target.checked;
if (checked) {
localStorage.setItem(key, "enabled");
playSound(event.target.name);
} else {
localStorage.setItem(key, "disabled");
stopSound(event.target.name);
}
}
function showSounds() {
var sounds = document.getElementById("sounds");
if (!localStorage.length) {
sounds.innerText = "";
return;
}
sounds.innerText = "Discovered sounds: (uncheck to disable)";
var keys = new Array();
for (var key in localStorage) {
keys.push(key);
console.log(key);
}
keys.sort();
for (var index in keys) {
var key = keys[index];
var div = document.createElement("div");
var check = document.createElement("input");
check.type = "checkbox"
check.name = key;
check.checked = localStorage[key] == "enabled";
check.onchange = soundChanged;
div.appendChild(check);
var text = document.createElement("span");
text.id = key;
text.innerText = key;
text.className = "sound";
text.onclick = function(event) { playSound(event.target.id); };
div.appendChild(text);
sounds.appendChild(div);
}
}
document.addEventListener('DOMContentLoaded', showSounds);
document.addEventListener('focus', showSounds);