Change `toggleStyle` implementation, now use global document object to get workspace root element to toggle class
This commit is contained in:
slow-groovin 2024-12-12 16:32:29 +08:00
parent db2bce7594
commit 57dc2d5394
3 changed files with 7 additions and 41 deletions

View file

@ -1,4 +1,4 @@
# Sample disguise / 简单伪装
# Simple disguise / 简单伪装
## Introduction
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.

44
main.ts
View file

@ -1,51 +1,17 @@
import { App, ItemView,WorkspaceTabs,WorkspaceLeaf ,Editor, MarkdownView, MarkdownEditView,Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import {Plugin} from 'obsidian';
export default class SimpleDisguisePlugin extends Plugin {
private styleEnabled: boolean = false;
async onload() {
console.log('onload')
this.addRibbonIcon('eye-off', 'Disguise', () => {
this.toggleStyle()
});
}
onunload() {
console.log('onunload')
}
private toggleStyle() {
this.styleEnabled = !this.styleEnabled;
if (this.styleEnabled) {
this.applyCustomStyle();
} else {
this.removeCustomStyle();
}
}
private applyCustomStyle() {
const view = this.app.workspace.getActiveViewOfType(ItemView);
const tabContainer=view?.containerEl?.parentElement?.parentElement
if (tabContainer) {
tabContainer.addClass('content-disguise')
}
}
private removeCustomStyle() {
const view = this.app.workspace.getActiveViewOfType(ItemView);
const tabContainer=view?.containerEl?.parentElement?.parentElement
if (tabContainer) {
tabContainer.removeClass('content-disguise')
}
const workspaceRoot=document.querySelector('.workspace-split.mod-root')
if(!workspaceRoot)return
const alreadyDisguise=workspaceRoot.hasClass('content-disguise')
workspaceRoot.toggleClass('content-disguise',!alreadyDisguise)
}
}

View file

@ -3,7 +3,7 @@
"name": "Simple Disguise",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "disguise/obscure/hide the content in a very simple way.",
"description": "Disguise/obscure/hide the content in a very simple way.",
"author": "slow-groovin",
"isDesktopOnly": false
}