User:Stumblean/common.js: Difference between revisions
Appearance
No edit summary Tags: Mobile edit Mobile web edit Advanced mobile edit |
No edit summary Tags: Reverted Mobile edit Mobile web edit Advanced mobile edit |
||
Line 22: | Line 22: | ||
}; | }; | ||
let settings = JSON.parse(localStorage.getItem("mahitoMenuSettings")) || defaultSettings; | |||
let prefs = JSON.parse(localStorage.getItem("mahitoMenuPrefs")) || defaultPrefs; | |||
function saveSettings() { | function saveSettings() { | ||
Line 32: | Line 32: | ||
} | } | ||
// ... (rest of your menu creation code here, unchanged) | |||
// -- Snippet for Preferences Panel -- | |||
const prefsPanel = document.createElement("div"); | const prefsPanel = document.createElement("div"); | ||
Object.assign(prefsPanel.style, { | Object.assign(prefsPanel.style, { | ||
Line 282: | Line 77: | ||
prefsPanel.appendChild(createCheckbox("Show Watermark Footer", "showWatermark")); | prefsPanel.appendChild(createCheckbox("Show Watermark Footer", "showWatermark")); | ||
// Add Reset Preferences Button | |||
const resetPrefsBtn = document.createElement("button"); | |||
resetPrefsBtn.textContent = "Reset Preferences"; | |||
Object.assign(resetPrefsBtn.style, { | |||
background: "#cc4444", | |||
color: "#fff", | |||
border: "none", | |||
borderRadius: "5px", | |||
padding: "6px 10px", | |||
marginTop: "10px", | |||
cursor: "pointer", | |||
width: "100%" | |||
Object.assign( | |||
}); | }); | ||
resetPrefsBtn.addEventListener("click", () => { | |||
if (confirm("Are you sure you want to reset all preferences to default?")) { | |||
prefs = {...defaultPrefs}; // reset to default | |||
savePrefs(); | |||
applyPreferences(); | |||
// Update all checkboxes to reflect defaults | |||
[...prefsPanel.querySelectorAll("input[type=checkbox]")].forEach(input => { | |||
input.checked = prefs[input.parentNode.textContent.trim().toLowerCase().includes("mass undo") ? "showMassUndo" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("explanation") ? "showExplanation" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("encouragement") ? "showEncouragement" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("yujify") ? "showYujify" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("customize") ? "showCustomize" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("undo changes") ? "showUndoChanges" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("preferences") ? "showPreferences" : | |||
input.parentNode.textContent.trim().toLowerCase().includes("watermark") ? "showWatermark" : "" | |||
]; | |||
}); | |||
} | |||
}); | }); | ||
prefsPanel.appendChild(resetPrefsBtn); | |||
// | // ... (append prefsPanel and other elements to menu as in your full code) | ||
// | // (rest of your applyPreferences function, menu setup, button creation, etc. stays the same) | ||
})(); | })(); |
Revision as of 18:45, 28 June 2025
(function () {
const defaultSettings = {
menuTitle: "Mahito Menu",
iconURL: "https://files.catbox.moe/wk78nl.jpg",
backgroundColor: "#7889B2",
buttonColor: "#45A8C5",
textColor: "#ffffff",
borderColor: "#ffffff",
iconSize: 15,
minimizedSize: 30
};
const defaultPrefs = {
showMassUndo: true,
showExplanation: true,
showEncouragement: true,
showYujify: true,
showCustomize: true,
showUndoChanges: true,
showPreferences: true, // always true so button never hides
showWatermark: true
};
let settings = JSON.parse(localStorage.getItem("mahitoMenuSettings")) || defaultSettings;
let prefs = JSON.parse(localStorage.getItem("mahitoMenuPrefs")) || defaultPrefs;
function saveSettings() {
localStorage.setItem("mahitoMenuSettings", JSON.stringify(settings));
}
function savePrefs() {
localStorage.setItem("mahitoMenuPrefs", JSON.stringify(prefs));
}
// ... (rest of your menu creation code here, unchanged)
// -- Snippet for Preferences Panel --
const prefsPanel = document.createElement("div");
Object.assign(prefsPanel.style, {
backgroundColor: "#333a66",
padding: "8px",
borderRadius: "6px",
marginTop: "10px",
display: "none",
color: "#eee",
fontSize: "13px"
});
function createCheckbox(labelText, prefKey) {
const label = document.createElement("label");
label.style.display = "block";
label.style.marginBottom = "6px";
label.style.cursor = "pointer";
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = prefs[prefKey];
checkbox.style.marginRight = "6px";
checkbox.addEventListener("change", () => {
prefs[prefKey] = checkbox.checked;
savePrefs();
applyPreferences();
});
label.appendChild(checkbox);
label.appendChild(document.createTextNode(labelText));
return label;
}
prefsPanel.appendChild(createCheckbox("Show Mass undo Button", "showMassUndo"));
prefsPanel.appendChild(createCheckbox("Show Explanation Button", "showExplanation"));
prefsPanel.appendChild(createCheckbox("Show Encouragement Button", "showEncouragement"));
prefsPanel.appendChild(createCheckbox("Show YUJIFY Button", "showYujify"));
prefsPanel.appendChild(createCheckbox("Show Customize Menu Button", "showCustomize"));
prefsPanel.appendChild(createCheckbox("Show Undo Changes Button", "showUndoChanges"));
prefsPanel.appendChild(createCheckbox("Show Preferences Button (cannot be hidden)", "showPreferences"));
prefsPanel.appendChild(createCheckbox("Show Watermark Footer", "showWatermark"));
// Add Reset Preferences Button
const resetPrefsBtn = document.createElement("button");
resetPrefsBtn.textContent = "Reset Preferences";
Object.assign(resetPrefsBtn.style, {
background: "#cc4444",
color: "#fff",
border: "none",
borderRadius: "5px",
padding: "6px 10px",
marginTop: "10px",
cursor: "pointer",
width: "100%"
});
resetPrefsBtn.addEventListener("click", () => {
if (confirm("Are you sure you want to reset all preferences to default?")) {
prefs = {...defaultPrefs}; // reset to default
savePrefs();
applyPreferences();
// Update all checkboxes to reflect defaults
[...prefsPanel.querySelectorAll("input[type=checkbox]")].forEach(input => {
input.checked = prefs[input.parentNode.textContent.trim().toLowerCase().includes("mass undo") ? "showMassUndo" :
input.parentNode.textContent.trim().toLowerCase().includes("explanation") ? "showExplanation" :
input.parentNode.textContent.trim().toLowerCase().includes("encouragement") ? "showEncouragement" :
input.parentNode.textContent.trim().toLowerCase().includes("yujify") ? "showYujify" :
input.parentNode.textContent.trim().toLowerCase().includes("customize") ? "showCustomize" :
input.parentNode.textContent.trim().toLowerCase().includes("undo changes") ? "showUndoChanges" :
input.parentNode.textContent.trim().toLowerCase().includes("preferences") ? "showPreferences" :
input.parentNode.textContent.trim().toLowerCase().includes("watermark") ? "showWatermark" : ""
];
});
}
});
prefsPanel.appendChild(resetPrefsBtn);
// ... (append prefsPanel and other elements to menu as in your full code)
// (rest of your applyPreferences function, menu setup, button creation, etc. stays the same)
})();