mirror of
https://wiilab.wiimart.org/wiimart/wiimart-extension
synced 2025-09-02 19:41:00 +02:00
49 lines
2.0 KiB
JavaScript
49 lines
2.0 KiB
JavaScript
// popup.js
|
|
const STORAGE_ENDPOINT = '/_extension_storage'; // Your existing storage endpoint
|
|
|
|
document.getElementById('clearTrace').addEventListener('click', function() {
|
|
fetch(`${STORAGE_ENDPOINT}?clogs=true`)
|
|
.catch(() => {});
|
|
document.getElementById('cleared').textContent = 'Cleared: trace';
|
|
});
|
|
|
|
document.getElementById('clearPoints').addEventListener('click', function() {
|
|
fetch(`${STORAGE_ENDPOINT}?cpts=true`)
|
|
.catch(() => {});
|
|
document.getElementById('cleared').textContent = 'Cleared: points';
|
|
});
|
|
|
|
// Handle the checkbox for enabling/disabling the font
|
|
document.getElementById('toggleFont').addEventListener('change', function() {
|
|
const isChecked = this.checked;
|
|
// Set the font state in the extension's storage
|
|
// Using chrome.storage.local for consistency with browser extension APIs
|
|
chrome.storage.local.set({ fontEnabled: isChecked }); // Renamed key to 'fontEnabled' for clarity
|
|
});
|
|
|
|
// Check the current font state when the popup is opened
|
|
chrome.storage.local.get(['fontEnabled'], function(result) {
|
|
// Default to true if not set (font enabled by default)
|
|
document.getElementById('toggleFont').checked = (result.fontEnabled !== false);
|
|
});
|
|
|
|
|
|
// --- NEW BGM TOGGLE LOGIC ---
|
|
document.getElementById('toggleBGM').addEventListener('change', function() {
|
|
const isChecked = this.checked;
|
|
chrome.storage.local.set({ bgmEnabled: isChecked }, function() {
|
|
// Optionally, send a message to content scripts to update immediately
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, {
|
|
action: "toggleBGM",
|
|
enabled: isChecked
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
// Check the current BGM state when the popup is opened
|
|
chrome.storage.local.get(['bgmEnabled'], function(result) {
|
|
// Default to false if not set (BGM disabled by default on startup)
|
|
document.getElementById('toggleBGM').checked = (result.bgmEnabled === true);
|
|
}); |