Zlef's modal and settings

Modal and settings framework, designed with Idle Pixel in mind but expanded beyond that scope.

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/538225/1603175/Zlef%27s%20modal%20and%20settings.js

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
Ryan (Zlef)
版本
1.0.2
创建于
2025-06-03
更新于
2025-06-07
大小
29.9 KB
许可证
MIT

The testing I originally used, documentation requires refinement:
class ModalTesting {
constructor() {
const pluginName = 'ModalTesting'
this.modal = new Modal(pluginName);

this.defaultSettings = {
'testNumInput': {type: 'numinput', value: 10, minValue: 0, maxValue: 20},
'section1': {
type: 'section',
name: "Section 1",
settings: {
'testCheckbox': {type: 'checkbox', value: true},
'testInput': {type: "text", value: "Hello", placeholder: "Hello message!"},
'testCheckboxes': {type: 'multicheckbox', name: 'Test Checkboxes', values: {'apple': true, 'pear': false, 'banana': true, 'cooked_chicken': false, 'cooked_bird_meat': false, 'cooked_meat': false, 'honey': false, 'cheese': false,}},
}
},
'section2': {
type: 'section',
name: "Section 2",
settings: {
'testRadio': {type: 'radio', options: ["item1", "item2", "item3"], value: "item1"},
'testCombo': {type: 'combobox', options: ['apple', 'banana', 'pear'], value: "apple"}
}
},
'testInputNoSection': {type: "text", value: "Free from sections", placeholder: "Hello message!"},
'testInputNoSection1': {type: "text", value: "Free from sections", placeholder: "Hello message!"}
};

// Plugin name for prefix, sets storage key etc, needs to be unique.
this.settingsManager = new SettingsManager(pluginName, this.defaultSettings);
this.settings = this.settingsManager.getSettings();

this.settingsModal = this.settingsManager.createSettingsContent(this.modal, 'auto', 'auto', this.onSettingsModalClose)

this.testButtons();

}

onSettingsModalClose() {
console.log('Settings modal closed');
}

testButtons() {
console.log("Adding buttons");

const container = document.createElement('div');
container.style.position = 'fixed';
container.style.top = '0';
container.style.left = '0';
container.style.zIndex = '9999';
container.style.background = 'rgba(255,255,255,0.9)';
container.style.padding = '5px';
container.style.borderBottom = '1px solid #ccc';

const testButton = this.createButton('Test Modal', () => this.settingsModal());
const resetButton = this.createButton('Reset settings', () => this.settingsManager.resetSettings());
const deleteButton = this.createButton('Delete from local', () => this.settingsManager.deleteSettings());
const logButton = this.createButton('Log this.settings', () => console.log(this.settings));
const differentModalButton = this.createButton('Open a different modal', () => this.differentModal());
const floatingModalButton = this.createButton('Open a floating modal', () => this.floatingModal());

[testButton, resetButton, deleteButton, logButton, differentModalButton, floatingModalButton].forEach(button => container.appendChild(button));

document.body.appendChild(container);
}


createButton(text, onClick) {
const button = document.createElement('button');
button.textContent = text;
button.addEventListener('click', onClick);
return button;
}

differentModal() {
const content = document.createElement('div');

this.modal.addTitle(content, "Example Item", 3, 'center');

const container = this.modal.addContainer(content);
const rowDiv = this.modal.addRow(container);
const depositColDiv = this.modal.addCol(rowDiv, undefined, 'centre');
this.modal.addVDivider(rowDiv);
const withdrawColDiv = this.modal.addCol(rowDiv, undefined, 'centre');

this.modal.addTitle(depositColDiv, 'Deposit Amount', 5, 'center');
this.modal.addInput(depositColDiv, 'number', 100, undefined, undefined, undefined, (value) => {
console.log('Deposit amount changed:', value);
});
const depositButton = this.modal.addButton(depositColDiv, 'DEPOSIT', () => {
console.log("Pressed deposit button");
}, 'btn btn-secondary deposit-button');
depositButton.style.backgroundColor = "red";
depositButton.style.color = "white";

this.modal.addTitle(withdrawColDiv, 'Withdraw Amount', 5, 'center');
this.modal.addInput(withdrawColDiv, 'number', 200, undefined, undefined, undefined, (value) => {
console.log('Withdraw amount changed:', value);
});

const withdrawButton = this.modal.addButton(withdrawColDiv, 'WITHDRAW', () => {
const take_amount = document.getElementById('withdrawAmount').value;
console.log("Pressed withdraw button");
}, 'btn btn-secondary withdraw-button');
withdrawButton.style.backgroundColor = "green";
withdrawButton.style.color = "white";

const rowDiv2 = this.modal.addRow(container);
rowDiv2.style.marginTop = "10px";
const section = this.modal.addSection(rowDiv2, "testing")
this.modal.addTitle(section, "Spam to add scroll", 3, 'center');

this.modal.addModal(content, 'Withdraw Modal', 500, 'auto', () => {
console.log('Modal closed');
});

}


floatingModal() {
const content = document.createElement('div');

this.modal.addTitle(content, "Example Item", 3, 'center');

const container = this.modal.addContainer(content);
const rowDiv = this.modal.addRow(container);
const depositColDiv = this.modal.addCol(rowDiv, undefined, 'centre');
this.modal.addVDivider(rowDiv);
const withdrawColDiv = this.modal.addCol(rowDiv, undefined, 'centre');

this.modal.addTitle(depositColDiv, 'Deposit Amount', 5, 'center');
this.modal.addInput(depositColDiv, 'number', 100, undefined, undefined, undefined, (value) => {
console.log('Deposit amount changed:', value);
});
const depositButton = this.modal.addButton(depositColDiv, 'DEPOSIT', () => {
console.log("Pressed deposit button");
}, 'btn btn-secondary deposit-button');
depositButton.style.backgroundColor = "red";
depositButton.style.color = "white";

this.modal.addTitle(withdrawColDiv, 'Withdraw Amount', 5, 'center');
this.modal.addInput(withdrawColDiv, 'number', 200, undefined, undefined, undefined, (value) => {
console.log('Withdraw amount changed:', value);
});

const withdrawButton = this.modal.addButton(withdrawColDiv, 'WITHDRAW', () => {
const take_amount = document.getElementById('withdrawAmount').value;
console.log("Pressed withdraw button");
}, 'btn btn-secondary withdraw-button');
withdrawButton.style.backgroundColor = "green";
withdrawButton.style.color = "white";

const rowDiv2 = this.modal.addRow(container);
rowDiv2.style.marginTop = "10px";
const section = this.modal.addSection(rowDiv2, "testing")
this.modal.addTitle(section, "Spam to add scroll", 3, 'center');

this.modal.addFloatingModal(content, 'Withdraw Modal', 500, 'auto', () => {
console.log('Modal closed');
});

}
}