مرحباً بك في محرر بكرى النصي! ✨ ابدأ بالكتابة هنا…
الحروف: 0الكلمات: 0
`;// Create Blob with UTF-8 BOM for better compatibility
const blob = new Blob(['\ufeff', fullHtml], { type: 'application/msword;charset=utf-8' });
const link = document.createElement("a");
// Use download attribute if supported
if (link.download !== undefined) {
const url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", filename);
link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url);
} else {
// Fallback
window.open("data:application/msword;charset=utf-8," + encodeURIComponent(fullHtml));
}
console.log("محاولة تصدير Word (.doc)...");
}// Actions to perform when the window loads
window.onload = () => {
// Set initial active state for direction buttons
if (editor.dir === 'rtl') { rtlBtn.classList.add('active'); }
else { ltrBtn.classList.add('active'); }// Check if the editor content is just the welcome message
const initialText = editor.innerText || editor.textContent;
const welcomeElement = document.getElementById('welcomeMessage');
const welcomeText = welcomeElement ? welcomeElement.textContent.trim() : ""; // Trim welcome text for comparison// If welcome message element doesn't exist or text is different (and not empty after trim), assume user content exists
if (!welcomeElement || (initialText.trim() !== welcomeText && initialText.trim() !== '')) {
welcomeMessageActive = false;
} else if (initialText.trim() === welcomeText) {
// Otherwise, if it matches the welcome text, it is active
welcomeMessageActive = true;
// Ensure welcome message styling is applied (might be lost if loaded from saved state)
welcomeElement.style.color = '#6b7280';
welcomeElement.style.fontStyle = 'italic';
welcomeElement.style.paddingTop = '2px'; // Reapply padding if needed
} else {
// Editor is empty but doesn't contain the welcome message (e.g., user deleted it)
welcomeMessageActive = false;
}
updateCounts(); // Update counts on initial load
};