2014-03-20 00:04:23 +01:00
|
|
|
/* This file is dedicated to the public domain; you may do as you wish with it. */
|
|
|
|
|
2014-03-10 21:24:41 +01:00
|
|
|
// Default settings
|
|
|
|
var defaultSettings = {
|
|
|
|
"videoexpand": true,
|
|
|
|
"videohover": false,
|
|
|
|
"videovolume": 1.0
|
|
|
|
};
|
|
|
|
|
|
|
|
// Non-persistent settings for when localStorage is absent/disabled
|
|
|
|
var tempSettings = {};
|
|
|
|
|
2013-11-10 13:57:45 +01:00
|
|
|
// Scripts obtain settings by calling this function
|
|
|
|
function setting(name) {
|
2014-03-10 21:24:41 +01:00
|
|
|
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];
|
|
|
|
}
|
2013-11-10 13:57:45 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:53:20 +01:00
|
|
|
// Settings should be changed with this function
|
|
|
|
function changeSetting(name, value) {
|
2014-03-10 21:24:41 +01:00
|
|
|
if (localStorage) {
|
|
|
|
localStorage[name] = JSON.stringify(value);
|
|
|
|
} else {
|
|
|
|
tempSettings[name] = value;
|
2013-11-10 13:57:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-10 10:56:45 +01:00
|
|
|
// Create settings menu
|
2013-11-10 13:57:45 +01:00
|
|
|
var settingsMenu = document.createElement("span");
|
|
|
|
settingsMenu.className = "settings";
|
|
|
|
settingsMenu.innerHTML = '<span>[Settings]</span>'
|
2013-11-14 07:41:35 +01:00
|
|
|
+ '<div style="display: none; text-align: left; position: absolute; right: 0px; margin-left: -999em; margin-top: -1px; padding-top: 1px;">'
|
2013-11-10 10:56:45 +01:00
|
|
|
+ '<label><input type="checkbox" name="videoexpand">Expand videos inline</label><br>'
|
2013-11-09 23:28:49 +01:00
|
|
|
+ '<label><input type="checkbox" name="videohover">Play videos on hover</label><br>'
|
2014-03-05 01:45:53 +01:00
|
|
|
+ '<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>'
|
2013-11-09 10:11:22 +01:00
|
|
|
+ '</div>';
|
|
|
|
|
|
|
|
function refreshSettings() {
|
2013-11-10 10:56:45 +01:00
|
|
|
var settingsItems = settingsMenu.getElementsByTagName("input");
|
2013-11-09 10:11:22 +01:00
|
|
|
for (var i = 0; i < settingsItems.length; i++) {
|
2014-03-05 01:45:53 +01:00
|
|
|
var control = settingsItems[i];
|
|
|
|
if (control.type == "checkbox") {
|
|
|
|
control.checked = setting(control.name);
|
|
|
|
} else if (control.type == "range") {
|
|
|
|
control.value = setting(control.name);
|
|
|
|
}
|
2013-11-09 10:11:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 01:45:53 +01:00
|
|
|
function setupControl(control) {
|
|
|
|
if (control.addEventListener) control.addEventListener("change", function(e) {
|
|
|
|
if (control.type == "checkbox") {
|
2014-03-05 04:53:20 +01:00
|
|
|
changeSetting(control.name, control.checked);
|
2014-03-05 01:45:53 +01:00
|
|
|
} else if (control.type == "range") {
|
2014-03-05 04:53:20 +01:00
|
|
|
changeSetting(control.name, control.value);
|
2014-03-05 01:45:53 +01:00
|
|
|
}
|
2013-11-10 13:57:45 +01:00
|
|
|
}, false);
|
2013-11-09 10:11:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshSettings();
|
2013-11-10 10:56:45 +01:00
|
|
|
var settingsItems = settingsMenu.getElementsByTagName("input");
|
2013-11-09 10:11:22 +01:00
|
|
|
for (var i = 0; i < settingsItems.length; i++) {
|
2014-03-05 01:45:53 +01:00
|
|
|
setupControl(settingsItems[i]);
|
2013-11-09 10:11:22 +01:00
|
|
|
}
|
|
|
|
|
2013-11-10 13:57:45 +01:00
|
|
|
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);
|
|
|
|
}
|