Initial commit
This commit is contained in:
48
ui/gemeinsam.js
Normal file
48
ui/gemeinsam.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* gemeinsam.js - Hilfsmittel für alle Dialogseiten.
|
||||
*/
|
||||
|
||||
/** Ruft die Ereignisseite und wirft bei Fehlern eine Ausnahme. */
|
||||
export async function ruf(befehl, daten = {}) {
|
||||
const antwort = await browser.runtime.sendMessage({ befehl, ...daten });
|
||||
if (!antwort?.ok) {
|
||||
throw new Error(antwort?.fehler || `Aufruf ${befehl} fehlgeschlagen`);
|
||||
}
|
||||
return antwort.daten;
|
||||
}
|
||||
|
||||
/**
|
||||
* Beschriftungen aus _locales einsetzen.
|
||||
*
|
||||
* Elemente mit data-i18n bekommen ihren Text, solche mit
|
||||
* data-i18n-placeholder ihren Platzhalter. Fehlt ein Eintrag, bleibt der
|
||||
* im HTML hinterlegte deutsche Text stehen.
|
||||
*/
|
||||
export function uebersetzeSeite() {
|
||||
for (const el of document.querySelectorAll("[data-i18n]")) {
|
||||
const s = browser.i18n.getMessage(el.dataset.i18n);
|
||||
if (s) el.textContent = s;
|
||||
}
|
||||
for (const el of document.querySelectorAll("[data-i18n-placeholder]")) {
|
||||
const s = browser.i18n.getMessage(el.dataset.i18nPlaceholder);
|
||||
if (s) el.placeholder = s;
|
||||
}
|
||||
for (const el of document.querySelectorAll("[data-i18n-title]")) {
|
||||
const s = browser.i18n.getMessage(el.dataset.i18nTitle);
|
||||
if (s) el.title = s;
|
||||
}
|
||||
}
|
||||
|
||||
export function fehlerAnzeigen(text) {
|
||||
const ziel = document.getElementById("meldung");
|
||||
if (!ziel) return;
|
||||
ziel.className = "fehler";
|
||||
ziel.textContent = String(text || "").slice(0, 300);
|
||||
}
|
||||
|
||||
export function meldungAnzeigen(text) {
|
||||
const ziel = document.getElementById("meldung");
|
||||
if (!ziel) return;
|
||||
ziel.className = "hinweis";
|
||||
ziel.textContent = String(text || "");
|
||||
}
|
||||
Reference in New Issue
Block a user