chore: checkpoint current working state
This commit is contained in:
@@ -2,6 +2,10 @@ const profileSelect = document.getElementById('profileSelect');
|
||||
const statusEl = document.getElementById('status');
|
||||
const debugToggle = document.getElementById('debugLoggingToggle');
|
||||
|
||||
function isValidProfileNumber(value) {
|
||||
return Number.isInteger(value) && value >= 1 && value <= 5;
|
||||
}
|
||||
|
||||
function apiFetch(url, options = {}) {
|
||||
const config = {
|
||||
...options,
|
||||
@@ -61,7 +65,7 @@ function updateStatus(message, saved = false) {
|
||||
|
||||
async function initProfileSelect() {
|
||||
const backendProfile = await fetchProfileState();
|
||||
if (backendProfile) {
|
||||
if (isValidProfileNumber(backendProfile)) {
|
||||
profileSelect.value = String(backendProfile);
|
||||
chrome.storage.sync.set({ profileNumber: backendProfile });
|
||||
updateStatus(`Profil ${backendProfile} ausgewählt`);
|
||||
@@ -69,9 +73,14 @@ async function initProfileSelect() {
|
||||
}
|
||||
|
||||
chrome.storage.sync.get(['profileNumber'], (result) => {
|
||||
const profileNumber = result.profileNumber || 1;
|
||||
profileSelect.value = String(profileNumber);
|
||||
updateStatus(`Profil ${profileNumber} ausgewählt (lokal)`);
|
||||
const profileNumber = result.profileNumber;
|
||||
if (isValidProfileNumber(profileNumber)) {
|
||||
profileSelect.value = String(profileNumber);
|
||||
updateStatus(`Profil ${profileNumber} ausgewählt (lokal)`);
|
||||
return;
|
||||
}
|
||||
profileSelect.value = '';
|
||||
updateStatus('Bitte zuerst ein Profil auswählen.');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,6 +110,10 @@ function reloadFacebookTabs() {
|
||||
|
||||
document.getElementById('saveBtn').addEventListener('click', async () => {
|
||||
const profileNumber = parseInt(profileSelect.value, 10);
|
||||
if (!isValidProfileNumber(profileNumber)) {
|
||||
updateStatus('Bitte zuerst ein Profil auswählen.');
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.storage.sync.set({ profileNumber }, async () => {
|
||||
updateStatus(`Profil ${profileNumber} gespeichert!`, true);
|
||||
|
||||
Reference in New Issue
Block a user