-
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
// Copyright 2026 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: MIT
function setupTabWidthSelector() {
const LOCAL_STORAGE_KEY = "legit_tab_width";
function isValidTabWidth(width) {
if (typeof width !== "string") {
return false;
}
const n = parseInt(width, 10);
return Number.isFinite(n) && n > 0;
}
function applyTabWidth(width) {
localStorage.setItem(LOCAL_STORAGE_KEY, width);
document.body.style.tabSize = width;
}
const saved = localStorage.getItem(LOCAL_STORAGE_KEY);
const value = isValidTabWidth(saved) ? saved : "4";
applyTabWidth(value);
const selector = document.getElementById("global-tab-width");
if (selector) {
selector.value = value;
selector.addEventListener("change", event => {
if (!isValidTabWidth(event.currentTarget.value)) {
return;
}
applyTabWidth(event.currentTarget.value);
});
}
}
function setupThemeColor() {
const LOCAL_STORAGE_KEY = "legit_theme_color";
const VALID_COLORS = ["red", "orange", "green", "gray", "pink", "purple", "yellow"];
function applyThemeColor(color) {
if (color) {
localStorage.setItem(LOCAL_STORAGE_KEY, color);
document.documentElement.dataset.themeColor = color;
} else {
localStorage.removeItem(LOCAL_STORAGE_KEY);
document.documentElement.dataset.themeColor = "";
}
}
const saved = localStorage.getItem(LOCAL_STORAGE_KEY) || "";
applyThemeColor(saved);
const selector = document.getElementById("theme-color");
if (selector) {
selector.value = saved;
selector.addEventListener("change", event => {
const value = event.currentTarget.value;
if (value && !VALID_COLORS.includes(value)) {
return;
}
applyThemeColor(value);
});
}
}
function setupTreeLayout() {
const LOCAL_STORAGE_KEY = "legit_tree_layout";
const VALID_LAYOUTS = ["compact"];
function applyTreeLayout(layout) {
if (layout) {
localStorage.setItem(LOCAL_STORAGE_KEY, layout);
} else {
localStorage.removeItem(LOCAL_STORAGE_KEY);
}
for (const tree of document.getElementsByClassName("tree-row")) {
tree.dataset.layout = layout;
}
}
const saved = localStorage.getItem(LOCAL_STORAGE_KEY) || "";
applyTreeLayout(saved);
const selector = document.getElementById("tree-layout");
if (selector) {
selector.value = saved;
selector.addEventListener("change", event => {
const value = event.currentTarget.value;
if (value && !VALID_LAYOUTS.includes(value)) {
return;
}
applyTreeLayout(value);
});
}
}
function setupFileModeFormat() {
const LOCAL_STORAGE_KEY = "legit_file_mode_format";
const VALID_FORMATS = ["octal", "hidden"];
const FILE_MODE_PATTERN = /^[d-]([r-][w-][x-]){3}$/;
function applyFileMode(format) {
if (format) {
localStorage.setItem(LOCAL_STORAGE_KEY, format);
} else {
localStorage.removeItem(LOCAL_STORAGE_KEY);
}
for (const el of document.querySelectorAll("[data-file-mode]")) {
const mode = el.dataset.fileMode;
if (!FILE_MODE_PATTERN.test(mode || "")) {
continue;
}
el.dataset.format = format;
switch (format) {
case "octal": {
const n = 0
+ (mode[1] === "r" ? 0o400 : 0)
+ (mode[2] === "w" ? 0o200 : 0)
+ (mode[3] === "x" ? 0o100 : 0)
+ (mode[4] === "r" ? 0o40 : 0)
+ (mode[5] === "w" ? 0o20 : 0)
+ (mode[6] === "x" ? 0o10 : 0)
+ (mode[7] === "r" ? 0o4 : 0)
+ (mode[8] === "w" ? 0o2 : 0)
+ (mode[9] === "x" ? 0o1 : 0);
el.textContent = n.toString(8).padStart(3, "0");
break;
}
default:
el.textContent = mode;
break;
}
}
}
const saved = localStorage.getItem(LOCAL_STORAGE_KEY) || "";
applyFileMode(saved);
const selector = document.getElementById("file-mode-format");
if (selector) {
selector.value = saved;
selector.addEventListener("change", event => {
const value = event.currentTarget.value;
if (value && !VALID_FORMATS.includes(value)) {
return;
}
applyFileMode(value);
});
}
}
function setupFileSizeFormat() {
const LOCAL_STORAGE_KEY = "legit_file_size_format";
const VALID_FORMATS = ["hidden"];
function applyFileSize(format) {
if (format) {
localStorage.setItem(LOCAL_STORAGE_KEY, format);
} else {
localStorage.removeItem(LOCAL_STORAGE_KEY);
}
for (const el of document.querySelectorAll("[data-file-size]")) {
const size = parseInt(el.dataset.fileSize, 10);
if (!Number.isFinite(size)) {
continue;
}
el.dataset.format = format;
}
}
const saved = localStorage.getItem(LOCAL_STORAGE_KEY) || "";
applyFileSize(saved);
const selector = document.getElementById("file-size-format");
if (selector) {
selector.value = saved;
selector.addEventListener("change", event => {
const value = event.currentTarget.value;
if (value && !VALID_FORMATS.includes(value)) {
return;
}
applyFileSize(value);
});
}
}
function setupPreferencesDialog() {
const preferences = document.getElementById("preferences-dialog");
document.getElementById("preferences-dialog-trigger")?.addEventListener("click", (event) => {
preferences?.showModal();
});
document.getElementById("preferences-dialog-closer")?.addEventListener("click", (event) => {
preferences?.close();
});
}
setupTabWidthSelector();
setupThemeColor();
setupTreeLayout();
setupFileModeFormat();
setupFileSizeFormat();
setupPreferencesDialog();