The version of vichan running on lainchan.org
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.

98 line
3.4KB

  1. /* This file is dedicated to the public domain; you may do as you wish with it. */
  2. if (typeof _ == 'undefined') {
  3. var _ = function(a) { return a; };
  4. }
  5. // Default settings
  6. var defaultSettings = {
  7. "videoexpand": true,
  8. "videohover": false,
  9. "videovolume": 1.0
  10. };
  11. // Non-persistent settings for when localStorage is absent/disabled
  12. var tempSettings = {};
  13. // Scripts obtain settings by calling this function
  14. function setting(name) {
  15. if (localStorage) {
  16. if (localStorage[name] === undefined) return defaultSettings[name];
  17. return JSON.parse(localStorage[name]);
  18. } else {
  19. if (tempSettings[name] === undefined) return defaultSettings[name];
  20. return tempSettings[name];
  21. }
  22. }
  23. // Settings should be changed with this function
  24. function changeSetting(name, value) {
  25. if (localStorage) {
  26. localStorage[name] = JSON.stringify(value);
  27. } else {
  28. tempSettings[name] = value;
  29. }
  30. }
  31. // Create settings menu
  32. var settingsMenu = document.createElement("div");
  33. var prefix = "", suffix = "", style = "";
  34. if (window.Options) {
  35. var tab = Options.add_tab("webm", "video-camera", _("WebM"));
  36. $(settingsMenu).appendTo(tab.content);
  37. }
  38. else {
  39. prefix = '<a class="unimportant" href="javascript:void(0)">'+_('WebM Settings')+'</a>';
  40. settingsMenu.style.textAlign = "right";
  41. settingsMenu.style.background = "inherit";
  42. suffix = '</div>';
  43. style = 'display: none; text-align: left; position: absolute; right: 1em; margin-left: -999em; margin-top: -1px; padding-top: 1px; background: inherit;';
  44. }
  45. settingsMenu.innerHTML = prefix
  46. + '<div style="'+style+'">'
  47. + '<label><input type="checkbox" name="videoexpand">'+_('Expand videos inline')+'</label><br>'
  48. + '<label><input type="checkbox" name="videohover">'+_('Play videos on hover')+'</label><br>'
  49. + '<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>'
  50. + suffix;
  51. function refreshSettings() {
  52. var settingsItems = settingsMenu.getElementsByTagName("input");
  53. for (var i = 0; i < settingsItems.length; i++) {
  54. var control = settingsItems[i];
  55. if (control.type == "checkbox") {
  56. control.checked = setting(control.name);
  57. } else if (control.type == "range") {
  58. control.value = setting(control.name);
  59. }
  60. }
  61. }
  62. function setupControl(control) {
  63. if (control.addEventListener) control.addEventListener("change", function(e) {
  64. if (control.type == "checkbox") {
  65. changeSetting(control.name, control.checked);
  66. } else if (control.type == "range") {
  67. changeSetting(control.name, control.value);
  68. }
  69. }, false);
  70. }
  71. refreshSettings();
  72. var settingsItems = settingsMenu.getElementsByTagName("input");
  73. for (var i = 0; i < settingsItems.length; i++) {
  74. setupControl(settingsItems[i]);
  75. }
  76. if (settingsMenu.addEventListener && !window.Options) {
  77. settingsMenu.addEventListener("mouseover", function(e) {
  78. refreshSettings();
  79. settingsMenu.getElementsByTagName("a")[0].style.fontWeight = "bold";
  80. settingsMenu.getElementsByTagName("div")[0].style.display = "block";
  81. }, false);
  82. settingsMenu.addEventListener("mouseout", function(e) {
  83. settingsMenu.getElementsByTagName("a")[0].style.fontWeight = "normal";
  84. settingsMenu.getElementsByTagName("div")[0].style.display = "none";
  85. }, false);
  86. }