ObsidianJustSharePlease/test-vault/.obsidian/plugins/just-share-please/main

163 lines
17 KiB
Text
Raw Normal View History

2023-06-25 18:16:06 +02:00
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/main.ts
__export(exports, {
default: () => JustSharePleasePlugin
});
var import_obsidian2 = __toModule(require("obsidian"));
// src/settings.ts
2023-08-11 19:01:10 +02:00
var defaultSettings = {
url: "http://localhost:8080",
shared: []
};
2023-06-25 18:16:06 +02:00
// src/settings-tab.ts
var import_obsidian = __toModule(require("obsidian"));
var JSPSettingsTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
this.containerEl.empty();
this.containerEl.createEl("h2", { text: "Just Share Please Settings" });
this.containerEl.createEl("hr");
this.containerEl.createEl("p", { text: "If you like this plugin and want to support its development, you can do so through my website by clicking this fancy image!" });
this.containerEl.createEl("a", { href: "https://ellpeck.de/support" }).createEl("img", {
attr: { src: "https://ellpeck.de/res/generalsupport.png" },
cls: "just-share-please-support"
});
}
};
// src/main.ts
var JustSharePleasePlugin = class extends import_obsidian2.Plugin {
onload() {
return __async(this, null, function* () {
yield this.loadSettings();
this.addSettingTab(new JSPSettingsTab(this.app, this));
2023-08-11 19:01:10 +02:00
this.registerEvent(this.app.workspace.on("file-menu", (m, f) => __async(this, null, function* () {
if (f instanceof import_obsidian2.TFile) {
let shared = this.settings.shared.find((i) => i.path == f.path);
if (!shared) {
m.addItem((i) => {
i.setTitle("Share to JSP");
i.setIcon("share");
i.onClick(() => __async(this, null, function* () {
let response = yield (0, import_obsidian2.requestUrl)({
url: `${this.settings.url}/share.php`,
method: "POST",
body: JSON.stringify({ content: yield this.app.vault.cachedRead(f) }),
throw: false
});
console.log(response.status + " " + response.text);
if (response.status == 200) {
shared = response.json;
shared.path = f.path;
this.settings.shared.push(shared);
yield this.saveSettings();
}
}));
});
} else {
m.addItem((i) => {
i.setTitle("Copy JSP link");
i.setIcon("link");
i.onClick(() => navigator.clipboard.writeText(`${this.settings.url}#${shared.id}`));
});
m.addItem((i) => {
i.setTitle("Update in JSP");
i.setIcon("share");
i.onClick(() => __async(this, null, function* () {
let response = yield (0, import_obsidian2.requestUrl)({
url: `${this.settings.url}/share.php?id=${shared.id}`,
method: "PATCH",
headers: { "Password": shared.password },
body: JSON.stringify({ content: yield this.app.vault.cachedRead(f) }),
throw: false
});
console.log(response.status + " " + response.text);
}));
});
m.addItem((i) => {
i.setTitle("Delete from JSP");
i.setIcon("trash");
i.onClick(() => __async(this, null, function* () {
let response = yield (0, import_obsidian2.requestUrl)({
url: `${this.settings.url}/share.php?id=${shared.id}`,
method: "DELETE",
headers: { "Password": shared.password },
throw: false
});
console.log(response.status);
if (response.status == 200) {
this.settings.shared.remove(shared);
yield this.saveSettings();
}
}));
});
}
}
})));
2023-06-25 18:16:06 +02:00
});
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, defaultSettings, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
};
2023-08-11 19:01:10 +02:00
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsic3JjL21haW4udHMiLCAic3JjL3NldHRpbmdzLnRzIiwgInNyYy9zZXR0aW5ncy10YWIudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImltcG9ydCB7UGx1Z2luLCByZXF1ZXN0VXJsLCBURmlsZX0gZnJvbSBcIm9ic2lkaWFuXCI7XHJcbmltcG9ydCB7ZGVmYXVsdFNldHRpbmdzLCBKU1BTZXR0aW5ncywgU2hhcmVkSXRlbX0gZnJvbSBcIi4vc2V0dGluZ3NcIjtcclxuaW1wb3J0IHtKU1BTZXR0aW5nc1RhYn0gZnJvbSBcIi4vc2V0dGluZ3MtdGFiXCI7XHJcblxyXG5leHBvcnQgZGVmYXVsdCBjbGFzcyBKdXN0U2hhcmVQbGVhc2VQbHVnaW4gZXh0ZW5kcyBQbHVnaW4ge1xyXG5cclxuICAgIC8vIFRPRE8gYWxsb3cgZGVsZXRpbmcgdXBsb2FkcyB3aG9zZSBsb2NhbCBmaWxlcyBoYXZlIGJlZW4gZGVsZXRlZCAodGhyb3VnaCBjb21tYW5kPylcclxuICAgIC8vIFRPRE8gYWRkIGEgc2V0dGluZyBmb3IgYXV0by1yZWZyZXNoaW5nIHVwbG9hZHMgd2hlbiBzYXZpbmdcclxuICAgIC8vIFRPRE8gc3RyaXAgZnJvbnRtYXR0ZXIgYmVmb3JlIHVwbG9hZGluZz8gbWF5YmUgb3B0aW9uYWxseVxyXG4gICAgc2V0dGluZ3M6IEpTUFNldHRpbmdzO1xyXG5cclxuICAgIGFzeW5jIG9ubG9hZCgpOiBQcm9taXNlPHZvaWQ+IHtcclxuICAgICAgICBhd2FpdCB0aGlzLmxvYWRTZXR0aW5ncygpO1xyXG4gICAgICAgIHRoaXMuYWRkU2V0dGluZ1RhYihuZXcgSlNQU2V0dGluZ3NUYWIodGhpcy5hcHAsIHRoaXMpKTtcclxuXHJcbiAgICAgICAgdGhpcy5yZWdpc3RlckV2ZW50KHRoaXMuYXBwLndvcmtzcGFjZS5vbihcImZpbGUtbWVudVwiLCBhc3luYyAobSwgZikgPT4ge1xyXG4gICAgICAgICAgICBpZiAoZiBpbnN0YW5jZW9mIFRGaWxlKSB7XHJcbiAgICAgICAgICAgICAgICBsZXQgc2hhcmVkID0gdGhpcy5zZXR0aW5ncy5zaGFyZWQuZmluZChpID0+IGkucGF0aCA9PSBmLnBhdGgpO1xyXG4gICAgICAgICAgICAgICAgaWYgKCFzaGFyZWQpIHtcclxuICAgICAgICAgICAgICAgICAgICAvLyAobmV3bHkpIHNoYXJlIGEgbm90ZVxyXG4gICAgICAgICAgICAgICAgICAgIG0uYWRkSXRlbShpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaS5zZXRUaXRsZShcIlNoYXJlIHRvIEpTUFwiKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaS5zZXRJY29uKFwic2hhcmVcIik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGkub25DbGljayhhc3luYyAoKSA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcmVzcG9uc2UgPSBhd2FpdCByZXF1ZXN0VXJsKHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cmw6IGAke3RoaXMuc2V0dGluZ3MudXJsfS9zaGFyZS5waHBgLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1ldGhvZDogXCJQT1NUXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYm9keTogSlNPTi5zdHJpbmdpZnkoe2NvbnRlbnQ6IGF3YWl0IHRoaXMuYXBwLnZhdWx0LmNhY2hlZFJlYWQoZil9KSxcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aHJvdzogZmFsc2VcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xyXG5cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFRPRE8gZGlzcGxheSBtZXNzYWdlIGFib3V0IHN0YXR1cyBzdWNjZXNzL2ZhaWwgYW5kIGNvcHkgVVJMIHRvIGNsaXBib2FyZFxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2Uuc3RhdHVzICsgXCIgXCIgKyByZXNwb25zZS50ZXh0KTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzID09IDIwMCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNoYXJlZCA9IHJlc3BvbnNlLmpzb247XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hhcmVkLnBhdGggPSBmLnBhdGg7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5zZXR0aW5ncy5zaGFyZWQucHVzaChzaGFyZWQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGF3YWl0IHRoaXMuc2F2ZVNldHRpbmdzKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgICAgICAvLyBjb3B5IG5vdGUgbGlua1xyXG4gICAgICAgICAgICAgICAgICAgIG0uYWRkSXRlbShpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaS5zZXRUaXRsZShcIkNvcHkgSlNQIGxpbmtcIik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGkuc2V0SWNvbihcImxpbmtcIik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFRPRE8gbGV0IHBlb3BsZSBrbm93IHRoaXMgaGFwcGVuZWRcclxuICAgICAgICAgICAgICAgICAgICAgICAgaS5vbkNsaWNrKCgpID0+IG5hdmlnYXRvci5jbGlwYm9hcmQud3JpdGVUZXh0KGAke3RoaXMuc2V0dGluZ3MudXJsfSMke3NoYXJlZC5pZH1gKSk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIC8vIHVwZGF0ZVxyXG4gICAgICAgICAgICAgICAgICAgIG0uYWRkSXRlbShpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaS5zZXRUaXRsZShcIlVwZGF0ZSBpbiBKU1BcIik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGkuc2V0SWNvbihcInNoYXJlXCIpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpLm9uQ2xpY2soYXN5bmMgKCkgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHJlc3BvbnNlID0gYXdhaXQgcmVxdWVzdFVybCh7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXJsOiBgJHt0aGlzLnNldHRpbmdzLnVybH0vc2hhcmUucGhwP2lkP