Tip of the Day
Long pressing an item opens multi-selection options in the inventory.

MediaWiki:Gadget-TranslatedTabTitle.js: Difference between revisions

From Walkscape Walkthrough
mNo edit summary
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
/**
/**
  * Gadget: TranslatedTabTitle
  * Gadget: TranslatedTabTitle
  * Updates the browser tab title to match the translated page title.
  * Updates the browser tab title to match the visible page heading.
* Works on all namespaces and translated pages.
  */
  */
(function () {
(function () {
   var SITE_SUFFIX = ' – TEST';
   var SITE_SUFFIX = '- The Walkscape Wiki';


   function computeTitle() {
   function computeTitle() {
Line 11: Line 12:
     if (!t) return;
     if (!t) return;


    // Optional: show language tag if on /lang subpage
     var current = document.title;
     var m = mw.config.get('wgPageName').match(/\/([a-z0-9\-]+)$/i);
     var base = t;
     var langTag = m ? ' [' + m[1] + ']' : '';


    var current = document.title;
    var base = t + langTag;
     if (!current.startsWith(base)) {
     if (!current.startsWith(base)) {
       document.title = base + SITE_SUFFIX;
       document.title = base + SITE_SUFFIX;
Line 24: Line 22:
   }
   }


   // Run when the page is ready
   // Run when the DOM is ready
   $(computeTitle);
   $(computeTitle);
  // Re-run when MediaWiki reloads content dynamically
   mw.hook('wikipage.content').add(computeTitle);
   mw.hook('wikipage.content').add(computeTitle);


   // Watch for changes to the heading text
   // Also observe heading changes
   var h = document.getElementById('firstHeading');
   var h = document.getElementById('firstHeading');
   if (h && window.MutationObserver) {
   if (h && window.MutationObserver) {

Latest revision as of 00:48, 28 November 2025

/**
 * Gadget: TranslatedTabTitle
 * Updates the browser tab title to match the visible page heading.
 * Works on all namespaces and translated pages.
 */
(function () {
  var SITE_SUFFIX = '- The Walkscape Wiki';

  function computeTitle() {
    var $h = $('#firstHeading, .firstHeading, .mw-first-heading, .mw-page-title-main').first();
    var t = $h.text().trim();
    if (!t) return;

    var current = document.title;
    var base = t;

    if (!current.startsWith(base)) {
      document.title = base + SITE_SUFFIX;
    } else if (!current.endsWith(SITE_SUFFIX)) {
      document.title = current + SITE_SUFFIX;
    }
  }

  // Run when the DOM is ready
  $(computeTitle);

  // Re-run when MediaWiki reloads content dynamically
  mw.hook('wikipage.content').add(computeTitle);

  // Also observe heading changes
  var h = document.getElementById('firstHeading');
  if (h && window.MutationObserver) {
    new MutationObserver(function () { computeTitle(); })
      .observe(h, { childList: true, characterData: true, subtree: true });
  }
})();