mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
* Remove docs folder. This was a redirect from a GitHub pages site that does not appear to be in use. * Rename api folder to api-samples. * Move examples to functional-samples folder. * Move cookbook sample to functional-samples. * Move tutorials to functional-samples folder. * Move mv2 and apps folders to _archive. * Rename tools folder to .repo. * Move reference folder to functional-samples. * Update README. Update README with new relative links for reorg. * Update README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> --------- Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
// 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);
|