import { App , Editor , MarkdownView , Modal , Notice , Plugin , PluginSettingTab , Setting } from 'obsidian' ; interface MyPluginSettings { mySetting : string ; } const DEFAULT_SETTINGS = { mySetting : 'default' } ; export default class MyPlugin extends Plugin { settings : MyPluginSettings ; async onload ( ) { await this . loadSettings ( ) ; const ribbonIconEl = this . addRibbonIcon ( 'dice' , 'Sample Plugin' , ( evt ) => { new Notice ( 'This is a notice!' ) ; } ) ; ribbonIconEl . addClass ( 'my-plugin-ribbon-class' ) ; const statusBarItemEl = this . addStatusBarItem ( ) ; statusBarItemEl . setText ( 'Status Bar Text' ) ; this . addCommand ( { id : 'open-sample-modal-simple' , name : 'Open sample modal (simple)' , callback : ( ) => { new SampleModal ( this . app ) . open ( ) ; } } ) ; this . addCommand ( { id : 'sample-editor-command' , name : 'Sample editor command' , editorCallback : ( editor , view ) => { console . log ( editor . getSelection ( ) ) ; editor . replaceSelection ( 'Sample Editor Command' ) ; } } ) ; this . addCommand ( { id : 'open-sample-modal-complex' , name : 'Open sample modal (complex)' , checkCallback : ( checking ) => { const markdownView = this . app . workspace . getActiveViewOfType ( MarkdownView ) ; if ( markdownView ) { if ( ! checking ) { new SampleModal ( this . app ) . open ( ) ; } return true ; } } } ) ; this . addSettingTab ( new SampleSettingTab ( this . app , this ) ) ; this . registerDomEvent ( document , 'click' , ( evt ) => { console . log ( 'click' , evt ) ; } ) ; this . registerInterval ( window . setInterval ( ( ) => console . log ( 'setInterval' ) , 5 * 60 * 1000 ) ) ; } onunload ( ) { } async loadSettings ( ) { this . settings = Object . assign ( { } , DEFAULT_SETTINGS , await this . loadData ( ) ) ; } async saveSettings ( ) { await this . saveData ( this . settings ) ; } } class SampleModal extends Modal { constructor ( app ) { super ( app ) ; } onOpen ( ) { const { contentEl } = this ; contentEl . setText ( 'Woah!' ) ; } onClose ( ) { const { contentEl } = this ; contentEl . empty ( ) ; } } class SampleSettingTab extends PluginSettingTab { plugin : MyPlugin ; constructor ( app , plugin ) { super ( app , plugin ) ; this . plugin = plugin ; } display ( ) { const { containerEl } = this ; containerEl . empty ( ) ; containerEl . createEl ( 'h2' , { text : 'Settings for my awesome plugin.' } ) ; new Setting ( containerEl ) . setName ( 'Setting #1' ) . setDesc ( 'It\'s a secret' ) . addText ( text => text . setPlaceholder ( 'Enter your secret' ) . setValue ( this . plugin . settings . mySetting ) . onChange ( async ( value ) => { console . log ( 'Secret: ' + value ) ; this . plugin . settings . mySetting = value ; await this . plugin . saveSettings ( ) ; } ) ) ; } }