diff --git a/main.ts b/main.ts index e4bcdd5..c37c8ea 100644 --- a/main.ts +++ b/main.ts @@ -22,17 +22,26 @@ export default class MyPlugin extends Plugin { .setTitle("New Paste") .setIcon("document") .onClick(async () => { - new Notice(file.path); + this.createpaste(); }); }); }) ); } - async createpaste(): Promise { + async createpaste(): Promise { const { vault } = this.app; + var result = ''; + var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + var charactersLength = characters.length; + for ( var i = 0; i < 6; i++ ) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + const File = await vault.create("paste/"+result+".md", ''); + let leaf = this.app.workspace.getLeaf(false); + await leaf.openFile(File); } - + onunload() { } @@ -45,48 +54,3 @@ export default class MyPlugin extends Plugin { await this.saveData(this.settings); } } - -class SampleModal extends Modal { - constructor(app: App) { - super(app); - } - - onOpen() { - const {contentEl} = this; - contentEl.setText('Woah!'); - } - - onClose() { - const {contentEl} = this; - contentEl.empty(); - } -} - -class SampleSettingTab extends PluginSettingTab { - plugin: MyPlugin; - - constructor(app: App, plugin: MyPlugin) { - super(app, plugin); - this.plugin = plugin; - } - - display(): void { - 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(); - })); - } -} diff --git a/package.json b/package.json index 3ada219..21f2f1d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "obsidian-sample-plugin", + "name": "obsidian-paste-baalajimaestro", "version": "1.0.0", - "description": "This is a sample plugin for Obsidian (https://obsidian.md)", + "description": "This is a very simple plugin to generate pastes", "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", diff --git a/styles.css b/styles.css deleted file mode 100644 index 71cc60f..0000000 --- a/styles.css +++ /dev/null @@ -1,8 +0,0 @@ -/* - -This CSS file will be included with your plugin, and -available in the app when your plugin is enabled. - -If your plugin does not need CSS, delete this file. - -*/