You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.9 KiB
82 lines
2.9 KiB
10 years ago
|
/* This file is dedicated to the public domain; you may do as you wish with it. */
|
||
|
|
||
10 years ago
|
// Default settings
|
||
|
var defaultSettings = {
|
||
|
"videoexpand": true,
|
||
|
"videohover": false,
|
||
|
"videovolume": 1.0
|
||
|
};
|
||
|
|
||
|
// Non-persistent settings for when localStorage is absent/disabled
|
||
|
var tempSettings = {};
|
||
|
|
||
11 years ago
|
// Scripts obtain settings by calling this function
|
||
|
function setting(name) {
|
||
10 years ago
|
if (localStorage) {
|
||
|
if (localStorage[name] === undefined) return defaultSettings[name];
|
||
|
return JSON.parse(localStorage[name]);
|
||
|
} else {
|
||
|
if (tempSettings[name] === undefined) return defaultSettings[name];
|
||
|
return tempSettings[name];
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
// Settings should be changed with this function
|
||
|
function changeSetting(name, value) {
|
||
10 years ago
|
if (localStorage) {
|
||
|
localStorage[name] = JSON.stringify(value);
|
||
|
} else {
|
||
|
tempSettings[name] = value;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
// Create settings menu
|
||
11 years ago
|
var settingsMenu = document.createElement("span");
|
||
|
settingsMenu.className = "settings";
|
||
|
settingsMenu.innerHTML = '<span>[Settings]</span>'
|
||
11 years ago
|
+ '<div style="display: none; text-align: left; position: absolute; right: 0px; margin-left: -999em; margin-top: -1px; padding-top: 1px;">'
|
||
11 years ago
|
+ '<label><input type="checkbox" name="videoexpand">Expand videos inline</label><br>'
|
||
11 years ago
|
+ '<label><input type="checkbox" name="videohover">Play videos on hover</label><br>'
|
||
10 years ago
|
+ '<label><input type="range" name="videovolume" min="0" max="1" step="0.01" style="width: 4em; height: 1ex; vertical-align: middle; margin: 0px;">Default volume</label><br>'
|
||
11 years ago
|
+ '</div>';
|
||
|
|
||
|
function refreshSettings() {
|
||
11 years ago
|
var settingsItems = settingsMenu.getElementsByTagName("input");
|
||
11 years ago
|
for (var i = 0; i < settingsItems.length; i++) {
|
||
10 years ago
|
var control = settingsItems[i];
|
||
|
if (control.type == "checkbox") {
|
||
|
control.checked = setting(control.name);
|
||
|
} else if (control.type == "range") {
|
||
|
control.value = setting(control.name);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
function setupControl(control) {
|
||
|
if (control.addEventListener) control.addEventListener("change", function(e) {
|
||
|
if (control.type == "checkbox") {
|
||
10 years ago
|
changeSetting(control.name, control.checked);
|
||
10 years ago
|
} else if (control.type == "range") {
|
||
10 years ago
|
changeSetting(control.name, control.value);
|
||
10 years ago
|
}
|
||
11 years ago
|
}, false);
|
||
11 years ago
|
}
|
||
|
|
||
|
refreshSettings();
|
||
11 years ago
|
var settingsItems = settingsMenu.getElementsByTagName("input");
|
||
11 years ago
|
for (var i = 0; i < settingsItems.length; i++) {
|
||
10 years ago
|
setupControl(settingsItems[i]);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
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);
|
||
|
}
|