Skip to content

Commit 57dc2d5

Browse files
committed
Change `toggleStyle` implementation, now use global document object to get workspace root element to toggle class
1 parent db2bce7 commit 57dc2d5

File tree

3 files changed

+7
-41
lines changed

3 files changed

+7
-41
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sample disguise / 简单伪装
1+
# Simple disguise / 简单伪装
22

33
## Introduction
44
Disguise/obscure/hide the content in a very simple way. Prevent your editing content from being seeing clearly too easily by others passing by in public spaces.

main.ts

+5-39
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,17 @@
1-
import { App, ItemView,WorkspaceTabs,WorkspaceLeaf ,Editor, MarkdownView, MarkdownEditView,Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
2-
3-
4-
1+
import {Plugin} from 'obsidian';
52

63

74
export default class SimpleDisguisePlugin extends Plugin {
8-
private styleEnabled: boolean = false;
95
async onload() {
10-
console.log('onload')
11-
126
this.addRibbonIcon('eye-off', 'Disguise', () => {
137
this.toggleStyle()
148
});
159
}
1610

17-
onunload() {
18-
console.log('onunload')
19-
20-
}
21-
22-
23-
2411
private toggleStyle() {
25-
this.styleEnabled = !this.styleEnabled;
26-
27-
if (this.styleEnabled) {
28-
this.applyCustomStyle();
29-
} else {
30-
this.removeCustomStyle();
31-
}
32-
}
33-
34-
private applyCustomStyle() {
35-
const view = this.app.workspace.getActiveViewOfType(ItemView);
36-
const tabContainer=view?.containerEl?.parentElement?.parentElement
37-
38-
if (tabContainer) {
39-
tabContainer.addClass('content-disguise')
40-
}
41-
}
42-
43-
private removeCustomStyle() {
44-
const view = this.app.workspace.getActiveViewOfType(ItemView);
45-
const tabContainer=view?.containerEl?.parentElement?.parentElement
46-
47-
if (tabContainer) {
48-
tabContainer.removeClass('content-disguise')
49-
}
12+
const workspaceRoot=document.querySelector('.workspace-split.mod-root')
13+
if(!workspaceRoot)return
14+
const alreadyDisguise=workspaceRoot.hasClass('content-disguise')
15+
workspaceRoot.toggleClass('content-disguise',!alreadyDisguise)
5016
}
5117
}

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Simple Disguise",
44
"version": "1.0.0",
55
"minAppVersion": "0.15.0",
6-
"description": "disguise/obscure/hide the content in a very simple way.",
6+
"description": "Disguise/obscure/hide the content in a very simple way.",
77
"author": "slow-groovin",
88
"isDesktopOnly": false
99
}

0 commit comments

Comments
 (0)