Jump to content

MediaWiki:Common.js

From Event Gates Wiki
Revision as of 14:10, 5 July 2025 by Kozsu (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//category tree on right panel
$(function () {
  $('.vector-sticky-pinned-container').append(`
    <div id="p-custom-categorytree" class="mw-table-of-contents-container vector-toc-landmark">
      <div id="p-custom-categorytree-container" class="vector-pinned-container">
        <div id="p-custom-categorytree-toc" class="vector-toc vector-pinnable-element">
          <div id="p-custom-categorytree-toc-2" class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" >
            <h2 class="vector-pinnable-header-label">Categories</h2>
          </div>
          <div id="categorytree-content" style="padding-left: 12px;">Loading categories...</div>
        </div>
      </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.');
    }
  });
});
//google translate init
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 put 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);
    }
  }, 1000);
});
//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.id = 'pt-recentchanges';
                    li.className = 'mw-list-item';

                   const a = document.createElement('a');
                    a.href = mw.util.getUrl('Special:RecentChanges');
                    a.title = 'Recent changes [alt-shift-r]';
                    a.accessKey = 'r';

                    const iconSpan = document.createElement('span');
                    iconSpan.className = 'vector-icon mw-ui-icon-wikimedia-history';

                    const textSpan = document.createElement('span');
                    textSpan.textContent = 'Recent changes';

                    a.appendChild(iconSpan);
                    a.appendChild(textSpan);

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

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