Jump to content

MediaWiki:Common.js: Difference between revisions

From Event Gates Wiki
No edit summary
No edit summary
Line 61: Line 61:
$(document).ready(function () {
$(document).ready(function () {
     if (mw.config.get('skin') === 'vector-2022') {
     if (mw.config.get('skin') === 'vector-2022') {
         const userMenu = document.querySelector('[data-event-name="user-menu-dropdown"]');
         const intervalId = setInterval(() => {
        if (userMenu) {
             const dropdown = document.getElementById('vector-user-links-dropdown');
             const menuList = userMenu.querySelector('ul');


             const li = document.createElement('li');
             if (dropdown) {
            li.className = 'vector-user-menu-overflow-item';
                const menuList = dropdown.querySelector('ul');
            const a = document.createElement('a');
            a.href = mw.util.getUrl('Special:RecentChanges');
            a.textContent = 'Recent changes';
            li.appendChild(a);


            menuList.appendChild(li);
                if (menuList && !menuList.querySelector('.recent-changes-item')) {
        } else {
                    const li = document.createElement('li');
            console.warn('User menu not found for Vector 2022.');
                    li.className = 'vector-user-links-menu-item recent-changes-item';
         }
 
                    const a = document.createElement('a');
                    a.href = mw.util.getUrl('Special:RecentChanges');
                    a.textContent = 'Recent changes';
 
                    li.appendChild(a);
                    menuList.appendChild(li);
                }
 
                clearInterval(intervalId);
            }
         }, 300);
     }
     }
});
});

Revision as of 10:19, 5 July 2025

$(function () {
  $('#mw-navigation').append(`
    <div id="p-custom-categorytree">
      <div class="vector-pinnable-header-label">Categories</div>
      <div id="categorytree-content">Loading categories...</div>
    </div>
  `);

  $.ajax({
    url: mw.util.wikiScript('api'),  // <-- fixed here
    data: {
      action: 'parse',
      page: 'SidebarMenu',
      format: 'json'
    },
    dataType: 'json',
    success: function(data) {
      if (data.parse && data.parse.text) {
        $('#categorytree-content').html(data.parse.text['*']);
      } else {
        $('#categorytree-content').html('Failed to load categories.');
      }
    },
    error: function() {
      $('#categorytree-content').html('Error loading categories.');
    }
  });
});

function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    includedLanguages: 'en,tr,de,fr', // Change as needed
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element');
}

//google translate at the search bar
document.addEventListener("DOMContentLoaded", function () {
  // Create the Google Translate container
  const translateDiv = document.createElement("div");
  translateDiv.id = "google_translate_element";
  translateDiv.style.display = "inline-block";
  translateDiv.style.marginLeft = "10px";

  // Wait a bit to ensure Vector 2022 has loaded the header
  setTimeout(() => {
    const headerRight = document.querySelector('.vector-header-end'); // This is where personal tools and search are
    if (headerRight) {
      headerRight.appendChild(translateDiv);

      // Now load the Google Translate script
      const gtScript = document.createElement('script');
      gtScript.type = 'text/javascript';
      gtScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
      document.body.appendChild(gtScript);
    }
  }, 500);
});
//add recent changes to personal tools
$(document).ready(function () {
    if (mw.config.get('skin') === 'vector-2022') {
        const intervalId = setInterval(() => {
            const dropdown = document.getElementById('vector-user-links-dropdown');

            if (dropdown) {
                const menuList = dropdown.querySelector('ul');

                if (menuList && !menuList.querySelector('.recent-changes-item')) {
                    const li = document.createElement('li');
                    li.className = 'vector-user-links-menu-item recent-changes-item';

                    const a = document.createElement('a');
                    a.href = mw.util.getUrl('Special:RecentChanges');
                    a.textContent = 'Recent changes';

                    li.appendChild(a);
                    menuList.appendChild(li);
                }

                clearInterval(intervalId);
            }
        }, 300);
    }
});