Initial commit: Templates Reply Add-on für Hotel Park Soltau
Modifiziertes Templates Reply Thunderbird Add-on mit: - HTML-Import von Netzlaufwerk - Massen-Delete mit Checkboxen - Deutsches UI mit "Vorlagen" Button - 16 Hotel-Vorlagen als HTML-Dateien
This commit is contained in:
66
popup.js
Normal file
66
popup.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// popup.js
|
||||
|
||||
const TEMPLATE_STORAGE_KEY = 'message_templates';
|
||||
|
||||
async function getTemplates() {
|
||||
try {
|
||||
const result = await browser.storage.local.get(TEMPLATE_STORAGE_KEY);
|
||||
return result[TEMPLATE_STORAGE_KEY] || [];
|
||||
} catch (error) {
|
||||
console.error("Error retrieving templates in popup:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function insertTemplateAndClose(templateText) {
|
||||
browser.runtime.sendMessage({
|
||||
action: 'insertTemplate',
|
||||
text: templateText
|
||||
}).catch(e => console.error("Error sending message to background:", e));
|
||||
window.close();
|
||||
}
|
||||
|
||||
async function renderPopupButtons() {
|
||||
const templates = await getTemplates();
|
||||
const templateList = document.getElementById('template-list');
|
||||
templateList.innerHTML = '';
|
||||
|
||||
if (templates.length === 0) {
|
||||
templateList.innerHTML = `
|
||||
<div class="empty-state">
|
||||
Keine Vorlagen vorhanden.<br>
|
||||
<a href="#" id="open-options">Jetzt einrichten</a>
|
||||
</div>`;
|
||||
document.getElementById('open-options').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
browser.runtime.openOptionsPage();
|
||||
window.close();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
templates.forEach(template => {
|
||||
const button = document.createElement('button');
|
||||
button.textContent = template.name;
|
||||
button.addEventListener('click', () => {
|
||||
insertTemplateAndClose(template.content);
|
||||
});
|
||||
templateList.appendChild(button);
|
||||
});
|
||||
|
||||
// Footer with manage link
|
||||
const footer = document.createElement('div');
|
||||
footer.className = 'footer';
|
||||
const manageLink = document.createElement('a');
|
||||
manageLink.href = "#";
|
||||
manageLink.textContent = 'Vorlagen verwalten';
|
||||
manageLink.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
browser.runtime.openOptionsPage();
|
||||
window.close();
|
||||
});
|
||||
footer.appendChild(manageLink);
|
||||
templateList.parentNode.appendChild(footer);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', renderPopupButtons);
|
||||
Reference in New Issue
Block a user