forked from kepano/obsidian-hider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
246 lines (215 loc) · 8.15 KB
/
main.ts
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import { App, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
export default class Hider extends Plugin {
settings: HiderSettings;
async onload() {
// load settings
await this.loadSettings();
// add the settings tab
this.addSettingTab(new HiderSettingTab(this.app, this));
// add the toggle on/off command
this.addCommand({
id: 'toggle-tab-containers',
name: 'Toggle tab bar',
callback: () => {
this.settings.hideTabs = !this.settings.hideTabs;
this.saveData(this.settings);
this.refresh();
}
});
this.addCommand({
id: 'toggle-app-ribbon',
name: 'Toggle app ribbon',
callback: () => {
this.settings.hideRibbon = !this.settings.hideRibbon;
this.saveData(this.settings);
this.refresh();
}
});
this.addCommand({
id: 'toggle-hider-status',
name: 'Toggle status bar',
callback: () => {
this.settings.hideStatus = !this.settings.hideStatus;
this.saveData(this.settings);
this.refresh();
}
});
this.refresh()
}
onunload() {
console.log('Unloading Hider plugin');
}
async loadSettings() {
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
// refresh function for when we change settings
refresh = () => {
// re-load the style
this.updateStyle()
}
// update the styles (at the start, or as the result of a settings change)
updateStyle = () => {
document.body.classList.toggle('hider-ribbon', this.settings.hideRibbon);
document.body.classList.toggle('hider-status', this.settings.hideStatus);
document.body.classList.toggle('hider-tabs', this.settings.hideTabs);
document.body.classList.toggle('hider-scroll', this.settings.hideScroll);
document.body.classList.toggle('hider-tooltips', this.settings.hideTooltips);
document.body.classList.toggle('hider-search-suggestions', this.settings.hideSearchSuggestions);
document.body.classList.toggle('hider-search-counts', this.settings.hideSearchCounts);
document.body.classList.toggle('hider-instructions', this.settings.hideInstructions);
document.body.classList.toggle('hider-meta', this.settings.hideMeta);
document.body.classList.toggle('hider-vault', this.settings.hideVault);
// if "hide titlebar" is on, show titlebar on hover.
if (this.settings.frameless) {
document.addEventListener("mousemove", ShowTitleBarOnHover, true);
} else {
document.removeEventListener("mousemove", ShowTitleBarOnHover, true);
}
}
}
interface HiderSettings {
hideRibbon: boolean;
hideStatus: boolean;
hideTabs: boolean;
hideScroll: boolean;
hideTooltips: boolean;
hideSearchSuggestions: boolean;
hideSearchCounts: boolean;
hideInstructions: boolean;
hideMeta: boolean;
hideVault: boolean;
}
const DEFAULT_SETTINGS: HiderSettings = {
hideRibbon: false,
hideStatus: false,
hideTabs: false,
hideScroll: false,
hideTooltips: false,
hideSearchSuggestions: false,
hideSearchCounts: false,
hideInstructions: false,
hideMeta: false,
hideVault: false
}
const ShowTitleBarOnHover = function(event: MouseEvent) {
if (event.clientY <= 40 && event.clientY - event.movementY > 40 && document.body.classList.contains('hider-frameless')) {
document.body.classList.toggle('hider-frameless');
}
if (event.clientY > 40 && event.clientY - event.movementY <= 40 && !document.body.classList.contains('hider-frameless')) {
document.body.classList.toggle('hider-frameless');
}
}
class HiderSettingTab extends PluginSettingTab {
plugin: Hider;
constructor(app: App, plugin: Hider) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
let {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Hide app ribbon')
.setDesc('Hides the Obsidian menu. Warning: to open Settings you will need use the hotkey (default is CMD + ,)')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideRibbon)
.onChange((value) => {
this.plugin.settings.hideRibbon = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide tab bar')
.setDesc('Hides the tab container at the top of the window')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideTabs)
.onChange((value) => {
this.plugin.settings.hideTabs = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide status bar')
.setDesc('Hides word count, character count and backlink count')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideStatus)
.onChange((value) => {
this.plugin.settings.hideStatus = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide vault name')
.setDesc('Hides the root folder name')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideVault)
.onChange((value) => {
this.plugin.settings.hideVault = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide scroll bars')
.setDesc('Hides all scroll bars')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideScroll)
.onChange((value) => {
this.plugin.settings.hideScroll = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide tooltips')
.setDesc('Hides all tooltips')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideTooltips)
.onChange((value) => {
this.plugin.settings.hideTooltips = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide instructions')
.setDesc('Hides instructional tips in modals')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideInstructions)
.onChange((value) => {
this.plugin.settings.hideInstructions = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide search suggestions')
.setDesc('Hides suggestions in search pane')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideSearchSuggestions)
.onChange((value) => {
this.plugin.settings.hideSearchSuggestions = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide count of search term matches')
.setDesc('Hides the number of matches within each search result')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideSearchCounts)
.onChange((value) => {
this.plugin.settings.hideSearchCounts = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
new Setting(containerEl)
.setName('Hide metadata block in Reading view')
.setDesc('When front matter is turned off in your Editor settings this hides the metadata block')
.addToggle(toggle => toggle.setValue(this.plugin.settings.hideMeta)
.onChange((value) => {
this.plugin.settings.hideMeta = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
}
}