Compare commits
2 Commits
v2.6.0
...
8057870f8b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8057870f8b | ||
|
|
2b6e2267c2 |
@@ -276,30 +276,49 @@ async function handleInsertTemplate(msg) {
|
||||
const newBody = msg.text + (old ? '\n' + old : '');
|
||||
await browser.compose.setComposeDetails(tab.id, { plainTextBody: newBody });
|
||||
} else {
|
||||
// HTML mode: use insertText API to go through the editor's rendering pipeline
|
||||
// HTML mode: wrap the template in a marker element (id=hps-vorlage) and
|
||||
// replace any previously inserted one — so durchswitchen ersetzt statt stapelt.
|
||||
const htmlContent = isHtmlTemplate ? msg.text : msg.text.replace(/\n/g, '<br>');
|
||||
|
||||
// Move cursor to beginning of body first via script injection
|
||||
await browser.tabs.executeScript(tab.id, {
|
||||
// Directly manipulate the editor DOM: remove the old template block (if any),
|
||||
// then insert the new one at the top of the body. Returns true on success.
|
||||
const injected = await browser.tabs.executeScript(tab.id, {
|
||||
code: `
|
||||
const editor = document.getElementById('messageEditor');
|
||||
const editorDoc = editor ? editor.contentDocument : document;
|
||||
const body = editorDoc.body;
|
||||
if (body) {
|
||||
(function () {
|
||||
const editor = document.getElementById('messageEditor');
|
||||
const editorDoc = editor ? editor.contentDocument : document;
|
||||
const body = editorDoc && editorDoc.body;
|
||||
if (!body) return false;
|
||||
|
||||
// Remove a previously inserted template block, so switching replaces it
|
||||
const prev = editorDoc.getElementById('hps-vorlage');
|
||||
if (prev) prev.remove();
|
||||
|
||||
// Wrap the new template in a marker element with a stable id
|
||||
const wrapper = editorDoc.createElement('div');
|
||||
wrapper.id = 'hps-vorlage';
|
||||
wrapper.innerHTML = ${JSON.stringify(htmlContent)};
|
||||
|
||||
// Insert at the very top of the body (above quote/signature/typed text)
|
||||
body.insertBefore(wrapper, body.firstChild);
|
||||
|
||||
// Place the cursor right after the inserted block
|
||||
const range = editorDoc.createRange();
|
||||
range.setStart(body, 0);
|
||||
range.setStartAfter(wrapper);
|
||||
range.collapse(true);
|
||||
const sel = editorDoc.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
return true;
|
||||
})();
|
||||
`
|
||||
}).catch(() => {
|
||||
// Fallback: some TB versions structure the editor differently
|
||||
});
|
||||
}).then(r => (Array.isArray(r) ? r[0] : r)).catch(() => false);
|
||||
|
||||
// Insert HTML at cursor position - this goes through the editor's render pipeline
|
||||
await browser.compose.insertText(tab.id, htmlContent + '<br>', { insertAsText: false });
|
||||
if (!injected) {
|
||||
// Fallback: editor DOM not reachable (TB version differences) — use the
|
||||
// insertText pipeline. Note: this variant cannot replace, only prepend.
|
||||
await browser.compose.insertText(tab.id, htmlContent + '<br>', { insertAsText: false });
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "HPS Vorlagen & Signaturen",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"description": "Vorlagen- und Signaturverwaltung für Hotel Park Soltau mit Git-Sync",
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
|
||||
Binary file not shown.
10
updates.json
10
updates.json
@@ -2,6 +2,16 @@
|
||||
"addons": {
|
||||
"it@hotel-park-soltau.de": {
|
||||
"updates": [
|
||||
{
|
||||
"version": "2.6.0",
|
||||
"update_link": "https://git.hotel-park-soltau.de/hps/hps-thunderbird-templates/releases/download/v2.6.0/templates-reply-hotel.xpi",
|
||||
"update_hash": "sha256:563e65f7686db7be30712fbc2be934f51c9ce8f4d35bb37f07046d8da40b562d",
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"strict_min_version": "109.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"version": "2.5.0",
|
||||
"update_link": "https://git.hotel-park-soltau.de/hps/hps-thunderbird-templates/releases/download/v2.5.0/templates-reply-hotel.xpi",
|
||||
|
||||
Reference in New Issue
Block a user