From 57dc2d5394f7609a69bdfba64f36f3ba05119d89 Mon Sep 17 00:00:00 2001 From: slow-groovin <136044792+slow-groovin@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:32:29 +0800 Subject: [PATCH] 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 --- README.md | 2 +- main.ts | 44 +++++--------------------------------------- manifest.json | 2 +- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 4d417aa..33d0881 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/main.ts b/main.ts index 2f2ca04..4303da9 100644 --- a/main.ts +++ b/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) } } diff --git a/manifest.json b/manifest.json index 2529ed7..0878f46 100644 --- a/manifest.json +++ b/manifest.json @@ -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 }