diff options
| author | Agando <roduccomm@gmail.com> | 2026-05-25 18:02:02 +0200 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-05-25 18:02:02 +0200 |
| commit | 4baa484b84c5184286cac2743575251454a5ee2b (patch) | |
| tree | cb9002f93644f363d0f35831dc97e6492bbb0ed6 /modules/core/module-my.js | |
auto: 2026-05-25_18:02 changes
Diffstat (limited to 'modules/core/module-my.js')
| -rw-r--r-- | modules/core/module-my.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/modules/core/module-my.js b/modules/core/module-my.js new file mode 100644 index 0000000..5fc13ca --- /dev/null +++ b/modules/core/module-my.js @@ -0,0 +1,82 @@ +class MyModule { + constructor() { + this.commands = {}; this.terminal = null; this.userData = {}; + try { const d = localStorage.getItem('webx11_my_data'); if (d) this.userData = JSON.parse(d); } catch (e) {} + } + getHelpInfo() { + return { + 'my': 'my — Show module info and stored key count', + 'my-set': 'my-set <key> <value> — Store a key-value pair', + 'my-get': 'my-get <key> — Retrieve a stored value by key', + 'my-list': 'my-list — List all stored keys', + 'my-export': 'my-export — Export all stored data as JSON', + 'my-import': 'my-import <json> — Import data from JSON string', + 'my-clear': 'my-clear — Clear all stored data' + }; + } + _save() { + try { localStorage.setItem('webx11_my_data', JSON.stringify(this.userData)); } catch (e) {} + } + registerCommands() { + this.commands['my'] = () => this.showInfo(); + this.commands['my-set'] = (args) => this.setData(args); + this.commands['my-get'] = (args) => this.getData(args); + this.commands['my-list'] = () => this.listData(); + this.commands['my-export'] = () => this.exportData(); + this.commands['my-import'] = (args) => this.importData(args); + this.commands['my-clear'] = () => this.clearData(); + } + showInfo() { + this.terminal.print("=== My Module v2.0 ===", "info"); + this.terminal.print("Personal workspace for custom commands"); + this.terminal.print(`Stored keys: ${Object.keys(this.userData).length}`, "success"); + } + setData(args) { + if (args.length < 2) { + this.terminal.print("Usage: my-set <key> <value>", "warning"); return; + } + const key = args[0], value = args.slice(1).join(' '); + this.userData[key] = { value, timestamp: new Date().toISOString() }; + this._save(); + this.terminal.print(`Saved: ${key} = ${value}`, "success"); + } + getData(args) { + if (!args[0]) { + this.terminal.print("Usage: my-get <key>", "warning"); return; + } + if (this.userData[args[0]]) { + this.terminal.print(`${args[0]}: ${this.userData[args[0]].value}`, "info"); + } else { + this.terminal.print(`Key '${args[0]}' not found`, "error"); + } + } + listData() { + const keys = Object.keys(this.userData); + if (!keys.length) return this.terminal.print('No data stored.', 'info'); + this.terminal.print('=== My Data ===', 'info'); + keys.forEach(k => { + const v = this.userData[k]; + const type = typeof v.value; + this.terminal.print(` ${k} (${type}): ${String(v.value).substring(0, 40)}`); + }); + } + exportData() { + this.terminal.print(JSON.stringify(this.userData, null, 2)); + } + importData(args) { + if (!args[0]) return this.terminal.print('Usage: my-import <json>', 'warning'); + try { + const data = JSON.parse(args.join(' ')); + Object.assign(this.userData, data); + this._save(); + this.terminal.print(`Imported ${Object.keys(data).length} keys`, 'success'); + } catch (e) { + this.terminal.print('Invalid JSON: ' + e.message, 'error'); + } + } + clearData() { + this.userData = {}; + localStorage.removeItem('webx11_my_data'); + this.terminal.print("Personal data cleared", "success"); + } +} |