18 lines
5.1 KiB
JavaScript
18 lines
5.1 KiB
JavaScript
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
|
export function signatureTools({template=false,reply=false}={}){
|
|
const endpoint=template?'/api/mail/template'+(reply?'?mode=reply':''):'/api/mail/signature',query=reply?'&':'?';
|
|
const box=el('details');box.append(el('summary',template?(reply?'Branded reply template · Thunderbird & Outlook':'Full branded message template · Thunderbird & Outlook'):'Email signature · Thunderbird & Outlook'));
|
|
const status=el('p');status.role='status';const actions=el('div');actions.className='git-control-actions';
|
|
const download=el('a',template?(reply?'Download reply template (.eml)':'Download email template (.eml)'):'Add signature to Thunderbird');download.href=endpoint;download.download=template?'dunerealms-email-template.eml':'dunerealms-signature.html';
|
|
const copy=el('button',template?'Copy full template for Outlook':'Copy signature for Outlook');copy.type='button';copy.disabled=true;actions.append(download,copy);if(template){const html=el('a','Download HTML template');html.href=endpoint+query+'format=html';html.download='dunerealms-email-template.html';actions.append(html);if(reply){const smart=el('a','Download SmartTemplates reply HTML');smart.href=endpoint+query+'format=smarttemplates';smart.download='dunerealms-reply-template-smarttemplates.html';actions.append(smart);}}
|
|
const preview=el('iframe');preview.title='Your personalised email signature';preview.loading='lazy';preview.height=template?'520':'430';preview.setAttribute('sandbox','');
|
|
box.append(el('p',template?'A complete branded draft with your verified identity, role seals and room for your message. Select it when composing; desktop replies are not automatically wrapped.':'Download your personalised HTML file for Thunderbird, or copy the formatted signature for Outlook. These buttons do not change your mail application settings.'),actions,status,preview);
|
|
let signature=null;
|
|
box.ontoggle=async()=>{if(!box.open||signature)return;preview.src=endpoint+query+'preview=1';try{const r=await fetch(endpoint+query+'format=json',{cache:'no-store'});if(!r.ok)throw Error('Your signature is temporarily unavailable. Please try again.');signature=await r.json();copy.disabled=false;}catch(error){status.textContent=error.message;}};
|
|
copy.onclick=async()=>{if(!signature)return;try{if(typeof ClipboardItem!=='undefined'&&navigator.clipboard?.write){await navigator.clipboard.write([new ClipboardItem({'text/html':new Blob([signature.html],{type:'text/html'}),'text/plain':new Blob([signature.text],{type:'text/plain'})})]);status.textContent=template?'Formatted message template copied. Paste it into a new Outlook message.':'Formatted signature copied. Paste it into the Outlook signature editor.';}else{await navigator.clipboard.writeText(signature.text);status.textContent='Plain-text signature copied; formatted copying is not supported by this browser.';}}catch{try{await navigator.clipboard.writeText(signature.text);status.textContent='Plain-text signature copied. Formatting was not available.';}catch{status.textContent='Clipboard access was blocked. Download the HTML file, open it and copy the visible signature manually.';}}};
|
|
const thunder=el('div');thunder.append(el('h3','Thunderbird'),el('p',template?reply?'Download SmartTemplates reply HTML and select it in SmartTemplates for this account under Reply. Enable Apply the following template and HTML. The design already includes your signature; avoid adding it twice. Thunderbird keeps the original quoted reply. This download does not automatically install a reply template.':'Open the .eml draft in Thunderbird, choose Edit as New if needed, write your message and save it under Templates for reuse. Keep the standalone signature enabled for normal new messages and replies.':'Save the downloaded file somewhere permanent. In Account Settings, select your mailbox, enable Attach the signature from a file, and choose the HTML file. Compose in HTML and enable signatures on replies and forwards in Composition & Addressing.'));
|
|
const th=el('a','Thunderbird signature guide');th.href='https://support.mozilla.org/en-US/kb/signatures';th.target='_blank';th.rel='noopener noreferrer';thunder.append(th);
|
|
const outlook=el('div');outlook.append(el('h3','Outlook'),el('p',template?'Open the .eml where your Outlook version supports it, or paste the copied full design into a new message. Save it using the template tools available in your version. Choose the template when composing; it does not automatically wrap replies.':'In new Outlook, go to Settings → Accounts → Signatures, create a signature and paste the copied design. Choose it for new messages and replies/forwards. In classic Outlook, use Message → Signature → Signatures. Labels vary by version.'));
|
|
const oh=el('a','Microsoft signature guide');oh.href='https://support.microsoft.com/en-us/outlook/mail/how-to-add-and-change-an-email-signature-in-outlook';oh.target='_blank';oh.rel='noopener noreferrer';outlook.append(oh);
|
|
box.append(thunder,outlook,el('p','The logo loads from DuneRealms; some mail apps hide remote images until the recipient allows them.'));return box;
|
|
}
|

Staff