(function () { 
  const url = window.location.href;

  // Если нет /view → не выполняем
  if (!url.includes('/view')) {
    console.log('Скрипт не выполняется, нет view');
    return;
  }

  // Если editMode=1 → не выполняем
  if (/editMode[=/]1/.test(url)) return;

  // &#9989; Если есть "fileindex/file" → не выполняем
  if (url.includes('/file')) {
    console.log('Скрипт не выполняется, есть fileindex/file');
    return;
  }
if (url.includes('/task/')) {
    console.log('Скрипт не выполняется, есть /task/');
    return;
  }
    
  console.log('Скрипт выполняется!');

  const GITHUB_BASE = 'https://oleggelo2002.github.io/Lilia_Gaevaya/';
  const head = document.head;

  // Проверка и подключение CSS
  const loadCSS = (filename) => {
    const fullHref = `${GITHUB_BASE}${filename}`;
    if (document.querySelector(`link[href="${fullHref}"]`)) return;

    const link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = fullHref;
    head.appendChild(link);
  };

  // Проверка и подключение JS
  const loadJS = (filename) => {
    const fullSrc = `${GITHUB_BASE}${filename}`;
    if (document.querySelector(`script[src="${fullSrc}"]`)) return;

    const script = document.createElement('script');
    script.src = fullSrc;
    script.defer = true;
    head.appendChild(script);
  };

  const isLessonPage = url.includes('/lesson/');
  const isBannerNeeded = !isLessonPage;

  loadCSS('Calendar.css');
  loadJS('Calendar.js');
    
  loadCSS('last-lesson.css');
  loadJS('last-lesson.js');
    
  loadCSS('Left-menu.css');
  loadJS('left-menu.js');
    
  loadCSS('Card.css');      
  loadJS('Card.js');     
    
  loadCSS('Search.css');
  loadJS('Search.js');

  if (!isLessonPage) {
    loadCSS('trening-and-lesson.css');
  }

  loadJS('v-yrok-name-url.js');
  loadJS('img-number_lesson.js');
  loadJS('trening-block-img.js');
  loadCSS('mvp.css');
  loadJS('mvp.js');

  if (!isLessonPage) {
    loadCSS('Banner.css');
    loadJS('Banner.js');
  }

  if (isLessonPage) {
    loadCSS('lesson-under.css');
  }
})();


