// Scripts obtain settings by calling this function function setting(name) { return JSON.parse(localStorage[name]); } // Default settings function setDefault(name, value) { if (!(name in localStorage)) { localStorage[name] = JSON.stringify(value); } } setDefault("videoexpand", true); setDefault("videohover", false); setDefault("videovolume", 1.0); // Create settings menu var settingsMenu = document.createElement("span"); settingsMenu.className = "settings"; settingsMenu.innerHTML = '[Settings]' + '
'; function refreshSettings() { var settingsItems = settingsMenu.getElementsByTagName("input"); for (var i = 0; i < settingsItems.length; i++) { var control = settingsItems[i]; if (control.type == "checkbox") { control.checked = setting(control.name); } else if (control.type == "range") { control.value = setting(control.name); } } } function setupControl(control) { if (control.addEventListener) control.addEventListener("change", function(e) { if (control.type == "checkbox") { localStorage[control.name] = JSON.stringify(control.checked); } else if (control.type == "range") { localStorage[control.name] = JSON.stringify(control.value); } }, false); } refreshSettings(); var settingsItems = settingsMenu.getElementsByTagName("input"); for (var i = 0; i < settingsItems.length; i++) { setupControl(settingsItems[i]); } if (settingsMenu.addEventListener) { settingsMenu.addEventListener("mouseover", function(e) { refreshSettings(); settingsMenu.getElementsByTagName("span")[0].style.fontWeight = "bold"; settingsMenu.getElementsByTagName("div")[0].style.display = "block"; }, false); settingsMenu.addEventListener("mouseout", function(e) { settingsMenu.getElementsByTagName("span")[0].style.fontWeight = "normal"; settingsMenu.getElementsByTagName("div")[0].style.display = "none"; }, false); }