forked from drheld/isotropic_dominion_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
90 lines (79 loc) · 3.16 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function setupOption(default_value, name) {
var enable = localStorage[name];
if (enable == undefined) {
enable = default_value;
}
var name_to_select = document.getElementById(name + "_" + enable);
name_to_select.checked = true
}
function loadOptions() {
setupOption("t", "allow_disable");
setupOption("f", "status_announce");
setupOption("t", "always_display");
// Sanity check the options. There were bugs in enforcing this.
// If disabling is not allowed, require status announce.
if (localStorage["allow_disable"] == "f") {
if (localStorage["status_announce"] != "t") {
alert("Enabling post in status message.\n" +
"This setting was lost due to a bug.\n\n" +
"If you do not want to post in status message, " +
"please allow disabling and turn off this setting.");
localStorage["status_announce"] = "t";
$('#status_announce_t').attr('checked', true);
}
$('#status_announce_t').attr('disabled', true);
$('#status_announce_f').attr('disabled', true);
}
}
function generateOptionButton(name, value, desc) {
var id = name + "_" + value;
return "<label for='" + id + "'>" +
"<input type='radio' name='" + name + "' id='" + id + "'" +
"onclick='saveOption(\"" + name + "\", \"" + value + "\")'>" +
desc +
"</label><br>";
}
function generateOption(option_desc, extra_desc, name, yes_desc, no_desc) {
if (extra_desc != "") {
extra_desc += '<div style="line-height:6px;"> </div>';
}
return "<h3>" + option_desc + "</h3>" + extra_desc +
generateOptionButton(name, "t", yes_desc) +
generateOptionButton(name, "f", no_desc);
}
var js_element = document.createElement("script");
js_element.id = "pointCounterOptionsJavascript";
js_element.type = "text/javascript";
js_element.innerHTML = "function saveOption(name, value) { localStorage[name] = value; }"
document.body.appendChild(js_element);
var element = document.createElement("div");
element.id = "pointCounterOptions";
element.innerHTML =
"<h1>Dominion Point Counter Options</h1>" +
generateOption("Allow opponents to disable point counter with !disable?",
"",
"allow_disable",
"Allow disabling.",
"Do not allow disabling.") +
generateOption("Change lobby status to announce you use point counter?",
"Mandatory if disabling is not allowed.",
"status_announce",
"Post in status message.",
"Do not post in status message.") +
generateOption("Always display counts / points?",
"",
"always_display",
"Replace exit/faq with scores.",
"Only display in chat box from !status command.");
document.body.appendChild(element);
loadOptions();
$('#allow_disable_t').click(function() {
$('#status_announce_t').attr('disabled', false);
$('#status_announce_f').attr('disabled', false);
})
$('#allow_disable_f').click(function() {
localStorage["status_announce"] = "t";
$('#status_announce_t').attr('checked', true);
$('#status_announce_t').attr('disabled', true);
$('#status_announce_f').attr('disabled', true);
})