@@ -409,6 +426,66 @@
}
});
+ document
+ .getElementById("open-plugin-icon")
+ .addEventListener("click", () => {
+ const input = document.createElement("input");
+ input.type = "file";
+ input.accept = ".js";
+ input.onchange = (e) => {
+ const file = e.target.files[0];
+ const reader = new FileReader();
+ reader.onload = (event) => {
+ try {
+ // Load and execute JavaScript code from the file
+ new Function(event.target.result)();
+ alert(`Plugin "${file.name}" executed successfully.`);
+ } catch (err) {
+ alert(`Failed to execute plugin "${file.name}": ${err.message}`);
+ }
+ };
+ reader.readAsText(file);
+ };
+ input.click();
+ });
+
+ document
+ .getElementById("open-folder-plugins-icon")
+ .addEventListener("click", () => {
+ const input = document.createElement("input");
+ input.type = "file";
+ input.webkitdirectory = true;
+ input.onchange = (e) => {
+ const folderFiles = e.target.files;
+ let allFilesLoaded = true;
+
+ for (let i = 0; i < folderFiles.length; i++) {
+ const file = folderFiles[i];
+ if (file.name.endsWith(".js")) {
+ const reader = new FileReader();
+ reader.onload = (event) => {
+ try {
+ // Load and execute JavaScript code from the file
+ new Function(event.target.result)();
+ console.log(`Plugin "${file.name}" executed successfully.`);
+ } catch (err) {
+ console.error(`Failed to execute plugin "${file.name}": ${err.message}`);
+ allFilesLoaded = false;
+ }
+ };
+ reader.readAsText(file);
+ }
+ }
+
+ if (allFilesLoaded) {
+ alert("All plugins executed successfully.");
+ } else {
+ alert("Some plugins failed to execute. Check console for details.");
+ }
+ };
+ input.click();
+ });
+
editor.on("change", () => {
files[currentFile] = editor.getValue();
});