-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.htm
231 lines (216 loc) · 6.96 KB
/
settings.htm
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Help Settings</title>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="static/theme.css" rel="stylesheet" type="text/css" />
<script src="static/content.js" type="text/javascript"></script>
<style>
table {
width: 100%
}
td:first-child {
width: 50%
}
select {
width: 100%;
height: 2em;
font-size: inherit
}
select>option {
font-size: inherit
}
button {
line-height: 1.75em;
font-size: inherit
}
</style>
</head>
<body>
<h1>Help Settings</h1>
<p>Specify the settings the help should be started with by default. These settings are permanent; this is, they apply for all current and future visits to this help.</p>
<table>
<tr>
<td>
<label for="fontSize">Content font size:</label>
</td>
<td>
<select id="fontSize" size="1">
<option value="0.6">Very small</option>
<option value="0.8">Small</option>
<option value="1" selected>Medium (default)</option>
<option value="1.2">Large</option>
<option value="1.4">Very large</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="clickTab">Selected tab:</label>
</td>
<td>
<select id="clickTab" size="1">
<option value="0" selected>Content (default)</option>
<option value="1">Index</option>
<option value="2">Search</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="displaySidebar">Sidebar visibility:</label>
</td>
<td>
<select id="displaySidebar" size="1">
<option value="0">Hidden</option>
<option value="1" selected>Visible (default)</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="colorTheme">Color theme:</label>
</td>
<td>
<select id="colorTheme" size="1">
<option value="0" selected>Light (default)</option>
<option value="1">Dark</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="collapseQuickRef">Quick reference visibility:</label>
</td>
<td>
<select id="collapseQuickRef" size="1">
<option value="0" selected>Uncollapsed (default)</option>
<option value="1">Collapsed</option>
</select>
</td>
</tr>
</table>
<div class="note" id="activex" style="display: none">
<p>
<strong>Note:</strong> If you press the following button, ActiveX is used to create a config file named 'chm_config.js' in the same directory as the CHM file, with the following content:</p>
<pre class="NoIndent no-highlight" id="config-stringified"></pre>
</div>
<table>
<tr>
<td> </td>
<td style="text-align: right">
<button id="save-settings" disabled>Save settings</button>
</td>
</tr>
</table>
<p id="permission-denied" style="display: none">Permission denied. Run the CHM file as administrator or create the config file manually.</p>
<script>
var config = {};
var selects = document.getElementsByTagName('select');
var btn = document.getElementById("save-settings");
var pre = document.getElementById("config-stringified");
// Get default values:
if (!user) {
var user = {};
for (var i = 0; i < selects.length; i++)
user[selects[i].id] = Number(selects[i].value);
}
// Set default stringified config:
pre.innerText = 'config = ' + JSON.stringify(user, null, 2);
// Get saved values:
if (location.href.search(/::/) > 0) {
var configPath = decodeURI(window.location.href.match(/mk:@MSITStore:(.*?)\\[^\\]+\.chm/i)[1] + '\\chm_config.js');
loadScript(configPath, setSelectValues); setSelectEvents();
document.getElementById("activex").style.display = 'block';
btn.onclick = saveToFile;
}
else if (window.localStorage) {
config = JSON.parse(window.localStorage.getItem('config'));
setSelectValues(); setSelectEvents();
btn.onclick = saveToLocalStorage;
}
else {
var result = document.cookie.match(/config=([^;]+)/);
result && (config = JSON.parse(result[1]));
setSelectValues(); setSelectEvents();
btn.onclick = saveToCookie;
}
function setSelectValues() {
// Overwrite default values:
for (var key in config)
if (key in user)
user[key] = config[key];
// Set select values on load:
document.onreadystatechange = function() {
var state = document.readyState;
if (state == 'complete') {
for (var i = 0; i < selects.length; i++) {
var select = selects[i];
if (user[select.id] !== undefined)
select.value = Number(user[select.id]);
else
select.disabled = true;
};
pre.innerText = 'config = ' + JSON.stringify(user, null, 2);
}
}
}
function setSelectEvents() {
for (var i = 0; i < selects.length; i++) {
var select = selects[i];
selects[i].onchange = function() {
btn.disabled = false;
user[this.id] = Number(this.value);
pre.innerText = 'config = ' + JSON.stringify(user, null, 2);
};
};
}
function saveToFile() {
btn.disabled = true;
var content = 'config = ' + JSON.stringify(user, null, 2);
pre.innerText = content;
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile(decodeURI(configPath), 2, true);
a.WriteLine(content.replace(/\n/g, '\r\n'));
a.Close();
}
catch (err) {
if (err.number = -2146828218)
alert(err.message + '\n\n' + document.getElementById("permission-denied").innerText);
else
alert(err.message + ' (' + err.number + ')');
}
}
function saveToLocalStorage() {
btn.disabled = true;
window.localStorage.setItem('config', JSON.stringify(user));
}
function saveToCookie() {
btn.disabled = true;
document.cookie = ['config', '=', JSON.stringify(user), '; expires=.', new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 365).toGMTString(), '; path=/;'].join('');
}
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) { // IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" ||
script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
</script>
</body>
</html>