mirror of
https://github.com/ctxinf/simple-disguise.git
synced 2026-07-22 05:32:12 +00:00
Followed suggestions from https://github.com/obsidianmd/obsidian-releases/pull/4856#issuecomment-2537858376
Change `toggleStyle` implementation, now use global document object to get workspace root element to toggle class
This commit is contained in:
parent
db2bce7594
commit
57dc2d5394
3 changed files with 7 additions and 41 deletions
|
|
@ -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
44
main.ts
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue