forked from Razumihin/obsidian-fullscreen-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
47 lines (40 loc) · 1.31 KB
/
Copy pathmain.ts
File metadata and controls
47 lines (40 loc) · 1.31 KB
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
import { Plugin } from "obsidian";
export default class FullScreenPlugin extends Plugin {
onload() {
this.addCommand({
id: "fullscreen-focus",
name: "Fullscreen focus mode",
callback: this.fullscreenMode.bind(this),
});
}
onunload() {}
fullscreenMode() {
var leaf = this.app.workspace.activeLeaf;
if (!leaf) return;
var el = leaf.containerEl;
var fullscreenMutationObserver;
el.requestFullscreen();
// disable mutation observer when exiting fullscreen mode
el.addEventListener("fullscreenchange", (event) => {
if (!document.fullscreenElement) {
fullscreenMutationObserver.disconnect();
document.body.classList.remove('fullscreen')
} else {
document.body.classList.add('fullscreen')
}
});
// copy all nodes
fullscreenMutationObserver = new MutationObserver((mutationRecords) => {
mutationRecords.forEach((mutationRecord) => {
mutationRecord.addedNodes.forEach((node) => {
document.body.removeChild(node);
el.appendChild(node);
});
});
// focus on prompt for file open
if (document.querySelector(".prompt-input"))
document.querySelector(".prompt-input").focus();
});
fullscreenMutationObserver.observe(document.body, { childList: true });
}
}