Add createpaste functions

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-12-10 17:14:48 +05:30
parent baf67445ec
commit c0bac8f83f
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5
3 changed files with 14 additions and 58 deletions

60
main.ts
View file

@ -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<number> {
async createpaste(): Promise<void> {
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();
}));
}
}

View file

@ -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",

View file

@ -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.
*/