Spaces:
Running
Running
Download index.html from eliazerpro/email-wizard-pro: direct link, hf CLI and curl.
- Browser
- Download file 51.1 kB
-
https://huggingface.co/spaces/eliazerpro/email-wizard-pro/resolve/main/index.html
- Command line
-
hf download hf://spaces/eliazerpro/email-wizard-pro/index.html
-
curl -L -o index.html https://huggingface.co/spaces/eliazerpro/email-wizard-pro/resolve/main/index.html
51.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Email Template Editor</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <style> | |
| /* ---- Tailwind subset ---- */ | |
| .bg-white{background:#fff}.bg-gray-50{background:#f9fafb}.bg-gray-100{background:#f3f4f6}.bg-blue-50{background:#eff6ff}.bg-blue-500{background:#3b82f6}.text-white{color:#fff}.text-blue-500{color:#3b82f6}.text-red-500{color:#ef4444}.text-green-600{color:#16a34a}.text-gray-600{color:#4b5563}.text-sm{font-size:.875rem}.text-lg{font-size:1.125rem}.font-bold{font-weight:700}.italic{font-style:italic}.underline{text-decoration:underline}.p-1{padding:.25rem}.p-2{padding:.5rem}.p-4{padding:1rem}.px-2{padding-left:.5rem;padding-right:.5rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.mb-2{margin-bottom:.5rem}.mb-4{margin-bottom:1rem}.mt-2{margin-top:.5rem}.border{border:1px solid #ccc}.border-2{border-width:2px}.border-dashed{border-style:dashed}.border-blue-500{border-color:#3b82f6}.rounded{border-radius:.25rem}.shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}.w-full{width:100%}.h-40{height:10rem}.h-96{height:24rem}.min-h-40{min-height:10rem}.max-h-40{max-height:10rem}.grid{display:grid}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-2{gap:.5rem}.flex{display:flex}.flex-wrap{flex-wrap:wrap}.cursor-pointer{cursor:pointer}.hover\:bg-gray-100:hover{background:#f3f4f6}.hover\:bg-blue-100:hover{background:#dbeafe}.hover\:bg-blue-600:hover{background:#2563eb}.focus\:ring-1:focus{outline:2px solid transparent;outline-offset:2px;box-shadow:0 0 0 1px #3b82f6}.hidden{display:none} | |
| /* ---- Custom ---- */ | |
| body{font-family:Arial,Verdana,Helvetica,sans-serif;margin:0;padding:20px;background:#f4f4f4;overflow-x:hidden} | |
| .container{max-width:1400px;margin:auto;display:flex;gap:20px;flex-wrap:wrap;position:relative} | |
| .preview{flex:2;border:1px solid #ccc;padding:20px;background:#474747;border-radius:8px;min-height:800px;overflow-y:auto;max-height:calc(100vh - 40px)} | |
| .sidebar{flex:1;border:1px solid #ccc;padding:20px;background:#f9f9f9;border-radius:8px;max-width:400px;overflow-y:auto;position:sticky;top:20px;height:fit-content;max-height:calc(100vh - 40px)} | |
| .preview table{width:100%;max-width:700px;margin:auto} | |
| .preview img{max-width:100%;height:auto;display:block} | |
| .preview .section{position:relative;border:2px dashed transparent;padding:8px;transition:border .2s} | |
| .preview .section:hover{border:2px dashed #007bff;background:rgba(0,123,255,.05)} | |
| .preview .section.active{border:2px solid #007bff;background:rgba(0,123,255,.1)} | |
| .two-column td.column{vertical-align:top;background:#f1f1f1;padding:10px 20px} | |
| .two-column-img-only td.column{vertical-align:top;background:#f1f1f1;padding:10px 20px} | |
| /* Section toolbar */ | |
| .section-toolbar{position:absolute;top:4px;right:4px;background:#fff;border:1px solid #ddd;border-radius:4px;padding:2px;display:none;z-index:10} | |
| .section:hover .section-toolbar{display:flex;gap:2px} | |
| .section-toolbar button{background:none;border:none;padding:4px 6px;font-size:11px;cursor:pointer;color:#555} | |
| .section-toolbar button:hover{color:#000;background:#f0f0f0} | |
| .section-toolbar button:disabled{color:#aaa;cursor:default} | |
| /* Resize handle */ | |
| .resizable-img{cursor:default;border:2px dashed transparent;position:relative;display:inline-block} | |
| .resizable-img:hover{border-color:#007bff} | |
| .resize-handle{position:absolute;right:-5px;bottom:-5px;width:15px;height:15px;background:#007bff;cursor:nwse-resize;border-radius:50%;z-index:10} | |
| /* Link icon */ | |
| .link-icon{position:absolute;top:5px;right:5px;background:rgba(0,0,0,.7);color:#fff;padding:3px 6px;border-radius:3px;font-size:11px;cursor:pointer} | |
| /* Action bar */ | |
| .action-bar{background:#fff;border:1px solid #ddd;border-radius:8px;padding:12px;display:flex;gap:12px;flex-wrap:wrap;align-items:center;justify-content:center;margin-top:1rem} | |
| .action-btn{background:#3b82f6;color:#fff;border:none;padding:8px 16px;border-radius:6px;cursor:pointer;font-weight:600;display:inline-flex;align-items:center;gap:6px} | |
| .action-btn:hover{background:#2563eb} | |
| .action-btn.send{background:#10b981} | |
| .action-btn.send:hover{background:#059669} | |
| .action-btn.export{background:#8b5cf6} | |
| .action-btn.export:hover{background:#7c3aed} | |
| .action-btn.copy{background:#22c55e} | |
| .action-btn.copy:hover{background:#16a34a} | |
| .action-icon{font-size:1.1rem} | |
| /* Modals */ | |
| .modal{display:none;position:fixed;z-index:1000;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,.5);overflow-y:auto} | |
| .modal-content{background:#fefefe;margin:5% auto;padding:20px;border-radius:8px;width:80%;max-width:800px;max-height:80vh;overflow-y:auto} | |
| .modal-close{color:#aaa;float:right;font-size:28px;font-weight:bold;cursor:pointer} | |
| .modal-close:hover{color:#000} | |
| .link-modal input{width:100%;padding:8px;margin:5px 0;border:1px solid #ccc;border-radius:4px} | |
| .link-modal label{display:block;margin:10px 0 5px;font-weight:bold} | |
| /* Gallery Modal */ | |
| #galleryModal .modal-content{max-width:900px} | |
| .gallery-tabs{display:flex;gap:0;border-bottom:1px solid #ddd;margin-bottom:10px} | |
| .tab-btn{flex:1;padding:10px;background:#f0f0f0;border:none;cursor:pointer;font-weight:600} | |
| .tab-btn.active{background:#fff;border-bottom:2px solid #3b82f6;color:#3b82f6} | |
| .gallery{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px;max-height:400px;overflow-y:auto;padding:10px} | |
| .gallery-item{cursor:pointer;text-align:center;padding:5px;border:2px solid transparent;border-radius:4px} | |
| .gallery-item:hover{border-color:#007bff;background:#f0f8ff} | |
| .gallery-item img{width:100px;height:100px;object-fit:cover;border-radius:4px} | |
| .gallery-item span{display:block;font-size:10px;margin-top:5px;word-break:break-word} | |
| .gallery-actions{display:flex;gap:10px;justify-content:center;margin-top:10px;flex-wrap:wrap} | |
| .refresh-btn,.upload-btn{background:#3b82f6;color:#fff;border:none;padding:8px 16px;border-radius:6px;cursor:pointer} | |
| .refresh-btn:hover,.upload-btn:hover{background:#2563eb} | |
| #galleryLoading{text-align:center;padding:20px;color:#666;font-style:italic} | |
| /* Popup */ | |
| .popup-modal{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.5);display:flex;justify-content:center;align-items:center;z-index:2000;} | |
| .popup-content{background:#fff;padding:20px;border-radius:8px;max-width:300px;width:80%;text-align:center;box-shadow:0 4px 12px rgba(0,0,0,.15);} | |
| .popup-content h4{margin:0 0 10px;font-size:1.1rem;} | |
| .popup-content p{margin:8px 0 15px;color:#444;} | |
| .popup-close-btn{padding:8px 16px;background:#10b981;color:#fff;border:none;border-radius:4px;cursor:pointer;font-weight:600;} | |
| .popup-close-btn:hover{background:#059669;} | |
| /* Divider edit */ | |
| .divider-preview{height:4px;background:#000;margin:10px 0;} | |
| .divider-controls{margin-top:10px;display:flex;gap:10px;align-items:center;flex-wrap:wrap;} | |
| .divider-controls input[type="color"]{width:40px;height:40px;padding:0;border:none;cursor:pointer;} | |
| .divider-controls input[type="range"]{flex:1;} | |
| /* Image placeholder */ | |
| .img-placeholder{border:2px dashed #aaa;background:#f9f9f9;padding:20px;text-align:center;color:#666;cursor:pointer;font-size:14px;} | |
| .img-placeholder:hover{border-color:#007bff;background:#f0f8ff;} | |
| /* Confirm buttons */ | |
| .confirm-btn{background:#ff4444;color:#fff;border:none;padding:8px 16px;border-radius:4px;cursor:pointer;font-weight:600;} | |
| .confirm-btn:hover{background:#cc0000;} | |
| .cancel-btn{background:#f0f0f0;color:#333;border:none;padding:8px 16px;border-radius:4px;cursor:pointer;} | |
| .cancel-btn:hover{background:#e0e0e0;} | |
| /* Copy button in export */ | |
| #copyBtnInModal{background:#22c55e;color:#fff;} | |
| #copyBtnInModal:hover{background:#16a34a;} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <!-- ==================== PREVIEW ==================== --> | |
| <div class="preview" id="preview"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#474747"> | |
| <tr><td align="center"> | |
| <table style="width:700px;" border="0" cellspacing="0" cellpadding="0"> | |
| <tr><td style="padding:15px 10px;"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0" style="background:#fff;border:18px solid #392b0e;"> | |
| <tr><td style="padding:0;"> | |
| <div style="border:3px solid #fff;"> | |
| <img src="https://drive.google.com/thumbnail?id=1XUnRDQiyh2uqYOYFBUk1EAgq57lm1IlI&sz=w800" alt="Header" style="width:100%;display:block;"> | |
| </div> | |
| <div id="contentArea" style="padding:10px 40px;"></div> | |
| <div style="border:3px solid #fff;"> | |
| <img src="https://drive.google.com/thumbnail?id=1X6HOaa17HVGUlEAHKCTHYefoPcXYFsCI&sz=w800" alt="Footer" style="width:100%;display:block;"> | |
| </div> | |
| </td></tr> | |
| </table> | |
| </td></tr> | |
| </table> | |
| </td></tr> | |
| </table> | |
| </div> | |
| <!-- ==================== SIDEBAR ==================== --> | |
| <div class="sidebar"> | |
| <h3 class="text-lg font-bold mb-4">Email Template Editor</h3> | |
| <!-- Add Section --> | |
| <details open><summary class="font-bold cursor-pointer mb-2">Add New Section</summary> | |
| <div class="grid grid-cols-2 gap-2 mb-4"> | |
| <div class="add-section-btn p-4 border-2 border-dashed border-blue-500 bg-blue-50 text-blue-500 rounded text-center font-bold cursor-pointer hover:bg-blue-100" onclick="addSection('image')">Image</div> | |
| <div class="add-section-btn p-4 border-2 border-dashed border-blue-500 bg-blue-50 text-blue-500 rounded text-center font-bold cursor-pointer hover:bg-blue-100" onclick="addSection('text')">Text</div> | |
| <div class="add-section-btn p-4 border-2 border-dashed border-blue-500 bg-blue-50 text-blue-500 rounded text-center font-bold cursor-pointer hover:bg-blue-100" onclick="addSection('divider')">Line Break</div> | |
| <div class="add-section-btn p-4 border-2 border-dashed border-blue-500 bg-blue-50 text-blue-500 rounded text-center font-bold cursor-pointer hover:bg-blue-100" onclick="addSection('twoColumn')">Two Column</div> | |
| <div class="add-section-btn p-4 border-2 border-dashed border-blue-500 bg-blue-50 text-blue-500 rounded text-center font-bold cursor-pointer hover:bg-blue-100" onclick="addSection('twoColumnImg')">Two Images</div> | |
| </div> | |
| </details> | |
| <!-- Email Subject --> | |
| <div id="emailSubjectSection" class="mt-4 hidden"> | |
| <label class="block mb-2 font-semibold">Email Subject:</label> | |
| <input id="emailSubject" type="text" placeholder="Enter email subject" class="w-full p-2 border rounded mb-2"> | |
| <button onclick="sendTestEmail()" class="w-full bg-blue-500 text-white p-2 rounded hover:bg-blue-600">Send Test Email</button> | |
| <button onclick="previewAndSend()" class="w-full bg-green-600 text-white p-2 rounded hover:bg-green-700 mt-2">Preview & Submit</button> | |
| <div id="sendStatus" class="mt-2"></div> | |
| </div> | |
| <!-- Action Bar --> | |
| <div class="action-bar"> | |
| <button class="action-btn send" onclick="prepareSendEmail()">Send Email</button> | |
| <button class="action-btn export" onclick="exportHtml()">Export HTML</button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- ==================== MODALS ==================== --> | |
| <!-- Export --> | |
| <div id="exportModal" class="modal"><div class="modal-content"><span class="modal-close" onclick="closeExportModal()">X</span><h2>Export HTML</h2><button id="copyBtnInModal" onclick="copyHtml()" class="p-2 rounded mb-2 hidden">Copy to Clipboard</button><textarea id="exportHtmlOutput" class="w-full h-96 font-mono text-xs" readonly></textarea></div></div> | |
| <!-- Gallery Modal --> | |
| <div id="galleryModal" class="modal"> | |
| <div class="modal-content"> | |
| <span class="modal-close" onclick="closeGalleryModal()">X</span> | |
| <h2>Image Gallery</h2> | |
| <div class="gallery-tabs"> | |
| <button class="tab-btn active" onclick="switchGalleryTab('ichud')">Ichud Images</button> | |
| <button class="tab-btn" onclick="switchGalleryTab('email')">Email Images</button> | |
| </div> | |
| <div class="gallery-actions" id="galleryActions"> | |
| <button class="refresh-btn" onclick="refreshGallery()">Refresh</button> | |
| <button class="upload-btn hidden" onclick="openUploadForm()">Upload More Images</button> | |
| </div> | |
| <div id="galleryLoading">Loading images...</div> | |
| <div id="galleryContent" class="gallery"></div> | |
| </div> | |
| </div> | |
| <!-- Text Edit --> | |
| <div id="textEditModal" class="modal" style="display:none;"> | |
| <div class="modal-content" style="max-width:800px;"> | |
| <span class="modal-close" onclick="closeTextEditModal()">X</span> | |
| <h3>Edit Text</h3> | |
| <div class="bg-white rounded shadow p-4 mb-4"> | |
| <div class="flex flex-wrap gap-2 mb-3"> | |
| <select id="modalFontFamily" class="border rounded p-1 text-sm bg-gray-50 focus:ring-1 focus:ring-blue-500"> | |
| <option value="Arial">Arial</option><option value="Times New Roman">Times New Roman</option><option value="Courier New">Courier New</option> | |
| <option value="Georgia">Georgia</option><option value="Verdana">Verdana</option><option value="Arial Hebrew">Arial Hebrew</option><option value="David">David</option><option value="Miriam">Miriam</option> | |
| </select> | |
| <select id="modalFontSize" class="border rounded p-1 text-sm bg-gray-50 focus:ring-1 focus:ring-blue-500"> | |
| <option value="8px">8px</option><option value="10px">10px</option><option value="12px">12px</option><option value="14px">14px</option><option value="16px" selected>16px</option> | |
| <option value="18px">18px</option><option value="20px">20px</option><option value="24px">24px</option><option value="28px">28px</option><option value="32px">32px</option> | |
| <option value="36px">36px</option><option value="48px">48px</option><option value="64px">64px</option> | |
| </select> | |
| <select id="modalTextColor" class="border rounded p-1 text-sm bg-gray-50 focus:ring-1 focus:ring-blue-500"> | |
| <option value="black">Black</option><option value="red">Red</option><option value="blue">Blue</option><option value="green">Green</option><option value="purple">Purple</option><option value="orange">Orange</option><option value="gray">Gray</option><option value="brown">Brown</option><option value="pink">Pink</option><option value="teal">Teal</option> | |
| </select> | |
| <button id="modalBoldBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100 font-bold">B</button> | |
| <button id="modalItalicBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100 italic">I</button> | |
| <button id="modalUnderlineBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100 underline">U</button> | |
| <button id="modalLinkBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100">Link</button> | |
| <button id="modalAlignLeftBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100">L</button> | |
| <button id="modalAlignCenterBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100">C</button> | |
| <button id="modalAlignRightBtn" class="border rounded p-1 text-sm bg-gray-50 hover:bg-gray-100">R</button> | |
| <label class="border rounded p-1 text-sm bg-gray-50 cursor-pointer"><input type="checkbox" id="modalRtlToggle" style="margin-right:5px;"> RTL</label> | |
| </div> | |
| <div id="modalTextEditor" contenteditable="true" style="min-height:200px;border:1px solid #ccc;padding:10px;border-radius:4px;background:#fff;font-family:Arial;font-size:16px;line-height:1.5;outline:none;"></div> | |
| <div class="mt-3 flex gap-2 justify-end"> | |
| <button onclick="closeTextEditModal()" class="cancel-btn">Cancel</button> | |
| <button onclick="saveTextEdit()" class="confirm-btn">Save</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Text Link Modal --> | |
| <div id="textLinkModal" class="modal" style="display:none;"> | |
| <div class="modal-content" style="max-width:500px;"> | |
| <span class="modal-close" onclick="closeTextLinkModal()">X</span> | |
| <h3>Insert Link</h3> | |
| <div class="link-modal"> | |
| <label>URL:</label> | |
| <input type="url" id="textLinkUrl" placeholder="https://example.com"> | |
| <div class="mt-3 flex gap-2 justify-end"> | |
| <button onclick="closeTextLinkModal()" class="cancel-btn">Cancel</button> | |
| <button onclick="applyTextLink()" class="confirm-btn">Insert Link</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Image Link Modal --> | |
| <div id="imageLinkModal" class="modal" style="display:none;"> | |
| <div class="modal-content" style="max-width:500px;"> | |
| <span class="modal-close" onclick="closeImageLinkModal()">X</span> | |
| <h3>Set Image Link</h3> | |
| <div class="link-modal"> | |
| <label>URL:</label> | |
| <input type="url" id="linkUrlInput" placeholder="https://example.com"> | |
| <div class="mt-3 flex gap-2 justify-end"> | |
| <button onclick="closeImageLinkModal()" class="cancel-btn">Cancel</button> | |
| <button onclick="saveImageLink()" class="confirm-btn">Save Link</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Divider Edit Modal --> | |
| <div id="dividerEditModal" class="modal" style="display:none;"> | |
| <div class="modal-content" style="max-width:500px;"> | |
| <span class="modal-close" onclick="closeDividerEditModal()">X</span> | |
| <h3>Edit Line Break</h3> | |
| <div style="padding:10px;"> | |
| <div class="divider-preview" id="dividerPreview"></div> | |
| <div class="divider-controls"> | |
| <label>Color:</label> | |
| <input type="color" id="dividerColor" value="#000000"> | |
| <label>Thickness:</label> | |
| <input type="range" id="dividerThickness" min="1" max="20" value="1"> | |
| <span id="thicknessValue">1px</span> | |
| </div> | |
| <div class="mt-3 flex gap-2 justify-end"> | |
| <button onclick="closeDividerEditModal()" class="cancel-btn">Cancel</button> | |
| <button onclick="saveDividerEdit()" class="confirm-btn">Save</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Copied Popup --> | |
| <div id="copiedPopup" class="popup-modal" style="display:none;"> | |
| <div class="popup-content"> | |
| <h4>Copied!</h4> | |
| <p>HTML has been copied to your clipboard.</p> | |
| <button class="popup-close-btn" onclick="closeCopiedPopup()">OK</button> | |
| </div> | |
| </div> | |
| <script> | |
| /* ==================== GLOBALS ==================== */ | |
| let sections = [], imageGalleries = {ichud: [], email: []}, dragIndex = -1, resizingImage = null, currentGalleryTab = 'ichud'; | |
| let startX = 0, startWidth = 0, pendingImageSelection = null; | |
| let currentTextEdit = {}, currentImageLink = {}, currentTextLinkRange = null, currentDividerEdit = {}; | |
| const ICHUD_SHEETS_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXGSrMaX5zA_rr9I8zwMv0q2J8RX-CGlBXy7UzHYU5X4h8xzCym1YFAIZWgnKLLILfWMKrjRiTgh3/pub?gid=1877520065&single=true&output=csv'; | |
| const EMAIL_SHEETS_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXGSrMaX5zA_rr9I8zwMv0q2J8RX-CGlBXy7UzHYU5X4h8xzCym1YFAIZWgnKLLILfWMKrjRiTgh3/pub?gid=1126641103&single=true&output=csv'; | |
| const UPLOAD_FORM_URL = 'https://docs.google.com/forms/d/e/1FAIpQLSdu7UujAGJ14BEgxJ8_UYR9UVlpJV5Q6l7TTEuh2gF7WP3PCg/viewform'; | |
| /* ==================== INIT ==================== */ | |
| async function init() { | |
| await loadAllGalleries(); | |
| sections = [ | |
| { type:'text', content:'<p style="text-align:center;font-size:16px;">יום א\' פרשת עקב, תשפ"ה לפ"ק</p>', alignment:'center', dir:'ltr' }, | |
| { type:'divider', thickness:'1', color:'#000000', style:'solid' }, | |
| { type:'text', content:'<p style="text-align:center;">פארן באקוועימליכקייט פונעם ציבור, איז כדי צו סעיוון די אימעיל אדרעס אין קאנטעקטס<br><a href="mailto:maduastzehlim@gmail.com">maduastzehlim@gmail.com</a><br>פאר סיי וועלכע הערה ביטע שיקט א אימעיל<br>האיחוד</p>', alignment:'center', dir:'rtl' } | |
| ]; | |
| renderSections(); | |
| } | |
| /* ==================== GALLERY ==================== */ | |
| async function loadAllGalleries() { | |
| await Promise.all([loadIchudImages(), loadEmailImages()]); | |
| } | |
| async function loadIchudImages() { | |
| return fetchFromSheet(ICHUD_SHEETS_URL, 'ichud'); | |
| } | |
| async function loadEmailImages() { | |
| return fetchFromSheet(EMAIL_SHEETS_URL, 'email'); | |
| } | |
| async function fetchFromSheet(url, type) { | |
| const proxies = ['https://api.allorigins.win/raw?url=', 'https://api.codetabs.com/v1/proxy?quest=', 'https://corsproxy.io/?']; | |
| let csv = null; | |
| for (const p of proxies) { | |
| try { | |
| const r = await fetch(p + encodeURIComponent(url)); | |
| if (r.ok) { csv = await r.text(); break; } | |
| } catch (e) { console.warn('Proxy failed:', p, e); } | |
| } | |
| if (!csv) return; | |
| const rows = csv.split('\n').filter(row => row.trim()); | |
| const gallery = []; | |
| for (let i = 1; i < rows.length; i++) { | |
| const cols = parseCSVRow(rows[i].trim()); | |
| if (cols.length < 3) continue; | |
| let name, rawUrls; | |
| if (type === 'ichud') { | |
| name = cols[1].replace(/^["']|["']$/g, '').trim() || `Ichud Img ${i}`; | |
| rawUrls = [cols[2].replace(/^["']|["']$/g, '').trim()]; | |
| } else { | |
| name = `Email Img ${gallery.length + 1}`; | |
| rawUrls = cols[1].replace(/^["']|["']$/g, '').trim().split(',').map(u => u.trim()).filter(u => u); | |
| } | |
| for (const raw of rawUrls) { | |
| if (!raw) continue; | |
| const imgUrl = getGoogleDriveImageUrl(raw); | |
| if (imgUrl !== 'invalid') { | |
| gallery.push({ name, url: imgUrl }); | |
| } | |
| } | |
| } | |
| imageGalleries[type] = gallery.reverse(); | |
| return gallery; | |
| } | |
| function parseCSVRow(r) { | |
| const a = []; let c = '', q = false; | |
| for (let i = 0; i < r.length; i++) { | |
| const ch = r[i]; | |
| if (ch === '"') q = !q; | |
| else if (ch === ',' && !q) { a.push(c); c = ''; } | |
| else c += ch; | |
| } | |
| a.push(c); return a; | |
| } | |
| function getGoogleDriveImageUrl(u) { | |
| if (!u.includes('drive.google.com')) return u; | |
| const m = u.match(/\/file\/d\/([a-zA-Z0-9-_]+)/) || u.match(/id=([a-zA-Z0-9-_]+)/) || u.match(/\/open\?id=([a-zA-Z0-9-_]+)/); | |
| return m ? `https://drive.google.com/thumbnail?id=${m[1]}&sz=w800` : 'invalid'; | |
| } | |
| function refreshGallery() { | |
| const btn = document.querySelector('#galleryActions .refresh-btn'); | |
| btn.disabled = true; | |
| btn.textContent = 'Refreshing...'; | |
| document.getElementById('galleryLoading').style.display = 'block'; | |
| document.getElementById('galleryContent').innerHTML = ''; | |
| const tab = currentGalleryTab; | |
| const loadFn = tab === 'ichud' ? loadIchudImages : loadEmailImages; | |
| loadFn().then(() => { | |
| renderGallery(tab); | |
| btn.disabled = false; | |
| btn.textContent = 'Refresh'; | |
| }).catch(() => { | |
| document.getElementById('galleryLoading').innerHTML = 'Failed to load. Try again.'; | |
| btn.disabled = false; | |
| btn.textContent = 'Refresh'; | |
| }); | |
| } | |
| function openUploadForm() { | |
| window.open(UPLOAD_FORM_URL, '_blank'); | |
| } | |
| function switchGalleryTab(tab) { | |
| currentGalleryTab = tab; | |
| document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active')); | |
| event.target.classList.add('active'); | |
| renderGallery(tab); | |
| document.querySelector('.upload-btn').classList.toggle('hidden', tab !== 'email'); | |
| } | |
| function renderGallery(tab) { | |
| const gallery = imageGalleries[tab] || []; | |
| const content = document.getElementById('galleryContent'); | |
| const loading = document.getElementById('galleryLoading'); | |
| loading.style.display = 'none'; | |
| content.innerHTML = gallery.length === 0 | |
| ? '<p style="text-align:center;color:#999;font-style:italic;">No images found.</p>' | |
| : gallery.map(img => ` | |
| <div class="gallery-item" onclick="selectImage('${img.url}', '${img.name}')"> | |
| <img src="${img.url}" alt="${img.name}" onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCIgdmlld0JveD0iMCAwIDEwMCAxMDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHJlY3Qgd2lkdGg9IjEwMCIgaGVpZ2h0PSIxMDAiIGZpbGw9IiNmMGYwZjAiLz48dGV4dCB4PSI1MCIgeT0iNTAiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZpbGw9IiM5OTkiIGZvbnQtc2l6ZT0iMTIiPk5vIEltYWdlPC90ZXh0Pjwvc3ZnPg=='"> | |
| <span>${img.name}</span> | |
| </div> | |
| `).join(''); | |
| } | |
| function openGalleryModal() { | |
| document.getElementById('galleryModal').style.display = 'block'; | |
| renderGallery(currentGalleryTab); | |
| document.querySelector('.upload-btn').classList.toggle('hidden', currentGalleryTab !== 'email'); | |
| } | |
| function closeGalleryModal() { | |
| document.getElementById('galleryModal').style.display = 'none'; | |
| } | |
| /* ==================== IMAGE SELECTION ==================== */ | |
| function openImageSelector(idx, side = null) { | |
| pendingImageSelection = { sectionIndex: idx, side }; | |
| openGalleryModal(); | |
| } | |
| function selectImage(url, name) { | |
| if (!pendingImageSelection) return; | |
| const { sectionIndex, side } = pendingImageSelection; | |
| const sec = sections[sectionIndex]; | |
| if (sec.type === 'image') { sec.url = url; sec.name = name; sec.width = 400; } | |
| else if (sec.type === 'twoColumn' || sec.type === 'twoColumnImg') { | |
| if (side === 'left') { sec.left.image = url; sec.left.name = name; sec.left.width = 250; } | |
| else if (side === 'right') { sec.right.image = url; sec.right.name = name; sec.right.width = 250; } | |
| } | |
| renderSections(); | |
| pendingImageSelection = null; | |
| closeGalleryModal(); | |
| } | |
| /* ==================== SECTION RENDERING (FIXED: EXACT SAME IMAGE RENDERING) ==================== */ | |
| function renderSections() { | |
| const area = document.getElementById('contentArea'); area.innerHTML = ''; | |
| sections.forEach((s, i) => { | |
| const secDiv = document.createElement('div'); | |
| secDiv.className = 'section'; | |
| secDiv.dataset.index = i; | |
| secDiv.draggable = true; | |
| const toolbar = document.createElement('div'); | |
| toolbar.className = 'section-toolbar'; | |
| toolbar.innerHTML = ` | |
| <button onclick="moveSection(${i},-1)" ${i===0?'disabled':''}>Up</button> | |
| <button onclick="moveSection(${i},1)" ${i===sections.length-1?'disabled':''}>Down</button> | |
| <button onclick="removeSection(${i})">Delete</button> | |
| `; | |
| secDiv.appendChild(toolbar); | |
| let html = ''; | |
| if (s.type === 'image') { | |
| const w = s.width ? `width:${s.width}px;` : 'width:400px;'; | |
| const placeholder = !s.url ? `<div class="img-placeholder" ondblclick="openImageSelector(${i})">Double-click to insert image</div>` : ''; | |
| html = `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:10px 40px;" align="center"> | |
| <div style="position:relative;display:inline-block;"> | |
| ${placeholder} | |
| ${s.url ? `<img class="resizable-img" data-index="${i}" style="display:block;max-width:100%;height:auto;${w}" | |
| src="${s.url}" alt="${s.name}" ondblclick="openImageSelector(${i})">` : ''} | |
| ${s.url ? `<div class="resize-handle"></div>` : ''} | |
| ${s.url ? `<div class="link-icon" onclick="openImageLinkModal(${i})">Link</div>` : ''} | |
| </div> | |
| </td></tr></table>`; | |
| } | |
| else if (s.type === 'text') { | |
| html = `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td ondblclick="openTextEditor(${i})" | |
| style="padding:10px 40px;font-family:Arial,Verdana,Helvetica,sans-serif;color:#3e3e3e;font-size:14px; | |
| text-align:${s.alignment||'center'};line-height:1.5;cursor:pointer;border:1px dashed transparent;" | |
| onmouseover="this.style.borderColor='#007bff'" onmouseout="this.style.borderColor='transparent'" | |
| title="Double-click to edit">${s.content}</td></tr></table>`; | |
| } | |
| else if (s.type === 'divider') { | |
| html = `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:10px 40px;" align="center" ondblclick="openDividerEditor(${i})"> | |
| <div style="height:${s.thickness||'1'}px;background:${s.color||'#000'};cursor:pointer;" title="Double-click to edit"></div></td></tr></table>`; | |
| } | |
| /* ---------- TWO-COLUMN (image + text BELOW) ---------- */ | |
| else if (s.type === 'twoColumn') { | |
| const lw = s.left.width ? `width:${s.left.width}px;` : 'width:250px;'; | |
| const rw = s.right.width ? `width:${s.right.width}px;` : 'width:250px;'; | |
| html = `<table border="0" width="100%" cellspacing="0" cellpadding="0" class="two-column"><tr><td style="padding:0 40px;" align="center"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0"><tr> | |
| <td class="column" style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| <div style="position:relative;display:inline-block;"> | |
| ${!s.left.image ? `<div class="img-placeholder" ondblclick="openImageSelector(${i},'left')">Double-click to insert</div>` : ''} | |
| ${s.left.image ? `<img class="resizable-img" data-index="${i}" data-side="left" | |
| style="display:block;max-width:100%;height:auto;${lw}" | |
| src="${s.left.image}" alt="${s.left.name}" ondblclick="openImageSelector(${i},'left')">` : ''} | |
| ${s.left.image ? `<div class="resize-handle"></div>` : ''} | |
| ${s.left.image ? `<div class="link-icon" onclick="openImageLinkModal(${i},'left')">Link</div>` : ''} | |
| </div> | |
| <div ondblclick="openTextEditor(${i},'left')" | |
| style="padding:10px 20px;font-size:14px;text-align:${s.left.alignment||'center'};line-height:1.5; | |
| cursor:pointer;border:1px dashed transparent;margin-top:10px;" | |
| onmouseover="this.style.borderColor='#007bff'" onmouseout="this.style.borderColor='transparent'" | |
| title="Double-click to edit">${s.left.text}</div> | |
| </td> | |
| <td style="width:10px;background:#fff;"></td> | |
| <td class="column" style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| <div style="position:relative;display:inline-block;"> | |
| ${!s.right.image ? `<div class="img-placeholder" ondblclick="openImageSelector(${i},'right')">Double-click to insert</div>` : ''} | |
| ${s.right.image ? `<img class="resizable-img" data-index="${i}" data-side="right" | |
| style="display:block;max-width:100%;height:auto;${rw}" | |
| src="${s.right.image}" alt="${s.right.name}" ondblclick="openImageSelector(${i},'right')">` : ''} | |
| ${s.right.image ? `<div class="resize-handle"></div>` : ''} | |
| ${s.right.image ? `<div class="link-icon" onclick="openImageLinkModal(${i},'right')">Link</div>` : ''} | |
| </div> | |
| <div ondblclick="openTextEditor(${i},'right')" | |
| style="padding:10px 20px;font-size:14px;text-align:${s.right.alignment||'center'};line-height:1.5; | |
| cursor:pointer;border:1px dashed transparent;margin-top:10px;" | |
| onmouseover="this.style.borderColor='#007bff'" onmouseout="this.style.borderColor='transparent'" | |
| title="Double-click to edit">${s.right.text}</div> | |
| </td> | |
| </tr></table></td></tr></table>`; | |
| } | |
| /* ---------- TWO-IMAGES (img only) ---------- */ | |
| else if (s.type === 'twoColumnImg') { | |
| const lw = s.left.width ? `width:${s.left.width}px;` : 'width:250px;'; | |
| const rw = s.right.width ? `width:${s.right.width}px;` : 'width:250px;'; | |
| html = `<table border="0" width="100%" cellspacing="0" cellpadding="0" class="two-column-img-only"><tr><td style="padding:0 40px;" align="center"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0"><tr> | |
| <td class="column" style="width:272px;vertical-align:top;"> | |
| <div style="position:relative;display:inline-block;"> | |
| ${!s.left.image ? `<div class="img-placeholder" ondblclick="openImageSelector(${i},'left')">Double-click to insert</div>` : ''} | |
| ${s.left.image ? `<img class="resizable-img" data-index="${i}" data-side="left" | |
| style="display:block;max-width:100%;height:auto;${lw}" | |
| src="${s.left.image}" alt="${s.left.name}" ondblclick="openImageSelector(${i},'left')">` : ''} | |
| ${s.left.image ? `<div class="resize-handle"></div>` : ''} | |
| ${s.left.image ? `<div class="link-icon" onclick="openImageLinkModal(${i},'left')">Link</div>` : ''} | |
| </div> | |
| </td> | |
| <td style="width:10px;"></td> | |
| <td class="column" style="width:272px;vertical-align:top;"> | |
| <div style="position:relative;display:inline-block;"> | |
| ${!s.right.image ? `<div class="img-placeholder" ondblclick="openImageSelector(${i},'right')">Double-click to insert</div>` : ''} | |
| ${s.right.image ? `<img class="resizable-img" data-index="${i}" data-side="right" | |
| style="display:block;max-width:100%;height:auto;${rw}" | |
| src="${s.right.image}" alt="${s.right.name}" ondblclick="openImageSelector(${i},'right')">` : ''} | |
| ${s.right.image ? `<div class="resize-handle"></div>` : ''} | |
| ${s.right.image ? `<div class="link-icon" onclick="openImageLinkModal(${i},'right')">Link</div>` : ''} | |
| </div> | |
| </td> | |
| </tr></table></td></tr></table>`; | |
| } | |
| secDiv.innerHTML += html; | |
| area.appendChild(secDiv); | |
| }); | |
| setupDragAndDrop(); | |
| setupImageResizing(); | |
| } | |
| /* ==================== DELETE SECTION ==================== */ | |
| function removeSection(i) { | |
| const modal = document.createElement('div'); | |
| modal.className = 'popup-modal'; | |
| modal.innerHTML = ` | |
| <div class="popup-content"> | |
| <h3 style="margin-top:0;">Delete Section</h3> | |
| <p>Are you sure?</p> | |
| <div style="display:flex;justify-content:flex-end;gap:10px;margin-top:20px;"> | |
| <button class="cancel-btn" onclick="this.closest('.popup-modal').remove()">Cancel</button> | |
| <button class="confirm-btn" onclick="sections.splice(${i},1);renderSections();this.closest('.popup-modal').remove()">Delete</button> | |
| </div> | |
| </div>`; | |
| document.body.appendChild(modal); | |
| } | |
| /* ==================== OTHER MODALS ==================== */ | |
| function openDividerEditor(idx) { | |
| const sec = sections[idx]; | |
| currentDividerEdit = { index: idx }; | |
| document.getElementById('dividerColor').value = sec.color || '#000000'; | |
| document.getElementById('dividerThickness').value = sec.thickness || 1; | |
| document.getElementById('thicknessValue').textContent = (sec.thickness || 1) + 'px'; | |
| document.getElementById('dividerPreview').style.height = (sec.thickness || 1) + 'px'; | |
| document.getElementById('dividerPreview').style.background = sec.color || '#000'; | |
| document.getElementById('dividerThickness').oninput = function() { | |
| const val = this.value; | |
| document.getElementById('thicknessValue').textContent = val + 'px'; | |
| document.getElementById('dividerPreview').style.height = val + 'px'; | |
| }; | |
| document.getElementById('dividerColor').oninput = function() { | |
| document.getElementById('dividerPreview').style.background = this.value; | |
| }; | |
| document.getElementById('dividerEditModal').style.display = 'block'; | |
| } | |
| function closeDividerEditModal() { | |
| document.getElementById('dividerEditModal').style.display = 'none'; | |
| currentDividerEdit = {}; | |
| } | |
| function saveDividerEdit() { | |
| const idx = currentDividerEdit.index; | |
| sections[idx].color = document.getElementById('dividerColor').value; | |
| sections[idx].thickness = document.getElementById('dividerThickness').value; | |
| renderSections(); | |
| closeDividerEditModal(); | |
| } | |
| function openTextEditor(idx, side = null) { | |
| const sec = sections[idx]; | |
| const content = side ? sec[side].text || '' : sec.content || ''; | |
| const align = side ? sec[side].alignment || 'center' : sec.alignment || 'center'; | |
| const dir = side ? sec[side].dir || 'ltr' : sec.dir || 'ltr'; | |
| currentTextEdit = { index: idx, side, originalContent: content, originalAlignment: align, originalDir: dir }; | |
| const ed = document.getElementById('modalTextEditor'); | |
| ed.innerHTML = content; ed.style.textAlign = align; ed.dir = dir; | |
| document.getElementById('modalRtlToggle').checked = (dir === 'rtl'); | |
| setupModalToolbar(); | |
| document.getElementById('textEditModal').style.display = 'block'; | |
| } | |
| function closeTextEditModal() { document.getElementById('textEditModal').style.display = 'none'; currentTextEdit = {}; } | |
| function saveTextEdit() { | |
| const ed = document.getElementById('modalTextEditor'); | |
| const html = ed.innerHTML.trim(); | |
| const align = ed.style.textAlign || 'center'; | |
| const dir = ed.dir || 'ltr'; | |
| const { index, side } = currentTextEdit; | |
| const sec = sections[index]; | |
| if (side) { sec[side].text = html; sec[side].alignment = align; sec[side].dir = dir; } | |
| else { sec.content = html; sec.alignment = align; sec.dir = dir; } | |
| renderSections(); closeTextEditModal(); | |
| } | |
| function setupModalToolbar() { | |
| const ed = document.getElementById('modalTextEditor'); | |
| const exec = (c, v = null) => { ed.focus(); document.execCommand(c, false, v); }; | |
| const setAlign = a => { const sel = window.getSelection(); if (!sel.rangeCount) return; const r = sel.getRangeAt(0); let n = r.commonAncestorContainer; while (n && n.nodeType !== 1) n = n.parentNode; if (n) n.style.textAlign = a; ed.style.textAlign = a; }; | |
| const setSize = s => { exec('fontSize', '7'); setTimeout(() => { ed.querySelectorAll('font[size="7"]').forEach(f => { f.style.fontSize = s; f.removeAttribute('size'); }); }, 10); }; | |
| const openLink = () => { | |
| const sel = window.getSelection(); | |
| if (!sel.rangeCount || sel.toString().trim() === '') { alert('Select text first!'); return; } | |
| currentTextLinkRange = sel.getRangeAt(0); | |
| document.getElementById('textLinkUrl').value = ''; | |
| document.getElementById('textLinkModal').style.display = 'block'; | |
| }; | |
| document.getElementById('modalFontFamily').onchange = e => exec('fontName', e.target.value); | |
| document.getElementById('modalFontSize').onchange = e => setSize(e.target.value); | |
| document.getElementById('modalTextColor').onchange = e => exec('foreColor', e.target.value); | |
| document.getElementById('modalBoldBtn').onclick = () => exec('bold'); | |
| document.getElementById('modalItalicBtn').onclick = () => exec('italic'); | |
| document.getElementById('modalUnderlineBtn').onclick = () => exec('underline'); | |
| document.getElementById('modalLinkBtn').onclick = openLink; | |
| document.getElementById('modalAlignLeftBtn').onclick = () => setAlign('left'); | |
| document.getElementById('modalAlignCenterBtn').onclick = () => setAlign('center'); | |
| document.getElementById('modalAlignRightBtn').onclick = () => setAlign('right'); | |
| document.getElementById('modalRtlToggle').onchange = e => { ed.dir = e.target.checked ? 'rtl' : 'ltr'; }; | |
| } | |
| function applyTextLink() { | |
| const url = document.getElementById('textLinkUrl').value.trim(); | |
| if (!url) { alert('Enter a URL'); return; } | |
| const a = document.createElement('a'); a.href = url; | |
| a.appendChild(currentTextLinkRange.extractContents()); | |
| currentTextLinkRange.insertNode(a); | |
| closeTextLinkModal(); | |
| } | |
| function closeTextLinkModal() { document.getElementById('textLinkModal').style.display = 'none'; currentTextLinkRange = null; } | |
| function openImageLinkModal(idx, side = null) { | |
| const sec = sections[idx]; | |
| currentImageLink = { index: idx, side, url: (side ? sec[side].link : sec.link) || '' }; | |
| document.getElementById('linkUrlInput').value = currentImageLink.url; | |
| document.getElementById('imageLinkModal').style.display = 'block'; | |
| } | |
| function closeImageLinkModal() { document.getElementById('imageLinkModal').style.display = 'none'; currentImageLink = {}; } | |
| function saveImageLink() { | |
| const url = document.getElementById('linkUrlInput').value.trim(); | |
| const { index, side } = currentImageLink; | |
| const sec = sections[index]; | |
| const val = url ? url : null; | |
| if (side) sec[side].link = val; else sec.link = val; | |
| renderSections(); closeImageLinkModal(); | |
| } | |
| /* ==================== RESIZE / DRAG-DROP ==================== */ | |
| function setupImageResizing() { | |
| document.querySelectorAll('.resize-handle').forEach(h => { | |
| h.onmousedown = e => { | |
| e.preventDefault(); e.stopPropagation(); | |
| const img = h.parentNode.querySelector('.resizable-img'); | |
| resizingImage = img; | |
| startX = e.clientX; | |
| startWidth = img.getBoundingClientRect().width; | |
| document.addEventListener('mousemove', resizeImage); | |
| document.addEventListener('mouseup', stopResize); | |
| }; | |
| }); | |
| } | |
| function resizeImage(e) { | |
| if (!resizingImage) return; | |
| const delta = e.clientX - startX; | |
| let w = startWidth + delta; | |
| w = Math.max(50, Math.min(700, w)); | |
| resizingImage.style.width = w + 'px'; | |
| const idx = parseInt(resizingImage.dataset.index), side = resizingImage.dataset.side; | |
| const sec = sections[idx]; | |
| if (sec.type === 'image') sec.width = w; | |
| else if (sec.type === 'twoColumn' || sec.type === 'twoColumnImg') sec[side].width = w; | |
| } | |
| function stopResize() { | |
| if (resizingImage) resizingImage = null; | |
| document.removeEventListener('mousemove', resizeImage); | |
| document.removeEventListener('mouseup', stopResize); | |
| } | |
| function setupDragAndDrop() { | |
| document.querySelectorAll('.section').forEach(s => { | |
| s.ondragstart = e => { dragIndex = parseInt(s.dataset.index); s.style.opacity = '0.5'; }; | |
| s.ondragend = () => { s.style.opacity = ''; }; | |
| s.ondragover = e => e.preventDefault(); | |
| s.ondrop = e => { | |
| e.preventDefault(); | |
| const drop = parseInt(s.dataset.index); | |
| if (dragIndex === -1 || dragIndex === drop) return; | |
| const [m] = sections.splice(dragIndex, 1); | |
| sections.splice(drop, 0, m); | |
| renderSections(); dragIndex = -1; | |
| }; | |
| }); | |
| } | |
| function moveSection(i, d) { | |
| const ni = i + d; | |
| if (ni < 0 || ni >= sections.length) return; | |
| const [m] = sections.splice(i, 1); | |
| sections.splice(ni, 0, m); | |
| renderSections(); | |
| } | |
| /* ==================== EXPORT / SEND ==================== */ | |
| function prepareSendEmail() { | |
| generateHtml(); | |
| document.getElementById('emailSubjectSection').style.display = 'block'; | |
| document.getElementById('emailSubject').focus(); | |
| } | |
| function sendTestEmail() { | |
| const sub = document.getElementById('emailSubject').value.trim(); | |
| if (!sub) { document.getElementById('sendStatus').innerHTML = '<span class="text-red-500">Enter a subject</span>'; return; } | |
| const html = document.getElementById('exportHtmlOutput').value; | |
| const fd = new FormData(); fd.append('entry.6401835', sub); fd.append('entry.1337605913', html); | |
| document.getElementById('sendStatus').innerHTML = '<span class="text-gray-600">Sending test email…</span>'; | |
| fetch('https://docs.google.com/forms/d/e/1FAIpQLSfU_CGfsB2k3jhphorDDlMKkAuBzOJwGIlDItvspHFIGkx9Sw/formResponse', { method: 'POST', mode: 'no-cors', body: fd }) | |
| .then(() => { document.getElementById('sendStatus').innerHTML = '<span class="text-green-600">Test email sent!</span>'; setTimeout(() => { document.getElementById('emailSubjectSection').style.display = 'none'; document.getElementById('sendStatus').innerHTML = ''; }, 3000); }) | |
| .catch(() => { document.getElementById('sendStatus').innerHTML = '<span class="text-red-500">Error sending test</span>'; }); | |
| } | |
| function previewAndSend() { | |
| const sub = document.getElementById('emailSubject').value.trim(); | |
| if (!sub) { | |
| document.getElementById('sendStatus').innerHTML = '<span class="text-red-500">Enter a subject</span>'; | |
| return; | |
| } | |
| const html = document.getElementById('exportHtmlOutput').value; | |
| // Open preview in new tab | |
| const previewUrl = `https://mail.google.com/mail/?view=cm&fs=1&su=${encodeURIComponent(sub)}&body=${encodeURIComponent(html)}`; | |
| window.open(previewUrl, '_blank'); | |
| // Submit to form | |
| document.getElementById('sendStatus').innerHTML = '<span class="text-gray-600">Submitting to form...</span>'; | |
| const formData = new FormData(); | |
| formData.append('entry.1234', sub); // Subject field | |
| formData.append('entry.4321', html); // HTML content field | |
| fetch('https://docs.google.com/forms/d/e/YOUR_FORM_ID_HERE/formResponse', { | |
| method: 'POST', | |
| mode: 'no-cors', | |
| body: formData | |
| }) | |
| .then(() => { | |
| document.getElementById('sendStatus').innerHTML = '<span class="text-green-600">Submitted successfully!</span>'; | |
| setTimeout(() => { | |
| document.getElementById('emailSubjectSection').style.display = 'none'; | |
| document.getElementById('sendStatus').innerHTML = ''; | |
| }, 3000); | |
| }) | |
| .catch(() => { | |
| document.getElementById('sendStatus').innerHTML = '<span class="text-red-500">Error submitting form</span>'; | |
| }); | |
| } | |
| function exportHtml() { | |
| generateHtml(); | |
| document.getElementById('copyBtnInModal').classList.remove('hidden'); | |
| document.getElementById('exportModal').style.display = 'block'; | |
| } | |
| function closeExportModal() { | |
| document.getElementById('exportModal').style.display = 'none'; | |
| document.getElementById('copyBtnInModal').classList.add('hidden'); | |
| } | |
| function generateHtml() { | |
| let content = ''; | |
| sections.forEach(s => { | |
| if (s.type === 'image') { | |
| const w = s.width ? ` width="${s.width}"` : ''; | |
| const link = s.link ? `<a href="${s.link}">` : ''; | |
| const cl = s.link ? '</a>' : ''; | |
| content += `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:10px 40px;" align="center">${link}<img style="display:block;max-width:100%;height:auto;" src="${s.url}" alt="${s.name}"${w}>${cl}</td></tr></table>`; | |
| } else if (s.type === 'text') { | |
| content += `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:10px 40px;font-family:Arial,Verdana,Helvetica,sans-serif;color:#3e3e3e;font-size:14px;text-align:${s.alignment||'center'};line-height:1.5;">${s.content}</td></tr></table>`; | |
| } else if (s.type === 'divider') { | |
| content += `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:10px 40px;" align="center"><div style="height:${s.thickness||'1'}px;background:${s.color||'#000'};"></div></td></tr></table>`; | |
| } else if (s.type === 'twoColumn') { | |
| const lw = s.left.width ? ` width="${s.left.width}"` : ''; | |
| const rw = s.right.width ? ` width="${s.right.width}"` : ''; | |
| const leftLink = s.left.link ? `<a href="${s.left.link}">` : ''; | |
| const leftCl = s.left.link ? '</a>' : ''; | |
| const rightLink = s.right.link ? `<a href="${s.right.link}">` : ''; | |
| const rightCl = s.right.link ? '</a>' : ''; | |
| content += `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:0 40px;" align="center"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0"><tr> | |
| <td style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| ${leftLink}<img style="display:block;max-width:100%;height:auto;" src="${s.left.image}" alt="${s.left.name}"${lw}>${leftCl} | |
| <div style="padding:10px 20px;font-size:14px;text-align:${s.left.alignment||'center'};line-height:1.5;">${s.left.text}</div> | |
| </td> | |
| <td style="width:10px;background:#fff;"></td> | |
| <td style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| ${rightLink}<img style="display:block;max-width:100%;height:auto;" src="${s.right.image}" alt="${s.right.name}"${rw}>${rightCl} | |
| <div style="padding:10px 20px;font-size:14px;text-align:${s.right.alignment||'center'};line-height:1.5;">${s.right.text}</div> | |
| </td> | |
| </tr></table></td></tr></table>`; | |
| } else if (s.type === 'twoColumnImg') { | |
| const lw = s.left.width ? ` width="${s.left.width}"` : ''; | |
| const rw = s.right.width ? ` width="${s.right.width}"` : ''; | |
| const leftLink = s.left.link ? `<a href="${s.left.link}">` : ''; | |
| const leftCl = s.left.link ? '</a>' : ''; | |
| const rightLink = s.right.link ? `<a href="${s.right.link}">` : ''; | |
| const rightCl = s.right.link ? '</a>' : ''; | |
| content += `<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td style="padding:0 40px;" align="center"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0"><tr> | |
| <td style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| ${leftLink}<img style="display:block;max-width:100%;height:auto;" src="${s.left.image}" alt="${s.left.name}"${lw}>${leftCl} | |
| </td> | |
| <td style="width:10px;"></td> | |
| <td style="width:272px;background:#f1f1f1;vertical-align:top;"> | |
| ${rightLink}<img style="display:block;max-width:100%;height:auto;" src="${s.right.image}" alt="${s.right.name}"${rw}>${rightCl} | |
| </td> | |
| </tr></table></td></tr></table>`; | |
| } | |
| }); | |
| const full = ` | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#474747"> | |
| <tbody><tr><td align="center"> | |
| <table style="width:700px;" border="0" cellspacing="0" cellpadding="0"> | |
| <tbody><tr><td style="padding:15px 10px;"> | |
| <table border="0" width="100%" cellspacing="0" cellpadding="0" style="background:#fff;border:18px solid #392b0e;"> | |
| <tbody><tr><td style="padding:0;"> | |
| <div style="border:3px solid #fff;"> | |
| <img src="https://drive.google.com/uc?export=view&id=1XUnRDQiyh2uqYOFBUk1EAgq57lm1IlI" alt="Header" style="width:100%;display:block;"> | |
| </div> | |
| <div style="padding:10px 40px;">${content}</div> | |
| <div style="border:3px solid #fff;"> | |
| <img src="https://drive.google.com/uc?export=view&id=1X6HOaa17HVGUlEAHKCTHYefoPcXYFsCI" alt="Footer" style="width:100%;display:block;"> | |
| </div> | |
| </td></tr></tbody> | |
| </table> | |
| </td></tr></tbody> | |
| </table> | |
| </td></tr></tbody> | |
| </table>`; | |
| document.getElementById('exportHtmlOutput').value = full; | |
| } | |
| function copyHtml() { | |
| const ta = document.getElementById('exportHtmlOutput'); | |
| ta.select(); | |
| document.execCommand('copy'); | |
| closeExportModal(); | |
| document.getElementById('copiedPopup').style.display = 'flex'; | |
| } | |
| function closeCopiedPopup() { | |
| document.getElementById('copiedPopup').style.display = 'none'; | |
| } | |
| /* ==================== SECTION ADD ==================== */ | |
| function addSection(type) { | |
| let sec; | |
| if (type === 'image') sec = { type: 'image', url: '', name: '', width: 400, link: null }; | |
| else if (type === 'text') sec = { type: 'text', content: '<p style="text-align:center;">Double-click to edit</p>', alignment: 'center', dir: 'ltr' }; | |
| else if (type === 'divider') sec = { type: 'divider', thickness: '1', color: '#000000', style: 'solid' }; | |
| else if (type === 'twoColumn') sec = { | |
| type: 'twoColumn', | |
| left: { image: '', name: '', text: '<p style="text-align:center;">Left text</p>', width: 250, alignment: 'center', link: null, dir: 'ltr' }, | |
| right: { image: '', name: '', text: '<p style="text-align:center;">Right text</p>', width: 250, alignment: 'center', link: null, dir: 'ltr' } | |
| }; | |
| else if (type === 'twoColumnImg') sec = { | |
| type: 'twoColumnImg', | |
| left: { image: '', name: '', width: 250, link: null }, | |
| right: { image: '', name: '', width: 250, link: null } | |
| }; | |
| sections.push(sec); renderSections(); | |
| } | |
| /* ==================== START ==================== */ | |
| init(); | |
| </script> | |
| </body> | |
| </html> |