mirror of
https://github.com/ryanpcmcquen/obsidian-javascript-init.git
synced 2026-07-22 06:00:30 +00:00
Hello Unix line endings.
Signed-off-by: Ryan McQuen <rpcm@linux.com>
This commit is contained in:
parent
5f9b034887
commit
23c4a1cadf
8 changed files with 173 additions and 172 deletions
28
.gitignore
vendored
28
.gitignore
vendored
|
|
@ -1,14 +1,14 @@
|
|||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
package-lock.json
|
||||
|
||||
# build
|
||||
main.js
|
||||
*.js.map
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
package-lock.json
|
||||
|
||||
# build
|
||||
main.js
|
||||
*.js.map
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
|
|
|
|||
14
README.md
14
README.md
|
|
@ -1,7 +1,7 @@
|
|||
## Obsidian JavaScript Init
|
||||
|
||||
Run JavaScript when Obsidian loads, or any other time.
|
||||
|
||||
### Manually installing the plugin
|
||||
|
||||
- Copy over `main.js` and `manifest.json` to your vault `VaultFolder/.obsidian/plugins/obsidian-javascript-init/`.
|
||||
## Obsidian JavaScript Init
|
||||
|
||||
Run JavaScript when Obsidian loads, or any other time.
|
||||
|
||||
### Manually installing the plugin
|
||||
|
||||
- Copy over `main.js` and `manifest.json` to your vault `VaultFolder/.obsidian/plugins/obsidian-javascript-init/`.
|
||||
|
|
|
|||
196
main.ts
196
main.ts
|
|
@ -1,98 +1,98 @@
|
|||
import { App, Notice, Plugin, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
interface JavaScriptInitPluginSettings {
|
||||
code: string;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: JavaScriptInitPluginSettings = {
|
||||
code: "",
|
||||
};
|
||||
|
||||
export default class JavaScriptInitPlugin extends Plugin {
|
||||
settings: JavaScriptInitPluginSettings;
|
||||
|
||||
runCode(code = this.settings.code) {
|
||||
const source = String(code);
|
||||
const appendedScript = document.createElement("script");
|
||||
appendedScript.textContent = source;
|
||||
(document.head || document.documentElement).appendChild(appendedScript);
|
||||
}
|
||||
|
||||
async onload() {
|
||||
console.log("Loading Custom JavaScript plugin ...");
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
this.addRibbonIcon("dice", "Custom JavaScript Plugin", () => {
|
||||
this.runCode();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "run-custom-javascript",
|
||||
name: "Run Custom JavaScript",
|
||||
callback: () => {
|
||||
this.runCode();
|
||||
},
|
||||
});
|
||||
|
||||
this.addSettingTab(new JavaScriptInitSettingTab(this.app, this));
|
||||
|
||||
console.log(this.settings);
|
||||
this
|
||||
.runCode
|
||||
// `document.addEventListener("DOMContentLoaded", () => { ${this.settings.code}; });`
|
||||
();
|
||||
}
|
||||
|
||||
onunload() {
|
||||
console.log("Unloading Custom JavaScript plugin ...");
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign(
|
||||
{},
|
||||
DEFAULT_SETTINGS,
|
||||
await this.loadData()
|
||||
);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
|
||||
class JavaScriptInitSettingTab extends PluginSettingTab {
|
||||
plugin: JavaScriptInitPlugin;
|
||||
|
||||
constructor(app: App, plugin: JavaScriptInitPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
let { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h2", { text: "Custom JavaScript Settings." });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Code")
|
||||
.setDesc("Custom code to execute on startup or on demand.")
|
||||
.addTextArea((text) => {
|
||||
const resultant = text
|
||||
|
||||
.setPlaceholder("Sweet code here ...")
|
||||
.setValue(this.plugin.settings.code || "")
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.code = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
|
||||
resultant.inputEl.style.fontFamily = "monospace";
|
||||
resultant.inputEl.style.width = "100%";
|
||||
|
||||
return resultant;
|
||||
});
|
||||
}
|
||||
}
|
||||
import { App, Plugin, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
type JavaScriptInitPluginSettings = {
|
||||
code: string;
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS: JavaScriptInitPluginSettings = {
|
||||
code: "",
|
||||
};
|
||||
|
||||
export default class JavaScriptInitPlugin extends Plugin {
|
||||
settings: JavaScriptInitPluginSettings;
|
||||
|
||||
runCode(code = this.settings.code) {
|
||||
const source = String(code);
|
||||
const appendedScript = document.createElement("script");
|
||||
appendedScript.textContent = source;
|
||||
(document.head || document.documentElement).appendChild(appendedScript);
|
||||
}
|
||||
|
||||
async onload() {
|
||||
console.log("Loading JavaScript Init plugin ...");
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
this.addRibbonIcon("dice", "Run Init JavaScript", () => {
|
||||
this.runCode();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "run-init-javascript",
|
||||
name: "Run Init JavaScript",
|
||||
callback: () => {
|
||||
this.runCode();
|
||||
},
|
||||
});
|
||||
|
||||
this.addSettingTab(new JavaScriptInitSettingTab(this.app, this));
|
||||
|
||||
console.log(this.settings);
|
||||
this
|
||||
.runCode
|
||||
// `document.addEventListener("DOMContentLoaded", () => { ${this.settings.code}; });`
|
||||
();
|
||||
}
|
||||
|
||||
onunload() {
|
||||
console.log("Unloading JavaScript Init plugin ...");
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign(
|
||||
{},
|
||||
DEFAULT_SETTINGS,
|
||||
await this.loadData()
|
||||
);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
|
||||
class JavaScriptInitSettingTab extends PluginSettingTab {
|
||||
plugin: JavaScriptInitPlugin;
|
||||
|
||||
constructor(app: App, plugin: JavaScriptInitPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
let { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h2", { text: "JavaScript Init Settings." });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Code")
|
||||
.setDesc("Custom code to execute on startup or on demand.")
|
||||
.addTextArea((text) => {
|
||||
const resultant = text
|
||||
|
||||
.setPlaceholder("Sweet code here ...")
|
||||
.setValue(this.plugin.settings.code || "")
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.code = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
|
||||
resultant.inputEl.style.fontFamily = "monospace";
|
||||
resultant.inputEl.style.width = "100%";
|
||||
|
||||
return resultant;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"id": "obsidian-javascript-init",
|
||||
"name": "JavaScript Init",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.9.12",
|
||||
"description": "Run JavaScript when Obsidian loads, or any other time.",
|
||||
"author": "ryanpcmcquen",
|
||||
"authorUrl": "https://github.com/ryanpcmcquen",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
{
|
||||
"id": "obsidian-javascript-init",
|
||||
"name": "JavaScript Init",
|
||||
"version": "1.0.0",
|
||||
"minAppVersion": "0.9.12",
|
||||
"description": "Run JavaScript when Obsidian loads, or any other time.",
|
||||
"author": "ryanpcmcquen",
|
||||
"authorUrl": "https://github.com/ryanpcmcquen",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MPL-2.0",
|
||||
"repository": "https://github.com/ryanpcmcquen/obsidian-javascript-init",
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^18.0.0",
|
||||
"@rollup/plugin-node-resolve": "^11.2.1",
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
import typescript from "@rollup/plugin-typescript";
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
|
||||
const isProd = process.env.BUILD === "production";
|
||||
|
||||
const banner = `/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
|
||||
if you want to view the source visit the plugins github repository
|
||||
*/
|
||||
`;
|
||||
|
||||
export default {
|
||||
input: "main.ts",
|
||||
output: {
|
||||
dir: ".",
|
||||
sourcemap: "inline",
|
||||
sourcemapExcludeSources: isProd,
|
||||
format: "cjs",
|
||||
exports: "default",
|
||||
banner,
|
||||
},
|
||||
external: ["obsidian"],
|
||||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()],
|
||||
};
|
||||
import typescript from "@rollup/plugin-typescript";
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
|
||||
const isProd = process.env.BUILD === "production";
|
||||
|
||||
const banner = `/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
|
||||
if you want to view the source visit the plugins github repository
|
||||
*/
|
||||
`;
|
||||
|
||||
export default {
|
||||
input: "main.ts",
|
||||
output: {
|
||||
dir: ".",
|
||||
sourcemap: "inline",
|
||||
sourcemapExcludeSources: isProd,
|
||||
format: "cjs",
|
||||
exports: "default",
|
||||
banner,
|
||||
},
|
||||
external: ["obsidian"],
|
||||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"module": "ESNext",
|
||||
"target": "es6",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"lib": ["dom", "es5", "scripthost", "es2015"]
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"module": "ESNext",
|
||||
"target": "es6",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"lib": ["dom", "es5", "scripthost", "es2015"]
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"1.0.0": "0.9.12"
|
||||
}
|
||||
{
|
||||
"1.0.0": "0.9.12"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue