options.js aktualisiert
This commit is contained in:
157
options.js
157
options.js
@@ -13,6 +13,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// NEU: Discord Webhook Input
|
// NEU: Discord Webhook Input
|
||||||
const discordWebhookInput = document.getElementById('discord-webhook-url');
|
const discordWebhookInput = document.getElementById('discord-webhook-url');
|
||||||
|
// NEU: Telegram Inputs
|
||||||
|
const telegramBotTokenInput = document.getElementById('telegram-bot-token');
|
||||||
|
const telegramChatIdInput = document.getElementById('telegram-chat-id');
|
||||||
|
|
||||||
// --- Tab-Logik ---
|
// --- Tab-Logik ---
|
||||||
const tabButtons = document.querySelectorAll('.tab-btn');
|
const tabButtons = document.querySelectorAll('.tab-btn');
|
||||||
@@ -86,7 +89,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// Verhindere, dass mehr als MAX_POPUP_SERVERS ausgewählt werden
|
// Verhindere, dass mehr als MAX_POPUP_SERVERS ausgewählt werden
|
||||||
if (selectedServers.length >= MAX_POPUP_SERVERS) {
|
if (selectedServers.length >= MAX_POPUP_SERVERS) {
|
||||||
alert(`Sie können maximal ${MAX_POPUP_SERVERS} Server auswählen.`);
|
alert(`Sie können maximal ${MAX_POPUP_SERVERS} Server auswählen.`);
|
||||||
checkbox.checked = false; // Haken entfernen
|
// Finde die Checkbox und setze den Haken zurück
|
||||||
|
const checkboxId = `popup-server-${service.name.replace(/\s+/g, '-')}`;
|
||||||
|
const checkbox = document.getElementById(checkboxId);
|
||||||
|
if(checkbox) checkbox.checked = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedServers.push(service);
|
selectedServers.push(service);
|
||||||
@@ -259,11 +265,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// --- Settings load/save ---
|
// --- Settings load/save ---
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
// NEU: discordWebhookUrl zu den abgerufenen Daten hinzufügen
|
// NEU: discordWebhookUrl, telegramBotToken und telegramChatId zu den abgerufenen Daten hinzufügen
|
||||||
chrome.storage.sync.get({ checkInterval: 1, notifyOnline: false, discordWebhookUrl: '' }, function(data) {
|
chrome.storage.sync.get({ checkInterval: 1, notifyOnline: false, discordWebhookUrl: '', telegramBotToken: '', telegramChatId: '' }, function(data) {
|
||||||
intervalSelect.value = data.checkInterval;
|
intervalSelect.value = data.checkInterval;
|
||||||
notifyOnlineCheckbox.checked = data.notifyOnline;
|
notifyOnlineCheckbox.checked = data.notifyOnline;
|
||||||
discordWebhookInput.value = data.discordWebhookUrl || ''; // NEU
|
discordWebhookInput.value = data.discordWebhookUrl || '';
|
||||||
|
telegramBotTokenInput.value = data.telegramBotToken || '';
|
||||||
|
telegramChatIdInput.value = data.telegramChatId || '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
intervalSelect.addEventListener('change', () => {
|
intervalSelect.addEventListener('change', () => {
|
||||||
@@ -277,35 +285,71 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
chrome.storage.sync.set({ discordWebhookUrl: discordWebhookInput.value.trim() });
|
chrome.storage.sync.set({ discordWebhookUrl: discordWebhookInput.value.trim() });
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Import/Export ---
|
// NEU: Event Listener für Telegram
|
||||||
|
telegramBotTokenInput.addEventListener('change', () => {
|
||||||
|
chrome.storage.sync.set({ telegramBotToken: telegramBotTokenInput.value.trim() });
|
||||||
|
});
|
||||||
|
telegramChatIdInput.addEventListener('change', () => {
|
||||||
|
chrome.storage.sync.set({ telegramChatId: telegramChatIdInput.value.trim() });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// --- ERWEITERTES Import/Export ---
|
||||||
exportBtn.addEventListener('click', () => {
|
exportBtn.addEventListener('click', () => {
|
||||||
chrome.storage.sync.get({ services: [] }, (data) => {
|
// Rufe alle relevanten Daten aus dem Speicher ab, inklusive der neuen Telegram-Einstellungen
|
||||||
const dataStr = JSON.stringify(data.services, null, 2);
|
chrome.storage.sync.get({
|
||||||
|
services: [],
|
||||||
|
popupServers: [],
|
||||||
|
checkInterval: 1,
|
||||||
|
notifyOnline: false,
|
||||||
|
discordWebhookUrl: '',
|
||||||
|
telegramBotToken: '',
|
||||||
|
telegramChatId: ''
|
||||||
|
}, (data) => {
|
||||||
|
// Erstelle einen String aus den Daten für die JSON-Datei
|
||||||
|
const dataStr = JSON.stringify(data, null, 2);
|
||||||
const blob = new Blob([dataStr], { type: 'application/json' });
|
const blob = new Blob([dataStr], { type: 'application/json' });
|
||||||
const url = URL.createObjectURL(blob); const a = document.createElement('a');
|
const url = URL.createObjectURL(blob);
|
||||||
a.href = url; a.download = 'uptime-services.json';
|
const a = document.createElement('a');
|
||||||
document.body.appendChild(a); a.click();
|
a.href = url;
|
||||||
document.body.removeChild(a); URL.revokeObjectURL(url);
|
a.download = 'uptime-monitor-backup.json'; // Passenderer Dateiname
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
importBtn.addEventListener('click', () => importFileInput.click());
|
importBtn.addEventListener('click', () => importFileInput.click());
|
||||||
importFileInput.addEventListener('change', (event) => {
|
importFileInput.addEventListener('change', (event) => {
|
||||||
const file = event.target.files[0]; if (!file) return;
|
const file = event.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
try { const importedServices = JSON.parse(e.target.result);
|
try {
|
||||||
if (Array.isArray(importedServices)) {
|
const importedData = JSON.parse(e.target.result);
|
||||||
chrome.storage.sync.set({ services: importedServices }, () => {
|
|
||||||
renderServices(searchInput.value.trim());
|
// Prüfe, ob die importierten Daten ein Objekt sind
|
||||||
renderPopupServerSelection(importedServices); // Auch die Auswahl neu rendern
|
if (typeof importedData === 'object' && importedData !== null) {
|
||||||
|
// Setze alle importierten Daten auf einmal
|
||||||
|
chrome.storage.sync.set(importedData, () => {
|
||||||
|
alert('Backup erfolgreich wiederhergestellt! Die Seite wird neu geladen, um alle Änderungen zu übernehmen.');
|
||||||
|
// Nach dem Import ist es am sichersten, die Seite neu zu laden
|
||||||
|
location.reload();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
alert('Ungültiges Dateiformat. Die Datei muss eine gültige Backup-Datei sein.');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler beim Verarbeiten der Import-Datei:', error);
|
||||||
|
alert('Fehler beim Lesen der Datei. Bitte stellen Sie sicher, dass es sich um eine gültige JSON-Datei handelt.');
|
||||||
}
|
}
|
||||||
else { alert('Ungültiges Dateiformat.'); }
|
|
||||||
} catch (error) { alert('Fehler beim Lesen der Datei.'); }
|
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// --- Statistik-Anzeige ---
|
// --- Statistik-Anzeige ---
|
||||||
function showStatsForService(service) {
|
function showStatsForService(service) {
|
||||||
if (!service) return;
|
if (!service) return;
|
||||||
@@ -379,4 +423,79 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
chrome.storage.sync.get({ services: [] }, (data) => {
|
chrome.storage.sync.get({ services: [] }, (data) => {
|
||||||
renderPopupServerSelection(data.services || []);
|
renderPopupServerSelection(data.services || []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- ROBUSTE: Gitea Repository Widget ---
|
||||||
|
// Führt mehrere Suchen durch und kombiniert die Ergebnisse.
|
||||||
|
function fetchAndDisplayGiteaRepos() {
|
||||||
|
const list = document.getElementById('gitea-repos-list');
|
||||||
|
const loadingIndicator = document.getElementById('gitea-repos-loading');
|
||||||
|
const errorIndicator = document.getElementById('gitea-repos-error');
|
||||||
|
|
||||||
|
const searchKeywords = ["Gitea", "Themes", "Server", "Minecraft", "Webseite", "Wordpress", "Plugin", "chrome-erweiterung"];
|
||||||
|
|
||||||
|
loadingIndicator.style.display = 'block';
|
||||||
|
list.style.display = 'none';
|
||||||
|
errorIndicator.style.display = 'none';
|
||||||
|
|
||||||
|
// Erstelle eine Liste von Promises, eine für jede Suchanfrage
|
||||||
|
const searchPromises = searchKeywords.map(keyword => {
|
||||||
|
const apiUrl = `https://git.viper.ipv64.net/api/v1/repos/search?q=${encodeURIComponent(keyword)}&limit=50&sort=updated&order=desc`;
|
||||||
|
return fetch(apiUrl).then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
// Wenn eine Anfrage fehlschlägt, geben wir ein leeres Array zurück, um die anderen nicht zu blockieren
|
||||||
|
console.warn(`Suche nach "${keyword}" fehlgeschlagen:`, response.status);
|
||||||
|
return { data: [] }; // Gib eine leere Antwort-Struktur zurück
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Führe alle Suchanfragen parallel aus
|
||||||
|
Promise.all(searchPromises)
|
||||||
|
.then(results => {
|
||||||
|
// Kombiniere alle Ergebnisse aus den einzelnen Suchen
|
||||||
|
const allRepos = results.flatMap(result => result.data || []);
|
||||||
|
|
||||||
|
// Entferne Duplikate anhand der einzigartigen ID des Repositories
|
||||||
|
const uniqueReposMap = new Map();
|
||||||
|
allRepos.forEach(repo => {
|
||||||
|
uniqueReposMap.set(repo.id, repo);
|
||||||
|
});
|
||||||
|
const uniqueRepos = Array.from(uniqueReposMap.values());
|
||||||
|
|
||||||
|
// Sortiere die kombinierten Repositories nach dem letzten Update-Datum
|
||||||
|
uniqueRepos.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at));
|
||||||
|
|
||||||
|
// Begrenze die Ergebnisse auf die 5 neuesten
|
||||||
|
const finalRepos = uniqueRepos.slice(0, 5);
|
||||||
|
|
||||||
|
loadingIndicator.style.display = 'none';
|
||||||
|
list.innerHTML = '';
|
||||||
|
|
||||||
|
if (finalRepos.length > 0) {
|
||||||
|
list.style.display = 'block';
|
||||||
|
finalRepos.forEach(repo => {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = repo.html_url;
|
||||||
|
link.textContent = repo.name;
|
||||||
|
link.target = '_blank';
|
||||||
|
link.rel = 'noopener noreferrer';
|
||||||
|
li.appendChild(link);
|
||||||
|
list.appendChild(li);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
list.style.display = 'block';
|
||||||
|
list.innerHTML = '<li>Keine passenden Repositories gefunden.</li>';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler beim Abrufen der Gitea Repositories:', error);
|
||||||
|
loadingIndicator.style.display = 'none';
|
||||||
|
errorIndicator.style.display = 'block';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rufe die neue Funktion auf, wenn die Seite geladen wird.
|
||||||
|
fetchAndDisplayGiteaRepos();
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user