// 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("videomuted", false); // 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 box = settingsItems[i]; box.checked = setting(box.name); } } function setupCheckbox(box) { if (box.addEventListener) box.addEventListener("change", function(e) { localStorage[box.name] = JSON.stringify(box.checked); }, false); } refreshSettings(); var settingsItems = settingsMenu.getElementsByTagName("input"); for (var i = 0; i < settingsItems.length; i++) { setupCheckbox(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); }