Перейти к содержанию

MediaWiki:Common.js: различия между версиями

нет описания правки
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
if (document.readyState !== 'loading') {
if (document.readyState !== 'loading') {
    console.log('document is already ready, just execute code here');
  console.log('document is already ready, just execute code here');
  myInitCode();
} else {
  document.addEventListener('DOMContentLoaded', function () {
    console.log('document was not ready, place code here');
     myInitCode();
     myInitCode();
} else {
  });
    document.addEventListener('DOMContentLoaded', function () {
        console.log('document was not ready, place code here');
        myInitCode();
    });
}
}
function myInitCode() {
function myInitCode() {
    const node = document.getElementById("content");
  var node = document.getElementById("content");
    const content = document.createElement("ul");
  var content = document.createElement("ul");
    content.classList.add("custom-top-menu");
  content.classList.add("custom-top-menu");
    
   var items = [{
    const items = [
    href: "/wiki/Вики-энциклопедия_университета",
      {
    title: "Главная",
        href: "/wiki/Вики-энциклопедия_университета",
    text: "Главная",
        title: "Главная",
    spanText: "Главная"
        text: "Главная",
  }, {
        spanText: "Главная"
    href: "/wiki/Правила",
      },
    title: "Правила",
      {
    text: "Правила",
        href: "/wiki/Правила",
    spanText: "Правила"
        title: "Правила",
  }, {
        text: "Правила",
    href: "/wiki/Служебная:Все_страницы",
        spanText: "Правила"
    title: "Все страницы",
      },
    text: "Статьи",
      {
    spanText: "Статьи"
        href: "/wiki/Служебная:Все_страницы",
  }, {
        title: "Все страницы",
    href: "/wiki/Служебная:Свежие_правки",
        text: "Статьи",
    title: "Свежие правки",
        spanText: "Статьи"
    text: "История правок",
      },
    spanText: "История правок"
      {
  }, {
        href: "/wiki/Служебная:Свежие_правки",
    href: "/wiki/Инструкции",
        title: "Свежие правки",
    title: "Инструкции",
        text: "История правок",
    text: "Инструкции",
        spanText: "История правок"
    spanText: "Инструкции"
      },
  }, {
      {
    href: "/wiki/Контакты",
        href: "/wiki/Инструкции",
    title: "Заголовок 2",
        title: "Инструкции",
    text: "Контакты",
        text: "Инструкции",
    spanText: "Контакты"
        spanText: "Инструкции"
  }];
      },
   items.forEach(function (item) {
      {
    var li = document.createElement("li");
        href: "/wiki/Контакты",
    var a = document.createElement("a");
        title: "Заголовок 2",
    a.href = item.href;
        text: "Контакты",
    a.title = item.title;
        spanText: "Контакты"
    a.textContent = item.text;
      }
    var span = document.createElement("span");
    ];
    span.textContent = item.spanText;
    
    a.appendChild(span);
    items.forEach((item) => {
    li.appendChild(a);
      const li = document.createElement("li");
    content.appendChild(li);
      const a = document.createElement("a");
  });
      a.href = item.href;
   node.parentNode.insertBefore(content, node);
      a.title = item.title;
  var currentPageHref = decodeURI(window.location.href);
      a.textContent = item.text;
  var links = document.querySelectorAll('.custom-top-menu a');
      const span = document.createElement("span");
  links.forEach(function (link) {
      span.textContent = item.spanText;
    var linkhref = link.getAttribute('href').trim();
      a.appendChild(span);
    console.log(currentPageHref + '=' + linkhref);
      li.appendChild(a);
    if (currentPageHref.indexOf(linkhref) > -1) {
      content.appendChild(li);
      link.closest('li').classList.add('a-current');
    });
    }
    
    node.parentNode.insertBefore(content, node);
      var currentPageHref = decodeURI(window.location.href);
      var links = document.querySelectorAll('.custom-top-menu a');
      links.forEach(function(link) {
      var linkhref = link.getAttribute('href').trim();
      console.log(currentPageHref + '=' + linkhref);
      if (currentPageHref.indexOf(linkhref) > -1) {
          link.closest('li').classList.add('a-current');
      }
   });
   });
}
}