Action successful!
`], { type: 'text/html' });
awpCreateLink(blob, `${filename}.html`);
} else if (format === 'txt') {
const blob = new Blob([awpEditor.innerText], { type: 'text/plain' });
awpCreateLink(blob, `${filename}.txt`);
} else if (format === 'md') {
const turndownService = new TurndownService();
const markdown = turndownService.turndown(content);
const blob = new Blob([markdown], { type: 'text/markdown' });
awpCreateLink(blob, `${filename}.md`);
} else if (format === 'pdf') {
awpShowToast('Generating PDF...', 'fa-spinner fa-spin');
html2canvas(awpEditor, { scale: 2 }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF('p', 'pt', 'a4');
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth() - 40;
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 20, 20, pdfWidth, pdfHeight);
pdf.save(`${filename}.pdf`);
awpShowToast('PDF Downloaded!');
}).catch(err => awpShowToast('PDF Generation Failed', 'fa-circle-xmark'));
}
}function awpCreateLink(blob, filename) {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
awpShowToast(`Downloaded as ${filename.split('.').pop().toUpperCase()}`);
}function awpSaveData() {
if (!awpEditor) return;
const data = awpIsSourceMode ? awpSource.value : awpEditor.innerHTML;
try {
localStorage.setItem('awp_saved_data', data);
awpShowToast('Progress Saved to Browser!');
} catch(e) {
awpShowToast('Storage unavailable', 'fa-triangle-exclamation');
}
}function awpToggleEmoji() {
const picker = document.getElementById('awp-emoji-picker');
if(picker) picker.style.display = picker.style.display === 'grid' ? 'none' : 'grid';
}function awpInit() {
awpEditor = document.getElementById('awp-editor');
awpSource = document.getElementById('awp-source');
awpContainer = document.getElementById('awp-container');if (!awpEditor || !awpSource || !awpContainer) return;// Core Listeners
awpEditor.addEventListener('input', awpUpdateCounts);
awpEditor.addEventListener('keyup', awpUpdateActiveStates);
awpEditor.addEventListener('mouseup', awpUpdateActiveStates);
awpSource.addEventListener('input', () => {
if(awpIsSourceMode) awpEditor.innerHTML = awpSource.value;
awpUpdateCounts();
});// Image Upload
const imgUpload = document.getElementById('awp-img-upload');
if(imgUpload) {
imgUpload.addEventListener('change', event => {
if(awpIsSourceMode) return;
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = e => awpExec('insertImage', e.target.result);
reader.readAsDataURL(file);
event.target.value = '';
}
});
}// File Import
const fileImport = document.getElementById('awp-file-import');
if(fileImport) {
fileImport.addEventListener('change', event => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = e => {
awpEditor.innerHTML = e.target.result;
if(awpIsSourceMode) awpSource.value = e.target.result;
awpUpdateCounts();
awpShowToast('File imported successfully!');
};
reader.readAsText(file);
event.target.value = '';
}
});
}// Load Saved Data
try {
const saved = localStorage.getItem('awp_saved_data');
if (saved) { awpEditor.innerHTML = saved; awpUpdateCounts(); }
} catch(e) {}// Auto Save Loop (Every 30s)
setInterval(() => {
if(!awpEditor) return;
const data = awpIsSourceMode ? awpSource.value : awpEditor.innerHTML;
if(data && data.trim() !== "") {
try { localStorage.setItem('awp_saved_data', data); } catch(e) {}
}
}, 30000);// Inject 100+ Fonts
const fonts = [
'Space Grotesk', 'Hind Siliguri', 'Abel', 'Anton', 'Archivo Black', 'Arimo', 'Arial',
'Bebas Neue', 'Bitter', 'Bree Serif', 'Cabin', 'Cairo', 'Caveat', 'Comfortaa',
'Cormorant Garamond', 'Courgette', 'Crimson Text', 'Dancing Script', 'Dosis',
'EB Garamond', 'Exo 2', 'Fira Sans', 'Fjalla One', 'Fredoka One', 'Georgia',
'Impact', 'Inconsolata', 'Indie Flower', 'Inter', 'Josefin Sans', 'Kanit',
'Karla', 'Lato', 'Libre Baskerville', 'Lobster', 'Lora', 'Macondo', 'Manrope',
'Merriweather', 'Montserrat', 'Mukta', 'Nanum Gothic', 'Noto Sans',
'Noto Sans Bengali', 'Nunito', 'Nunito Sans', 'Open Sans', 'Oswald', 'Oxygen',
'PT Sans', 'PT Serif', 'Pacifico', 'Playfair Display', 'Poiret One', 'Poppins',
'Prompt', 'Quicksand', 'Rajdhani', 'Raleway', 'Righteous', 'Roboto',
'Roboto Condensed', 'Roboto Mono', 'Roboto Slab', 'Rubik', 'Shadows Into Light',
'Signika', 'SolaimanLipi', 'Source Code Pro', 'Source Sans Pro', 'Tahoma', 'Teko',
'Times New Roman', 'Titillium Web', 'Trebuchet MS', 'Ubuntu', 'Varela Round',
'Verdana', 'Work Sans', 'Yanone Kaffeesatz', 'Zilla Slab'
];
const fontSelect = document.getElementById('awp-font-select');
if(fontSelect) {
fonts.forEach(font => {
const opt = document.createElement('option');
opt.value = font;
opt.innerText = font;
opt.style.fontFamily = `"${font}", sans-serif`;
fontSelect.appendChild(opt);
});
fontSelect.value = 'Space Grotesk';
}// Inject Extensive Emojis
const emojis = ['๐','๐','๐','๐','๐','๐
','๐','๐คฃ','๐ฅฒ','โบ๏ธ','๐','๐','๐','๐','๐','๐','๐','๐ฅฐ','๐','๐','๐','๐','๐','๐','๐','๐','๐คช','๐คจ','๐ง','๐ค','๐','๐ฅธ','๐คฉ','๐ฅณ','๐','๐','๐','๐','๐','๐','๐','โน๏ธ','๐ฃ','๐','๐ซ','๐ฉ','๐ฅบ','๐ข','๐ญ','๐ค','๐ ','๐ก','๐คฌ','๐คฏ','๐ณ','๐ฅต','๐ฅถ','๐ฑ','๐จ','๐ฐ','๐ฅ','๐','๐ค','๐ค','๐คญ','๐คซ','๐คฅ','๐ถ','๐','๐','๐ฌ','๐','๐ฏ','๐ฆ','๐ง','๐ฎ','๐ฒ','๐ฅฑ','๐ด','๐คค','๐ช','๐ต','๐ค','๐ฅด','๐คข','๐คฎ','๐คง','๐ท','๐ค','๐ค','๐ค','๐ค ','๐','๐ฟ','๐น','๐บ','๐คก','๐ฉ','๐ป','๐','โ ๏ธ','๐ฝ','๐พ','๐ค','๐','๐บ','๐ธ','๐น','๐ป','๐ผ','๐ฝ','๐','๐ฟ','๐พ','๐','๐ค','๐','โ','๐','๐','๐ค','๐ค','โ๏ธ','๐ค','๐ค','๐ค','๐ค','๐','๐','๐','๐','๐','โ๏ธ','๐','๐','โ','๐','๐ค','๐ค','๐','๐','๐','๐คฒ','๐ค','๐','โค๏ธ','๐งก','๐','๐','๐','๐','๐ค','๐ค','๐ค','๐','โค๏ธโ๐ฅ','โค๏ธโ๐ฉน','โฃ๏ธ','๐','๐','๐','๐','๐','๐','๐','โ
','โ','๐ฅ','โจ','๐','๐ฅ','๐ฏ'];
const emojiContainer = document.getElementById('awp-emoji-picker');
if(emojiContainer) {
emojis.forEach(e => {
const btn = document.createElement('button');
btn.className = 'awp-emoji-btn';
btn.innerText = e;
btn.onclick = (ev) => {
ev.preventDefault();
awpExec('insertText', e);
awpToggleEmoji();
};
emojiContainer.appendChild(btn);
});
}// Outside Click Listener for Menus
document.addEventListener('click', (e) => {
if (!e.target.closest('#awp-emoji-picker') && !e.target.closest('button[onclick="awpToggleEmoji()"]')) {
const ep = document.getElementById('awp-emoji-picker');
if(ep) ep.style.display = 'none';
}
});
}// Safely fire script (WordPress safe initialization)
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', awpInit);
} else {
awpInit();
}