document.addEventListener("DOMContentLoaded", function() {
// --- التعديل الجديد: التحقق من الصفحة الرئيسية ---
// إذا لم يكن الرابط هو الصفحة الرئيسية (/)، يتم إيقاف الكود فوراً
if (window.location.pathname !== '/') {
return;
}
// ---------------------------------------------
// 1. تعريف كود HTML
const myHeaderHTML = `
`;
// 2. تعريف كود CSS
const myStyles = `
`;
// 3. حقن الكود داخل الصفحة
document.head.insertAdjacentHTML("beforeend", myStyles);
const siteHeader = document.querySelector('header') || document.querySelector('.site-header');
const topBar = document.querySelector('.top-bar') || document.querySelector('.s-header');
let targetElement = siteHeader || topBar;
if (targetElement && !document.getElementById('custom-header-section')) {
targetElement.insertAdjacentHTML('afterend', myHeaderHTML);
} else if (!document.getElementById('custom-header-section')) {
document.body.insertAdjacentHTML('afterbegin', myHeaderHTML);
}
// 4. وظيفة النزول عند الضغط
setTimeout(function() {
const scrollBtn = document.getElementById('scrollBtn');
if (scrollBtn) {
scrollBtn.addEventListener('click', function() {
window.scrollTo({
top: 850,
behavior: 'smooth'
});
});
}
}, 500);
// 5. دالة الكتابة والمسح المتكررة
function startTypingLoop() {
const textToType = "معلومات متكاملة";
const typeElement = document.getElementById("type-text");
if (!typeElement) return;
let charIndex = 0;
let isDeleting = false;
function type() {
const currentText = textToType;
if (isDeleting) {
typeElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
} else {
typeElement.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
}
let typeSpeed = 100;
if (isDeleting) typeSpeed /= 2;
if (!isDeleting && charIndex === currentText.length) {
typeSpeed = 2000;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
typeSpeed = 500;
}
setTimeout(type, typeSpeed);
}
type();
}
setTimeout(startTypingLoop, 500);
// 6. تحميل خلفية Particles
function loadParticlesLibrary() {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js';
script.onload = function () {
particlesJS("particles-js", {
"particles": {
"number": { "value": 100, "density": { "enable": true, "value_area": 800 } },
"color": { "value": "#ffffff" },
"shape": { "type": "circle" },
"opacity": { "value": 0.5, "random": false },
"size": { "value": 3, "random": true },
"line_linked": { "enable": true, "distance": 150, "color": "#ffffff", "opacity": 0.4, "width": 1 },
"move": { "enable": true, "speed": 4, "direction": "none", "random": false, "straight": false, "out_mode": "out", "bounce": false }
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": { "enable": true, "mode": "repulse" },
"onclick": { "enable": true, "mode": "push" },
"resize": true
}
},
"retina_detect": true
});
};
document.body.appendChild(script);
}
loadParticlesLibrary();
});