محرر Word أونلاين متكاملاسحب الملفات هنا
يمكنك سحب ملفات Word (.docx) أو النصية (.txt) وإفلاتها هنا لفتحها
مرحباً بك في محرر Word أونلاين!
هذا محرر نصوص متكامل يمكنك من:
- فتح ملفات نصية (TXT) و Word (DOCX)
- تحرير النصوص وتنسيقها بشكل كامل
- حفظ المستندات كملفات Word أو نص
- طباعة المستندات مباشرة
- إنشاء مستندات جديدة
ابدأ بالكتابة أو حمل ملفاً للبدء!
عدد الكلمات: 0
عدد الأحرف: 0
الصفحات: 1
حالة: جاهز
وضع: تحرير
تم تنفيذ العملية بنجاح!
`;
// إنشاء ملف Word باستخدام MIME type صحيح
const blob = new Blob([content], {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
});
// حفظ الملف
saveAs(blob, "مستند_Word_" + getCurrentDateTime() + ".docx");
hideLoading();
showNotification('تم حفظ الملف كـ Word بنجاح!', 'success');
} catch (error) {
console.error('Error saving Word file:', error);
hideLoading();
showNotification('حدث خطأ أثناء حفظ الملف كـ Word', 'error');
}
}// دالة للحصول على التاريخ والوقت الحالي
function getCurrentDateTime() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;
}// حفظ كملف نصي
function saveAsTxt() {
const content = editor.innerText;
if (!content.trim()) {
showNotification('لا يوجد محتوى لحفظه', 'warning');
return;
}
try {
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
saveAs(blob, "مستند_نصي_" + getCurrentDateTime() + ".txt");
showNotification('تم حفظ الملف النصي بنجاح!', 'success');
} catch (error) {
console.error('Error saving text file:', error);
showNotification('حدث خطأ أثناء حفظ الملف النصي', 'error');
}
}// باقي الدوال تبقى كما هي
function execCommand(command, value = null) {
try {
document.execCommand(command, false, value);
editor.focus();
updateWordCount();
} catch (error) {
console.error('Command error:', error);
showNotification('لا يمكن تنفيذ هذا الأمر', 'error');
}
}function printDocument() {
if (!editor.innerText.trim()) {
showNotification('لا يوجد محتوى للطباعة', 'warning');
return;
}
try {
const printContent = `
طباعة المستند
${editor.innerHTML}
`;
const printWindow = window.open('', '_blank');
printWindow.document.write(printContent);
printWindow.document.close();
setTimeout(() => {
printWindow.print();
}, 500);
} catch (error) {
console.error('Error printing:', error);
showNotification('حدث خطأ أثناء الطباعة', 'error');
}
}function newDocument() {
if (editor.innerText.trim() && !confirm('هل تريد إنشاء مستند جديد؟ سيتم فقدان التغييرات غير المحفوظة.')) {
return;
}
editor.innerHTML = `
مستند جديد
ابدأ الكتابة هنا...
`;
updateWordCount();
showNotification('تم إنشاء مستند جديد', 'success');
}function insertLink() {
document.getElementById('linkModal').style.display = 'block';
}function insertLinkConfirm() {
const text = document.getElementById('linkText').value || 'رابط';
const url = document.getElementById('linkUrl').value;
if (!url) {
showNotification('يرجى إدخال رابط صحيح', 'warning');
return;
}
try {
const linkHTML = `
${text}`;
document.execCommand('insertHTML', false, linkHTML);
closeModal('linkModal');
showNotification('تم إدراج الرابط بنجاح', 'success');
} catch (error) {
showNotification('خطأ في إدراج الرابط', 'error');
}
}function insertTable() {
const rows = parseInt(prompt('عدد الصفوف:', '3')) || 3;
const cols = parseInt(prompt('عدد الأعمدة:', '3')) || 3;
if (rows > 0 && cols > 0) {
try {
let tableHTML = '
';
for (let i = 0; i < rows; i++) {
tableHTML += '';
for (let j = 0; j < cols; j++) {
tableHTML += `| | `;
}
tableHTML += '
';
}
tableHTML += '
';
document.execCommand('insertHTML', false, tableHTML);
showNotification('تم إدراج الجدول بنجاح', 'success');
} catch (error) {
showNotification('خطأ في إدراج الجدول', 'error');
}
}
}function setViewMode(mode) {
document.getElementById('mainContainer').classList.remove('focus-mode', 'read-mode');
document.getElementById('editViewBtn').classList.remove('active');
document.getElementById('readViewBtn').classList.remove('active');
document.getElementById('focusViewBtn').classList.remove('active');
if (mode === 'focus') {
document.getElementById('mainContainer').classList.add('focus-mode');
document.getElementById('focusViewBtn').classList.add('active');
document.getElementById('viewMode').textContent = 'تركيز';
} else if (mode === 'read') {
document.getElementById('mainContainer').classList.add('read-mode');
document.getElementById('readViewBtn').classList.add('active');
document.getElementById('viewMode').textContent = 'قراءة';
} else {
document.getElementById('editViewBtn').classList.add('active');
document.getElementById('viewMode').textContent = 'تحرير';
}
}function toggleRuler() {
const ruler = document.getElementById('ruler');
const isVisible = ruler.style.display === 'block';
ruler.style.display = isVisible ? 'none' : 'block';
document.getElementById('rulerToggle').classList.toggle('active', !isVisible);
showNotification(isVisible ? 'تم إخفاء المسطرة' : 'تم إظهار المسطرة');
}function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
if (modalId === 'linkModal') {
document.getElementById('linkText').value = '';
document.getElementById('linkUrl').value = '';
} else if (modalId === 'imageModal') {
document.getElementById('imageUrl').value = '';
document.getElementById('imageUpload').value = '';
document.getElementById('imagePreview').style.display = 'none';
}
}function showLoading(text = 'جاري التحميل...') {
loadingText.textContent = text;
loading.style.display = 'flex';
}function hideLoading() {
loading.style.display = 'none';
}function updateWordCount() {
const text = editor.innerText || editor.textContent;
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
const chars = text.length;
const pages = Math.ceil(chars / 2000) || 1;
document.getElementById('wordCount').textContent = words;
document.getElementById('charCount').textContent = chars;
document.getElementById('pageCount').textContent = pages;
}function showNotification(message, type = 'info') {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.className = 'notification';
if (type === 'error') {
notification.classList.add('error');
} else if (type === 'warning') {
notification.classList.add('warning');
}
notification.style.display = 'block';
setTimeout(() => {
notification.style.display = 'none';
}, 3000);
}document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeModal('linkModal');
closeModal('imageModal');
}
});