rpg-westreiche/RPG/.obsidian/plugins/fantasy-name/main.js
2025-06-04 21:07:47 +02:00

128 lines
No EOL
4.5 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// index.ts
var fantasy_name_exports = {};
__export(fantasy_name_exports, {
default: () => FantasyNameGenerator
});
module.exports = __toCommonJS(fantasy_name_exports);
var import_obsidian = require("obsidian");
var insertName = (editor, name) => {
const cursor = editor.getCursor();
editor.replaceRange(name, cursor);
editor.setCursor(cursor.line, cursor.ch + name.length);
};
var API_URL = "https://fantasyname.lukewh.com?family=t";
var editorCallback = async (editor, { gender, ancestry, family }) => {
let url = API_URL;
const params = [];
if (gender) {
params.push(`gender=${gender}`);
}
if (ancestry) {
params.push(`ancestry=${ancestry}`);
}
if (params.length) {
url = `${url}&${params.join("&")}`;
}
const resp = await (0, import_obsidian.requestUrl)(url);
const name = resp.text;
new import_obsidian.Notice(`Name: ${name}`);
insertName(editor, name);
};
var FantasyNameGenerator = class extends import_obsidian.Plugin {
async onload() {
console.log("loading fantasy-name plugin");
const commands = [
{
id: "fantasy-name-insert-human",
name: "Insert fantasy name: Human",
editorCallback: (editor) => editorCallback(editor, {})
},
{
id: "fantasy-name-insert-human-female",
name: "Insert fantasy name: Human - Female",
editorCallback: (editor) => editorCallback(editor, { gender: "f" /* FEMALE */ })
},
{
id: "fantasy-name-insert-human-male",
name: "Insert fantasy name: Human - Male",
editorCallback: (editor) => editorCallback(editor, { gender: "m" /* MALE */ })
},
{
id: "fantasy-name-insert-elf",
name: "Insert fantasy name: Elf",
editorCallback: (editor) => editorCallback(editor, { ancestry: "e" /* ELF */ })
},
{
id: "fantasy-name-insert-elf-female",
name: "Insert fantasy name: Elf - Female",
editorCallback: (editor) => editorCallback(editor, { ancestry: "e" /* ELF */, gender: "f" /* FEMALE */ })
},
{
id: "fantasy-name-insert-elf-male",
name: "Insert fantasy name: Elf - Male",
editorCallback: (editor) => editorCallback(editor, { ancestry: "e" /* ELF */, gender: "m" /* MALE */ })
},
{
id: "fantasy-name-insert-dwarf",
name: "Insert fantasy name: Dwarf",
editorCallback: (editor) => editorCallback(editor, { ancestry: "d" /* DWARF */ })
},
{
id: "fantasy-name-insert-dwarf-female",
name: "Insert fantasy name: Dwarf - Female",
editorCallback: (editor) => editorCallback(editor, { ancestry: "d" /* DWARF */, gender: "f" /* FEMALE */ })
},
{
id: "fantasy-name-insert-dwarf-male",
name: "Insert fantasy name: Dwarf - Male",
editorCallback: (editor) => editorCallback(editor, { ancestry: "d" /* DWARF */, gender: "m" /* MALE */ })
},
{
id: "fantasy-name-insert-orc",
name: "Insert fantasy name: Orc",
editorCallback: (editor) => editorCallback(editor, { ancestry: "o" /* ORC */ })
},
{
id: "fantasy-name-insert-orc-female",
name: "Insert fantasy name: Orc - Female",
editorCallback: (editor) => editorCallback(editor, { ancestry: "o" /* ORC */, gender: "f" /* FEMALE */ })
},
{
id: "fantasy-name-insert-orc-male",
name: "Insert fantasy name: Orc - Male",
editorCallback: (editor) => editorCallback(editor, { ancestry: "o" /* ORC */, gender: "m" /* MALE */ })
}
];
for (const command of commands) {
this.addCommand(command);
}
}
onunload() {
console.log("unloading fantasy-name plugin");
}
};
/* nosourcemap */