From b98429d414b95748fb5babf210e17e2fbeceb59a Mon Sep 17 00:00:00 2001
From: city-unit <140349364+city-unit@users.noreply.github.com>
Date: Wed, 2 Aug 2023 00:23:23 -0400
Subject: [PATCH] Actually make this good.
---
example.html | 22 +++++++++++++++++++++-
index.js | 34 ++++++++++++++++++++++++++--------
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/example.html b/example.html
index dba8d32..340069a 100644
--- a/example.html
+++ b/example.html
@@ -1,2 +1,22 @@
\ No newline at end of file
+ It's good practice to separate it out from your code -->
+
+
+
+ Extension Example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.js b/index.js
index 966c29e..1cf888a 100644
--- a/index.js
+++ b/index.js
@@ -4,27 +4,44 @@
//You'll likely need to import extension_settings, getContext, and loadExtensionSettings from extensions.js
import { extension_settings, getContext, loadExtensionSettings } from "../../../extensions.js";
-// Keep track of where your extension is located
-const extensionName = "example-extension";
-const extensionFolderPath = `scripts/extensions/third-party/${extensionName}/`;
+//You'll likely need to import some other functions from the main script
+import { saveSettingsDebounced } from "../../../../script.js";
+
+// Keep track of where your extension is located, name should match repo name
+const extensionName = "st-extension-example";
+const extensionFolderPath = `scripts/extensions/third-party/${extensionName}`;
const extensionSettings = extension_settings[extensionName];
const defaultSettings = {};
-/**
- * Loads the extension settings if they exist, otherwise initializes them to the defaults.
- */
+
+
+// Loads the extension settings if they exist, otherwise initializes them to the defaults.
async function loadSettings() {
//Create the settings if they don't exist
extension_settings[extensionName] = extension_settings[extensionName] || {};
if (Object.keys(extension_settings[extensionName]).length === 0) {
Object.assign(extension_settings[extensionName], defaultSettings);
}
+
+ // Updating settings in the UI
+ $("#example_setting").prop("checked", extension_settings[extensionName].example_setting).trigger("input");
}
+// This function is called when the extension settings are changed in the UI
+function onExampleInput(event) {
+ const value = Boolean($(event.target).prop("checked"));
+ extension_settings[extensionName].example_setting = value;
+ saveSettingsDebounced();
+}
+// This function is called when the button is clicked
function onButtonClick() {
- // This function is called when the button is clicked
// You can do whatever you want here
+ // Let's make a popup appear with the checked setting
+ toastr.info(
+ `The checkbox is ${extension_settings[extensionName].example_setting ? "checked" : "not checked"}`,
+ "A popup appeared because you clicked the button!"
+ );
}
// This function is called when the extension is loaded
@@ -38,7 +55,8 @@ jQuery(async () => {
$("#extensions_settings").append(settingsHtml);
// These are examples of listening for events
- $("#my_button").on("click", onButtonClick());
+ $("#my_button").on("click", onButtonClick);
+ $("#example_setting").on("input", onExampleInput);
// Load settings when starting things up (if you have any)
loadSettings();