copy link to clipboard

This commit is contained in:
Jamie Steiner 2024-11-08 19:35:35 +02:00
parent 0937755de9
commit f1cbc8170a
2 changed files with 19 additions and 1 deletions

View file

@ -105,6 +105,7 @@ export default class Note {
if (this.plugin.settings.usePastebin) {
let pastebinApiKey = this.plugin.settings.pastebinApiKey;
let pastebinUserKey = this.plugin.settings.pasteBinUserKey;
let expiry = this.plugin.settings.pastebinExpiry;
const noteContent = await this.plugin.app.vault.read(this.file);
console.log("noteContent", noteContent);
requestUrl({
@ -115,7 +116,7 @@ export default class Note {
},
body: `api_dev_key=${pastebinApiKey}&api_user_key=${pastebinUserKey}&api_option=paste&api_paste_private=1&api_paste_name=${
this.file.basename
}&api_paste_expire_date=N&api_paste_format=text&api_paste_code=${encodeURIComponent(noteContent)}`,
}&api_paste_expire_date=${expiry}&api_paste_format=text&api_paste_code=${encodeURIComponent(noteContent)}`,
})
.then((res) => {
console.log("res", res.text);
@ -126,6 +127,7 @@ export default class Note {
const suffix = pathSegments[pathSegments.length - 1];
const obsidianUrl = `obsidian://send-note?sendurl=https://pastebin.com/raw/${suffix}&filename=${this.file.basename}.md`;
console.log(obsidianUrl);
navigator.clipboard.writeText(obsidianUrl);
})
.catch((err) => {
console.log("err", err);

View file

@ -43,6 +43,7 @@ export interface SendNoteSettings {
pastebinUsername: string;
pastebinPassword: string;
pasteBinUserKey: string;
pastebinExpiry: string;
}
export const DEFAULT_SETTINGS: SendNoteSettings = {
@ -66,6 +67,7 @@ export const DEFAULT_SETTINGS: SendNoteSettings = {
pastebinUsername: "",
pastebinPassword: "",
pasteBinUserKey: "",
pastebinExpiry: "1D",
};
export class SendNoteSettingsTab extends PluginSettingTab {
@ -179,6 +181,20 @@ export class SendNoteSettingsTab extends PluginSettingTab {
});
});
// Pastebin expiry period
new Setting(containerEl)
.setName("Pastebin expiry")
.setDesc("Pastebin expiry period: N, 1D, 1W, 1M, 1Y")
.addText((inputEl) => {
inputEl
.setPlaceholder("Pastebin expiry period")
.setValue(this.plugin.settings.pastebinExpiry)
.onChange(async (value) => {
this.plugin.settings.pastebinExpiry = value;
await this.plugin.saveSettings();
});
});
// Local YAML field
new Setting(containerEl)
.setName("Frontmatter property prefix")