import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; // Remember to rename these classes and interfaces! interface MyPluginSettings { mySetting: string; } const DEFAULT_SETTINGS: MyPluginSettings = { mySetting: 'default' } export default class MyPlugin extends Plugin { settings: MyPluginSettings; async onload() { await this.loadSettings(); this.registerEvent( this.app.workspace.on("file-menu", (menu, file) => { menu.addItem((item) => { item .setTitle("New Paste") .setIcon("document") .onClick(async () => { this.createpaste(); }); }); }) ); this.addCommand({ id: "new-paste", name: "Create a new paste", callback: () => { this.createpaste(); }, }); } 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() { } async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); } async saveSettings() { await this.saveData(this.settings); } }