MediaWiki:Common.js: Difference between revisions

Undo revision 6208 by Vaishnavi (talk)
Tag: Undo
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* MediaWiki:Common.js — grantha.io  (v7) */
/* MediaWiki:Common.js — grantha.io  (v7) */


( function () {
(function () {


  var LS_SCRIPT_KEY = 'grantha_reader_script';
    var LS_SCRIPT_KEY = 'grantha_reader_script';
  var currentScript = 'deva';
    var currentScript = 'deva';


  function devanagariToIAST( text ) {
    function devanagariToIAST(text) {
    var CONSONANTS = {
        var CONSONANTS = {
      'क':'k','ख':'kh','ग':'g','घ':'gh','ङ':'ṅ',
            'क': 'k', 'ख': 'kh', 'ग': 'g', 'घ': 'gh', 'ङ': 'ṅ',
      'च':'c','छ':'ch','ज':'j','झ':'jh','ञ':'ñ',
            'च': 'c', 'छ': 'ch', 'ज': 'j', 'झ': 'jh', 'ञ': 'ñ',
      'ट':'ṭ','ठ':'ṭh','ड':'ḍ','ढ':'ḍh','ण':'ṇ',
            'ट': 'ṭ', 'ठ': 'ṭh', 'ड': 'ḍ', 'ढ': 'ḍh', 'ण': 'ṇ',
      'त':'t','थ':'th','द':'d','ध':'dh','न':'n',
            'त': 't', 'थ': 'th', 'द': 'd', 'ध': 'dh', 'न': 'n',
      'प':'p','फ':'ph','ब':'b','भ':'bh','म':'m',
            'प': 'p', 'फ': 'ph', 'ब': 'b', 'भ': 'bh', 'म': 'm',
      'य':'y','र':'r','ल':'l','ळ':'ḷ','व':'v',
            'य': 'y', 'र': 'r', 'ल': 'l', 'ळ': 'ḷ', 'व': 'v',
      'श':'ś','ष':'ṣ','स':'s','ह':'h'
            'श': 'ś', 'ष': 'ṣ', 'स': 's', 'ह': 'h'
    };
        };
    var DIACRITICS = {
        var DIACRITICS = {
      'ा':'ā','ि':'i','ी':'ī','ु':'u','ू':'ū',
            'ा': 'ā', 'ि': 'i', 'ी': 'ī', 'ु': 'u', 'ू': 'ū',
      'ृ':'ṛ','ॄ':'ṝ','े':'e','ै':'ai','ो':'o','ौ':'au'
            'ृ': 'ṛ', 'ॄ': 'ṝ', 'े': 'e', 'ै': 'ai', 'ो': 'o', 'ौ': 'au'
    };
        };
    var VOWELS = {
        var VOWELS = {
      'अ':'a','आ':'ā','इ':'i','ई':'ī','उ':'u','ऊ':'ū',
            'अ': 'a', 'आ': 'ā', 'इ': 'i', 'ई': 'ī', 'उ': 'u', 'ऊ': 'ū',
      'ऋ':'ṛ','ॠ':'ṝ','ए':'e','ऐ':'ai','ओ':'o','औ':'au','ऽ':"'"
            'ऋ': 'ṛ', 'ॠ': 'ṝ', 'ए': 'e', 'ऐ': 'ai', 'ओ': 'o', 'औ': 'au', 'ऽ': "'"
    };
        };
    var MISC = {
        var MISC = {
      'ं':'ṃ','ः':'ḥ','ँ':'m̐','ॐ':'oṃ',
            'ं': 'ṃ', 'ः': 'ḥ', 'ँ': 'm̐', 'ॐ': 'oṃ',
      '०':'0','१':'1','२':'2','३':'3','४':'4',
            '०': '0', '१': '1', '२': '2', '३': '3', '४': '4',
      '५':'5','६':'6','७':'7','८':'8','९':'9'
            '५': '5', '६': '6', '७': '7', '८': '8', '९': '9'
    };
        };
    var HALANTA = '्';
        var HALANTA = '्';
    var chars = Array.from( text );
        var chars = Array.from(text);
    var result = '';
        var result = '';
    var i = 0;
        var i = 0;
    while ( i < chars.length ) {
        while (i < chars.length) {
      var ch   = chars[ i ];
            var ch = chars[i];
      var next = chars[ i + 1 ];
            var next = chars[i + 1];
      if ( CONSONANTS[ ch ] ) {
            if (CONSONANTS[ch]) {
        var base = CONSONANTS[ ch ];
                var base = CONSONANTS[ch];
        if ( next === HALANTA )         { result += base;               i += 2; }
                if (next === HALANTA) { result += base; i += 2; }
        else if ( DIACRITICS[ next ] )   { result += base + DIACRITICS[ next ]; i += 2; }
                else if (DIACRITICS[next]) { result += base + DIACRITICS[next]; i += 2; }
        else if ( next === 'ं' || next === 'ः' ) { result += base + 'a' + MISC[ next ]; i += 2; }
                else if (next === 'ं' || next === 'ः') { result += base + 'a' + MISC[next]; i += 2; }
        else                             { result += base + 'a';         i++;   }
                else { result += base + 'a'; i++; }
      } else if ( VOWELS[ ch ] )         { result += VOWELS[ ch ];       i++; }
            } else if (VOWELS[ch]) { result += VOWELS[ch]; i++; }
      else if ( DIACRITICS[ ch ] )       { result += DIACRITICS[ ch ];   i++; }
            else if (DIACRITICS[ch]) { result += DIACRITICS[ch]; i++; }
      else if ( MISC[ ch ] )             { result += MISC[ ch ];         i++; }
            else if (MISC[ch]) { result += MISC[ch]; i++; }
      else                               { result += ch;                 i++; }
            else { result += ch; i++; }
        }
        return result;
     }
     }
    return result;
  }


  var SCRIPT_MAP = {
    var SCRIPT_MAP = {
    kn: {
        kn: {
      'अ':'ಅ','आ':'ಆ','इ':'ಇ','ई':'ಈ','उ':'ಉ','ऊ':'ಊ','ऋ':'ಋ',
            'अ': 'ಅ', 'आ': 'ಆ', 'इ': 'ಇ', 'ई': 'ಈ', 'उ': 'ಉ', 'ऊ': 'ಊ', 'ऋ': 'ಋ',
      'ए':'ಏ','ऐ':'ಐ','ओ':'ಓ','औ':'ಔ','ऽ':'ಽ',
            'ए': 'ಏ', 'ऐ': 'ಐ', 'ओ': 'ಓ', 'औ': 'ಔ', 'ऽ': 'ಽ',
      'क':'ಕ','ख':'ಖ','ग':'ಗ','घ':'ಘ','ङ':'ಙ',
            'क': 'ಕ', 'ख': 'ಖ', 'ग': 'ಗ', 'घ': 'ಘ', 'ङ': 'ಙ',
      'च':'ಚ','छ':'ಛ','ज':'ಜ','झ':'ಝ','ञ':'ಞ',
            'च': 'ಚ', 'छ': 'ಛ', 'ज': 'ಜ', 'झ': 'ಝ', 'ञ': 'ಞ',
      'ट':'ಟ','ठ':'ಠ','ड':'ಡ','ढ':'ಢ','ण':'ಣ',
            'ट': 'ಟ', 'ठ': 'ಠ', 'ड': 'ಡ', 'ढ': 'ಢ', 'ण': 'ಣ',
      'त':'ತ','थ':'ಥ','द':'ದ','ध':'ಧ','न':'ನ',
            'त': 'ತ', 'थ': 'ಥ', 'द': 'ದ', 'ध': 'ಧ', 'न': 'ನ',
      'प':'ಪ','फ':'ಫ','ब':'ಬ','भ':'ಭ','म':'ಮ',
            'प': 'ಪ', 'फ': 'ಫ', 'ब': 'ಬ', 'भ': 'ಭ', 'म': 'ಮ',
      'य':'ಯ','र':'ರ','ल':'ಲ','व':'ವ',
            'य': 'ಯ', 'र': 'ರ', 'ल': 'ಲ', 'व': 'ವ',
      'श':'ಶ','ष':'ಷ','स':'ಸ','ह':'ಹ',
            'श': 'ಶ', 'ष': 'ಷ', 'स': 'ಸ', 'ह': 'ಹ',
      'ा':'ಾ','ि':'ಿ','ी':'ೀ','ु':'ು','ू':'ೂ',
            'ा': 'ಾ', 'ि': 'ಿ', 'ी': 'ೀ', 'ु': 'ು', 'ू': 'ೂ',
      'ृ':'ೃ','े':'ೇ','ै':'ೈ','ो':'ೋ','ौ':'ೌ',
            'ृ': 'ೃ', 'े': 'ೇ', 'ै': 'ೈ', 'ो': 'ೋ', 'ौ': 'ೌ',
      'ं':'ಂ','ः':'ಃ','्':'್',
            'ं': 'ಂ', 'ः': 'ಃ', '्': '್',
      '०':'೦','१':'೧','२':'೨','३':'೩','४':'೪',
            '०': '೦', '१': '೧', '२': '೨', '३': '೩', '४': '೪',
      '५':'೫','६':'೬','७':'೭','८':'೮','९':'೯'
            '५': '೫', '६': '೬', '७': '೭', '८': '೮', '९': '೯'
    },
        },
    ta: {
        ta: {
      'अ':'அ','आ':'ஆ','इ':'இ','ई':'ஈ','उ':'உ','ऊ':'ஊ',
            'अ': 'அ', 'आ': 'ஆ', 'इ': 'இ', 'ई': 'ஈ', 'उ': 'உ', 'ऊ': 'ஊ',
      'ऋ':'ரு','ॠ':'ரூ',
            'ऋ': 'ரு', 'ॠ': 'ரூ',
      'ए':'ஏ','ऐ':'ஐ','ओ':'ஓ','औ':'ஔ',
            'ए': 'ஏ', 'ऐ': 'ஐ', 'ओ': 'ஓ', 'औ': 'ஔ',
      'क':'க','ख':'க','ग':'க','घ':'க','ङ':'ங',
            'क': 'க', 'ख': 'க', 'ग': 'க', 'घ': 'க', 'ङ': 'ங',
      'च':'ச','छ':'ச','ज':'ஜ','झ':'ஜ','ञ':'ஞ',
            'च': 'ச', 'छ': 'ச', 'ज': 'ஜ', 'झ': 'ஜ', 'ञ': 'ஞ',
      'ட':'ட','ठ':'ட','ड':'ட','ढ':'ட','ண':'ண',
            'ட': 'ட', 'ठ': 'ட', 'ड': 'ட', 'ढ': 'ட', 'ண': 'ண',
      'त':'த','थ':'த','द':'த','ध':'த','न':'ந',
            'त': 'த', 'थ': 'த', 'द': 'த', 'ध': 'த', 'न': 'ந',
      'प':'ப','फ':'ப','ब':'ப','भ':'ப','म':'ம',
            'प': 'ப', 'फ': 'ப', 'ब': 'ப', 'भ': 'ப', 'म': 'ம',
      'य':'ய','र':'ர','ल':'ல','ळ':'ழ','व':'வ',
            'य': 'ய', 'र': 'ர', 'ल': 'ல', 'ळ': 'ழ', 'व': 'வ',
      'श':'ஶ','ष':'ஷ','स':'ஸ','ह':'ஹ',
            'श': 'ஶ', 'ष': 'ஷ', 'स': 'ஸ', 'ह': 'ஹ',
      'ा':'ா','ि':'ி','ी':'ீ','ु':'ு','ू':'ூ',
            'ा': 'ா', 'ि': 'ி', 'ी': 'ீ', 'ु': 'ு', 'ू': 'ூ',
      'ृ':'ு','ॄ':'ூ',
            'ृ': 'ு', 'ॄ': 'ூ',
      'े':'ே','ை':'ை','ो':'ோ','ौ':'ௌ',
            'े': 'ே', 'ை': 'ை', 'ो': 'ோ', 'ौ': 'ௌ',
      'ं':'ம்','ः':':','ँ':'ம்','्':'்','ॐ':'ௐ','ऽ':'ௗ',
            'ं': 'ம்', 'ः': ':', 'ँ': 'ம்', '्': '்', 'ॐ': 'ௐ', 'ऽ': 'ௗ',
      '०':'0','१':'1','२':'2','३':'3','४':'4',
            '०': '0', '१': '1', '२': '2', '३': '3', '४': '4',
      '५':'5','६':'6','७':'7','८':'8','९':'9'
            '५': '5', '६': '6', '७': '7', '८': '8', '९': '9'
    }
        }
  };
    };


  var PRE = [
    var PRE = [
    [ /ङ्क/g, 'ंक' ], [ /ङ्ख/g, 'ंख' ], [ /ङ्ग/g, 'ंग' ], [ /ङ्घ/g, 'ंघ' ],
        [/ङ्क/g, 'ंक'], [/ङ्ख/g, 'ंख'], [/ङ्ग/g, 'ंग'], [/ङ्घ/g, 'ंघ'],
    [ /ञ्च/g, 'ंच' ], [ /ञ्ज/g, 'ंज' ], [ /ण्ट/g, 'ंट' ], [ /ण्ड/g, 'ंड' ],
        [/ञ्च/g, 'ंच'], [/ञ्ज/g, 'ंज'], [/ण्ट/g, 'ंट'], [/ण्ड/g, 'ंड'],
    [ /न्त/g, 'ंत' ], [ /न्द/g, 'ंद' ], [ /म्ब/g, 'ंब' ], [ /म्भ/g, 'ंभ' ]
        [/न्त/g, 'ंत'], [/न्द/g, 'ंद'], [/म्ब/g, 'ंब'], [/म्भ/g, 'ंभ']
  ];
    ];


  function transliterateText( text, script ) {
    function transliterateText(text, script) {
    if ( script === 'en' ) return devanagariToIAST( text );
        if (script === 'en') return devanagariToIAST(text);
    var map = SCRIPT_MAP[ script ];
        var map = SCRIPT_MAP[script];
    if ( !map ) return text;
        if (!map) return text;
    var t = text;
        var t = text;
    PRE.forEach( function ( p ) { t = t.replace( p[ 0 ], p[ 1 ] ); } );
        PRE.forEach(function (p) { t = t.replace(p[0], p[1]); });
    return Array.from( t ).map( function ( ch ) {
        return Array.from(t).map(function (ch) {
      return map[ ch ] !== undefined ? map[ ch ] : ch;
            return map[ch] !== undefined ? map[ch] : ch;
    } ).join( '' );
        }).join('');
  }
    }


  var translatableSpans = [];
    var translatableSpans = [];


  function tagTextNodes() {
    function tagTextNodes() {
    var content = document.querySelector( '.mw-parser-output' );
        var content = document.querySelector('.mw-parser-output');
    if ( content ) {
        if (content) {
      var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT );
            var walker = document.createTreeWalker(content, NodeFilter.SHOW_TEXT);
      var nodes = [];
            var nodes = [];
      while ( walker.nextNode() ) nodes.push( walker.currentNode );
            while (walker.nextNode()) nodes.push(walker.currentNode);
      nodes.forEach( function ( node ) {
            nodes.forEach(function (node) {
        var p = node.parentNode;
                var p = node.parentNode;
        if ( !p ) return;
                if (!p) return;
        if ( p.hasAttribute && p.hasAttribute( 'data-deva' ) ) return;
                if (p.hasAttribute && p.hasAttribute('data-deva')) return;
        if ( p.closest ) {
                if (p.closest) {
          if ( p.closest( '.gr-controls' )   ) return;
                    if (p.closest('.gr-controls')) return;
          if ( p.closest( '.mw-editsection' ) ) return;
                    if (p.closest('.mw-editsection')) return;
                }
                var orig = node.textContent;
                if (!orig.trim()) return;
                var span = document.createElement('span');
                span.setAttribute('data-deva', orig);
                span.textContent = orig;
                p.replaceChild(span, node);
                translatableSpans.push(span);
            });
         }
         }
         var orig = node.textContent;
         document.querySelectorAll('.vector-toc .vector-toc-text').forEach(function (span) {
        if ( !orig.trim() ) return;
            if (span.hasAttribute('data-deva')) return;
        var span = document.createElement( 'span' );
            var orig = span.textContent;
        span.setAttribute( 'data-deva', orig );
            if (!orig.trim()) return;
        span.textContent = orig;
            span.setAttribute('data-deva', orig);
        p.replaceChild( span, node );
            translatableSpans.push(span);
        translatableSpans.push( span );
        });
      } );
     }
     }
    document.querySelectorAll( '.vector-toc .vector-toc-text' ).forEach( function ( span ) {
      if ( span.hasAttribute( 'data-deva' ) ) return;
      var orig = span.textContent;
      if ( !orig.trim() ) return;
      span.setAttribute( 'data-deva', orig );
      translatableSpans.push( span );
    } );
  }


  function applyScript( script ) {
    function applyScript(script) {
    currentScript = script;
        currentScript = script;
    translatableSpans.forEach( function ( span ) {
        translatableSpans.forEach(function (span) {
      if ( !span.parentNode ) return;
            if (!span.parentNode) return;
      var orig = span.getAttribute( 'data-deva' );
            var orig = span.getAttribute('data-deva');
      if ( !orig ) return;
            if (!orig) return;
      span.textContent = ( script === 'deva' )
            span.textContent = (script === 'deva')
        ? orig
                ? orig
        : transliterateText( orig, script );
                : transliterateText(orig, script);
    } );
        });
  }
    }


  function _isNoTocPage() {
    function _isNoTocPage() {
    var pn = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || '';
        var pn = (window.mw && mw.config && mw.config.get('wgPageName')) || '';
    return pn === 'Main_Page' || /^[A-Za-z0-9_]+:About$/.test( pn );
        return pn === 'Main_Page' || /^[A-Za-z0-9_]+:About$/.test(pn);
  }
    }


  function renameTocTitle() {
    function renameTocTitle() {
    if ( _isNoTocPage() ) return;
        if (_isNoTocPage()) return;
    var toc = document.querySelector('.vector-toc');
        var toc = document.querySelector('.vector-toc');
    if ( !toc ) return;
        if (!toc) return;
    var titleEl = toc.querySelector('.vector-toc-title') || toc.querySelector('.vector-pinnable-header-label');
        var titleEl = toc.querySelector('.vector-toc-title') || toc.querySelector('.vector-pinnable-header-label');
    if ( !titleEl ) return;
        if (!titleEl) return;
    var LABEL = 'विषयसूची';
        var LABEL = 'विषयसूची';
    var span = titleEl.querySelector('.gr-toc-title');
        var span = titleEl.querySelector('.gr-toc-title');
    if ( !span ) {
        if (!span) {
      titleEl.innerHTML = '';
            titleEl.innerHTML = '';
      span = document.createElement('span');
            span = document.createElement('span');
      span.className = 'gr-toc-title';
            span.className = 'gr-toc-title';
      span.setAttribute('data-deva', LABEL);
            span.setAttribute('data-deva', LABEL);
      titleEl.appendChild(span);
            titleEl.appendChild(span);
      translatableSpans.push(span);
            translatableSpans.push(span);
        }
        span.textContent = currentScript === 'deva' ? LABEL : transliterateText(LABEL, currentScript);
     }
     }
    span.textContent = currentScript === 'deva' ? LABEL : transliterateText(LABEL, currentScript);
  }


  function removeTocBeginning() {
    function removeTocBeginning() {
    if ( _isNoTocPage() ) return;
        if (_isNoTocPage()) return;
    var toc = document.querySelector( '.vector-toc' );
        var toc = document.querySelector('.vector-toc');
    if ( !toc ) return;
        if (!toc) return;
    var el = toc.querySelector( '#vector-toc-beginning' );
        var el = toc.querySelector('#vector-toc-beginning');
    if ( !el ) {
        if (!el) {
      var items = toc.querySelectorAll( '.vector-toc-list-item' );
            var items = toc.querySelectorAll('.vector-toc-list-item');
      for ( var i = 0; i < items.length; i++ ) {
            for (var i = 0; i < items.length; i++) {
        var a = items[ i ].querySelector( 'a' );
                var a = items[i].querySelector('a');
        if ( a ) {
                if (a) {
          var href = a.getAttribute( 'href' ) || '';
                    var href = a.getAttribute('href') || '';
          if ( href.indexOf( '#' ) === -1 ) { el = items[ i ]; break; }
                    if (href.indexOf('#') === -1) { el = items[i]; break; }
                }
            }
         }
         }
      }
        if (el && el.parentNode) el.parentNode.removeChild(el);
     }
     }
    if ( el && el.parentNode ) el.parentNode.removeChild( el );
  }


  function expandTocSections() {
    function expandTocSections() {
    if ( _isNoTocPage() ) return;
        if (_isNoTocPage()) return;
    var toc = document.querySelector( '.vector-toc' );
        var toc = document.querySelector('.vector-toc');
    if ( !toc ) return;
        if (!toc) return;
    toc.querySelectorAll( '.vector-toc-list-item-collapsed' ).forEach( function ( li ) {
        toc.querySelectorAll('.vector-toc-list-item-collapsed').forEach(function (li) {
      li.classList.remove( 'vector-toc-list-item-collapsed' );
            li.classList.remove('vector-toc-list-item-collapsed');
    } );
        });
  }
    }


  function injectTocDocNav() {
    function injectTocDocNav() {
    if ( _isNoTocPage() ) return;
        if (_isNoTocPage()) return;
    var toc = document.querySelector( '.vector-toc' );
        var toc = document.querySelector('.vector-toc');
    if ( !toc ) return;
        if (!toc) return;
    if ( document.getElementById( 'gr-toc-doc-nav' ) ) return;
        if (document.getElementById('gr-toc-doc-nav')) return;
    var artPath   = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1';
        var artPath = (window.mw && mw.config && mw.config.get('wgArticlePath')) || '/wiki/$1';
    var pageTitle = ( window.mw && mw.config && mw.config.get( 'wgPageName'   ) ) || '';
        var pageTitle = (window.mw && mw.config && mw.config.get('wgPageName')) || '';
    var teekaPage   = document.querySelector( '.gr-teeka-page' );
        var teekaPage = document.querySelector('.gr-teeka-page');
    var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || '' ) : '';
        var primarySlug = teekaPage ? (teekaPage.getAttribute('data-primary') || '') : '';
    if ( !primarySlug ) { primarySlug = pageTitle.split( '/' )[ 0 ]; }
        if (!primarySlug) { primarySlug = pageTitle.split('/')[0]; }
    if ( !primarySlug ) return;
        if (!primarySlug) return;
    function wikiUrl( slug ) {
        function wikiUrl(slug) {
      if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug );
            if (window.mw && mw.util && mw.util.getUrl) return mw.util.getUrl(slug);
      return artPath.replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) );
            return artPath.replace('$1', encodeURIComponent(slug).replace(/%2F/g, '/'));
        }
        var docTitleEl = document.querySelector('.gr-doc-title');
        var hasMoolaPage = docTitleEl && docTitleEl.getAttribute('data-has-moola') === '1';
        var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute('data-has-ullekha') === '1';
        var showMoolaPage = !teekaPage && hasMoolaPage;
        var showMoolaBack = !!teekaPage;
        var showUllekha = hasUllekhaPage || !!teekaPage;
        if (!showMoolaPage && !showMoolaBack && !showUllekha) return;
        var nav = document.createElement('div');
        nav.id = 'gr-toc-doc-nav';
        nav.setAttribute('class', 'toc-main-links');
        function makeBtn(href, label) {
            var a = document.createElement('a');
            a.href = href;
            a.setAttribute('class', 'toc-main-link-item');
            var lspan = document.createElement('span');
            lspan.setAttribute('data-deva', label);
            lspan.textContent = (currentScript && currentScript !== 'deva') ? transliterateText(label, currentScript) : label;
            translatableSpans.push(lspan);
            a.appendChild(lspan);
            a.addEventListener('mouseover', function () { this.style.opacity = '0.72'; });
            a.addEventListener('mouseout', function () { this.style.opacity = '1'; });
            return a;
        }
        if (showMoolaPage) nav.appendChild(makeBtn(wikiUrl(primarySlug + '/Moola'), 'मूलम्'));
        if (showMoolaBack) nav.appendChild(makeBtn(wikiUrl(primarySlug), 'मूल'));
        if (showUllekha) nav.appendChild(makeBtn(wikiUrl(primarySlug + '/Ullekha'), 'उल्लेख'));
        var tocContents = toc.querySelector('.vector-toc-contents');
        if (tocContents) toc.insertBefore(nav, tocContents);
        else toc.appendChild(nav);
     }
     }
     var docTitleEl     = document.querySelector( '.gr-doc-title' );
 
    var hasMoolaPage  = docTitleEl && docTitleEl.getAttribute( 'data-has-moola' )   === '1';
     var _headingObserver = null;
    var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-ullekha' ) === '1';
 
    var showMoolaPage  = !teekaPage && hasMoolaPage;
     function attachHeadingObserver() {
    var showMoolaBack  = !!teekaPage;
        if (_isNoTocPage()) return;
    var showUllekha    = hasUllekhaPage || !!teekaPage;
        if (_headingObserver) return;
    if ( !showMoolaPage && !showMoolaBack && !showUllekha ) return;
        if (!window.IntersectionObserver) return;
    var nav = document.createElement( 'div' );
        var ACTIVE_COLOR = '#f57c00';
    nav.id = 'gr-toc-doc-nav';
        var _activeId = null;
    nav.setAttribute( 'class', 'toc-main-links' );
        var content = document.querySelector('.mw-parser-output');
    function makeBtn( href, label ) {
        if (!content) return;
      var a = document.createElement( 'a' );
        var headings = Array.from(content.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]'));
      a.href = href;
        if (!headings.length) return;
      a.setAttribute( 'class', 'toc-main-link-item' );
        var toc = document.querySelector('.vector-toc');
      var lspan = document.createElement( 'span' );
        if (!toc) return;
      lspan.setAttribute( 'data-deva', label );
        function getTocLink(id) { return toc.querySelector('a[href="#' + CSS.escape(id) + '"]'); }
      lspan.textContent = ( currentScript && currentScript !== 'deva' ) ? transliterateText( label, currentScript ) : label;
        function getTocLi(id) { var a = getTocLink(id); return a ? a.closest('.vector-toc-list-item') : null; }
      translatableSpans.push( lspan );
        function clearActive() {
      a.appendChild( lspan );
            toc.querySelectorAll('.vector-toc-list-item').forEach(function (li) {
      a.addEventListener( 'mouseover', function () { this.style.opacity = '0.72'; } );
                li.classList.remove('vector-toc-list-item-active');
      a.addEventListener( 'mouseout',  function () { this.style.opacity = '1';    } );
                var lnk = li.querySelector('.vector-toc-link');
      return a;
                if (!lnk) return;
                lnk.style.removeProperty('color');
                lnk.style.setProperty('font-weight', '400', 'important');
                lnk.querySelectorAll('*').forEach(function (el) { el.style.removeProperty('color'); el.style.setProperty('font-weight', '400', 'important'); });
            });
        }
        function setActive(id) {
            if (_activeId === id) return;
            _activeId = id;
            clearActive();
            if (!id) return;
            var li = getTocLi(id);
            if (!li) return;
            li.classList.add('vector-toc-list-item-active');
            var hasActiveChild = !!li.querySelector('.vector-toc-list-item .vector-toc-list-item-active');
            if (!hasActiveChild) {
                var lnk = li.querySelector('.vector-toc-link');
                if (lnk) {
                    lnk.style.setProperty('color', ACTIVE_COLOR, 'important');
                    lnk.style.setProperty('font-weight', '700', 'important');
                    lnk.querySelectorAll('*').forEach(function (el) { el.style.setProperty('color', ACTIVE_COLOR, 'important'); el.style.setProperty('font-weight', '700', 'important'); });
                }
            }
            var anc = li.parentNode;
            while (anc && anc !== toc) {
                if (anc.classList) anc.classList.remove('vector-toc-list-item-collapsed');
                if (anc.tagName === 'UL' || anc.tagName === 'LI') anc.style.removeProperty('display');
                anc = anc.parentNode;
            }
            var sticky = document.querySelector('.vector-sticky-pinned-container');
            var scrollEl = sticky || toc;
            if (scrollEl.scrollHeight > scrollEl.clientHeight) {
                var lr = li.getBoundingClientRect();
                var cr = scrollEl.getBoundingClientRect();
                if (lr.top < cr.top + 8 || lr.bottom > cr.bottom - 8) {
                    scrollEl.scrollTop += lr.top - cr.top - scrollEl.clientHeight / 2 + li.offsetHeight / 2;
                }
            }
        }
        var _visible = new Set();
        _headingObserver = new IntersectionObserver(function (entries) {
            entries.forEach(function (entry) {
                if (entry.isIntersecting) _visible.add(entry.target.id);
                else _visible.delete(entry.target.id);
            });
            var topId = null, topY = Infinity;
            _visible.forEach(function (id) {
                var el = document.getElementById(id);
                if (el) { var y = el.getBoundingClientRect().top; if (y >= 0 && y < topY) { topY = y; topId = id; } }
            });
            if (!topId) {
                var bestY = -Infinity;
                headings.forEach(function (h) { var y = h.getBoundingClientRect().top; if (y < 0 && y > bestY) { bestY = y; topId = h.id; } });
            }
            setActive(topId || null);
        }, { rootMargin: '-60px 0px -65% 0px', threshold: 0 });
        headings.forEach(function (h) { _headingObserver.observe(h); });
     }
     }
    if ( showMoolaPage ) nav.appendChild( makeBtn( wikiUrl( primarySlug + '/Moola' ), 'मूलम्' ) );
    if ( showMoolaBack ) nav.appendChild( makeBtn( wikiUrl( primarySlug ),            'मूल'  ) );
    if ( showUllekha  ) nav.appendChild( makeBtn( wikiUrl( primarySlug + '/Ullekha'), 'उल्लेख') );
    var tocContents = toc.querySelector( '.vector-toc-contents' );
    if ( tocContents ) toc.insertBefore( nav, tocContents );
    else              toc.appendChild( nav );
  }


  var _headingObserver = null;
    function setupToc() {
        if (_isNoTocPage()) return;
        var toc = document.querySelector('.vector-toc');
        if (!toc) return;
        removeTocBeginning();
        renameTocTitle();
        expandTocSections();
        injectTocDocNav();
        attachHeadingObserver();
    }


  function attachHeadingObserver() {
    function init() {
    if ( _isNoTocPage() ) return;
        var HIDE_IDS = ['vector-appearance', 'vector-appearance-pinned-container', 'vector-appearance-unpinned-container'];
    if ( _headingObserver ) return;
        function removeHiddenEls() {
    if ( !window.IntersectionObserver ) return;
            HIDE_IDS.forEach(function (id) { var el = document.getElementById(id); if (el && el.parentNode) el.parentNode.removeChild(el); });
    var ACTIVE_COLOR = '#f57c00';
            var pt = document.getElementById('vector-page-tools') || document.querySelector('.vector-page-tools-pinned-container');
    var _activeId    = null;
            if (pt) pt.querySelectorAll('[aria-controls="vector-appearance"]').forEach(function (el) { if (el.parentNode) el.parentNode.removeChild(el); });
    var content  = document.querySelector( '.mw-parser-output' );
         }
    if ( !content ) return;
        removeHiddenEls();
    var headings = Array.from( content.querySelectorAll( 'h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]' ) );
         (function detectTeekaMode() {
    if ( !headings.length ) return;
            var tp = document.querySelector('.gr-teeka-page');
    var toc = document.querySelector( '.vector-toc' );
            if (!tp) return;
    if ( !toc ) return;
            var primary = tp.getAttribute('data-primary') || '';
    function getTocLink( id ) { return toc.querySelector( 'a[href="#' + CSS.escape( id ) + '"]' ); }
            var artPath = (window.mw && mw.config.get('wgArticlePath')) || '/wiki/$1';
    function getTocLi( id ) { var a = getTocLink( id ); return a ? a.closest( '.vector-toc-list-item' ) : null; }
            var mainUrl = artPath.replace('$1', primary);
    function clearActive() {
            var refParam = window.location.search.match(/[?&]ref=([01])/);
      toc.querySelectorAll( '.vector-toc-list-item' ).forEach( function ( li ) {
            if (refParam) { document.body.classList.add(refParam[1] === '1' ? 'gr-ref-mode' : 'gr-standalone'); return; }
         li.classList.remove( 'vector-toc-list-item-active' );
            var ref = document.referrer || '';
         var lnk = li.querySelector( '.vector-toc-link' );
            document.body.classList.add((ref && primary && ref.indexOf(mainUrl) !== -1) ? 'gr-ref-mode' : 'gr-standalone');
        if ( !lnk ) return;
        }());
        lnk.style.removeProperty( 'color' );
        if (window.MutationObserver) {
        lnk.style.setProperty( 'font-weight', '400', 'important' );
            var hideObs = new MutationObserver(function (mutations) {
        lnk.querySelectorAll( '*' ).forEach( function ( el ) { el.style.removeProperty( 'color' ); el.style.setProperty( 'font-weight', '400', 'important' ); } );
                var dirty = false;
      } );
                mutations.forEach(function (m) { if (m.addedNodes.length) dirty = true; });
    }
                if (dirty) removeHiddenEls();
    function setActive( id ) {
            });
      if ( _activeId === id ) return;
            hideObs.observe(document.body, { childList: true, subtree: false });
      _activeId = id;
            setTimeout(function () { hideObs.disconnect(); }, 6000);
      clearActive();
      if ( !id ) return;
      var li = getTocLi( id );
      if ( !li ) return;
      li.classList.add( 'vector-toc-list-item-active' );
      var hasActiveChild = !!li.querySelector( '.vector-toc-list-item .vector-toc-list-item-active' );
      if ( !hasActiveChild ) {
        var lnk = li.querySelector( '.vector-toc-link' );
        if ( lnk ) {
          lnk.style.setProperty( 'color', ACTIVE_COLOR, 'important' );
          lnk.style.setProperty( 'font-weight', '700', 'important' );
          lnk.querySelectorAll( '*' ).forEach( function ( el ) { el.style.setProperty( 'color', ACTIVE_COLOR, 'important' ); el.style.setProperty( 'font-weight', '700', 'important' ); } );
         }
         }
      }
        var content = document.querySelector('.mw-parser-output');
      var anc = li.parentNode;
        var alreadyTagged = content && content.querySelector('[data-deva]');
      while ( anc && anc !== toc ) {
         if (!alreadyTagged) { translatableSpans = []; tagTextNodes(); }
        if ( anc.classList ) anc.classList.remove( 'vector-toc-list-item-collapsed' );
         else {
         if ( anc.tagName === 'UL' || anc.tagName === 'LI' ) anc.style.removeProperty( 'display' );
            document.querySelectorAll('.vector-toc .vector-toc-text:not([data-deva])').forEach(function (span) {
         anc = anc.parentNode;
                var orig = span.textContent; if (!orig.trim()) return;
      }
                span.setAttribute('data-deva', orig); translatableSpans.push(span);
      var sticky = document.querySelector( '.vector-sticky-pinned-container' );
            });
      var scrollEl = sticky || toc;
      if ( scrollEl.scrollHeight > scrollEl.clientHeight ) {
        var lr = li.getBoundingClientRect();
        var cr = scrollEl.getBoundingClientRect();
        if ( lr.top < cr.top + 8 || lr.bottom > cr.bottom - 8 ) {
          scrollEl.scrollTop += lr.top - cr.top - scrollEl.clientHeight / 2 + li.offsetHeight / 2;
         }
         }
      }
        var saved = (function () { try { return localStorage.getItem(LS_SCRIPT_KEY); } catch (e) { return null; } }());
        if (saved && saved !== 'deva') { applyScript(saved); } else { currentScript = 'deva'; }
        setTimeout(setupToc, 200);
     }
     }
    var _visible = new Set();
    _headingObserver = new IntersectionObserver( function ( entries ) {
      entries.forEach( function ( entry ) {
        if ( entry.isIntersecting ) _visible.add( entry.target.id );
        else _visible.delete( entry.target.id );
      } );
      var topId = null, topY = Infinity;
      _visible.forEach( function ( id ) {
        var el = document.getElementById( id );
        if ( el ) { var y = el.getBoundingClientRect().top; if ( y >= 0 && y < topY ) { topY = y; topId = id; } }
      } );
      if ( !topId ) {
        var bestY = -Infinity;
        headings.forEach( function ( h ) { var y = h.getBoundingClientRect().top; if ( y < 0 && y > bestY ) { bestY = y; topId = h.id; } } );
      }
      setActive( topId || null );
    }, { rootMargin: '-60px 0px -65% 0px', threshold: 0 } );
    headings.forEach( function ( h ) { _headingObserver.observe( h ); } );
  }


  function setupToc() {
    window.addEventListener('gr-script-change', function (e) {
    if ( _isNoTocPage() ) return;
        var script = e && e.detail && e.detail.script;
    var toc = document.querySelector( '.vector-toc' );
        if (script) applyScript(script);
    if ( !toc ) return;
     });
    removeTocBeginning();
     renameTocTitle();
    expandTocSections();
    injectTocDocNav();
    attachHeadingObserver();
  }


  function init() {
    window.addEventListener('gr-new-content', function (e) {
    var HIDE_IDS = [ 'vector-appearance', 'vector-appearance-pinned-container', 'vector-appearance-unpinned-container' ];
        var container = e && e.detail && e.detail.container;
    function removeHiddenEls() {
        if (!container) return;
      HIDE_IDS.forEach( function ( id ) { var el = document.getElementById( id ); if ( el && el.parentNode ) el.parentNode.removeChild( el ); } );
        var walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
      var pt = document.getElementById( 'vector-page-tools' ) || document.querySelector( '.vector-page-tools-pinned-container' );
        var nodes = [];
      if ( pt ) pt.querySelectorAll( '[aria-controls="vector-appearance"]' ).forEach( function ( el ) { if ( el.parentNode ) el.parentNode.removeChild( el ); } );
        while (walker.nextNode()) nodes.push(walker.currentNode);
        nodes.forEach(function (node) {
            var p = node.parentNode;
            if (!p || (p.hasAttribute && p.hasAttribute('data-deva'))) return;
            var orig = node.textContent;
            if (!orig.trim()) return;
            var span = document.createElement('span');
            span.setAttribute('data-deva', orig);
            span.textContent = currentScript !== 'deva' ? transliterateText(orig, currentScript) : orig;
            p.replaceChild(span, node);
            translatableSpans.push(span);
        });
    });
 
    try {
        var _grBC = new BroadcastChannel('gr-script');
        _grBC.onmessage = function (e) {
            var script = e && e.data && e.data.script;
            if (script) { currentScript = script; var sel = document.querySelector('.gr-script-sel'); if (sel) sel.value = script; applyScript(script); }
        };
    } catch (e) { }
 
    if (window.mw) {
        mw.hook('wikipage.content').add(function () {
            setTimeout(function () {
                var content = document.querySelector('.mw-parser-output');
                var alreadyTagged = content && content.querySelector('[data-deva]');
                if (!alreadyTagged) { translatableSpans = []; tagTextNodes(); }
                else {
                    document.querySelectorAll('.vector-toc .vector-toc-text:not([data-deva])').forEach(function (span) {
                        var orig = span.textContent; if (!orig.trim()) return;
                        span.setAttribute('data-deva', orig); translatableSpans.push(span);
                    });
                }
                if (currentScript !== 'deva') applyScript(currentScript);
                setupToc();
            }, 150);
        });
     }
     }
     removeHiddenEls();
 
     ( function detectTeekaMode() {
     if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); }
      var tp = document.querySelector( '.gr-teeka-page' );
     else { init(); }
      if ( !tp ) return;
 
      var primary = tp.getAttribute( 'data-primary' ) || '';
}());  /* ← end of main IIFE */
      var artPath = ( window.mw && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1';
 
      var mainUrl = artPath.replace( '$1', primary );
 
      var refParam = window.location.search.match( /[?&]ref=([01])/ );
// ── Inject "Help" and "About" links into the header ─────────────────
      if ( refParam ) { document.body.classList.add( refParam[1] === '1' ? 'gr-ref-mode' : 'gr-standalone' ); return; }
(function () {
      var ref = document.referrer || '';
    function wikiHref(title) {
      document.body.classList.add( ( ref && primary && ref.indexOf( mainUrl ) !== -1 ) ? 'gr-ref-mode' : 'gr-standalone' );
        if (window.mw && mw.util && mw.util.getUrl) return mw.util.getUrl(title);
    }() );
        var ap = (window.mw && mw.config && mw.config.get('wgArticlePath')) || '/wiki/$1';
    if ( window.MutationObserver ) {
        return ap.replace('$1', title);
      var hideObs = new MutationObserver( function ( mutations ) {
        var dirty = false;
        mutations.forEach( function ( m ) { if ( m.addedNodes.length ) dirty = true; } );
        if ( dirty ) removeHiddenEls();
      } );
      hideObs.observe( document.body, { childList: true, subtree: false } );
      setTimeout( function () { hideObs.disconnect(); }, 6000 );
     }
     }
     var content = document.querySelector( '.mw-parser-output' );
     var linkStyle = ['color:rgba(255,255,255,0.88)', 'font-size:0.88em', 'font-family:system-ui,sans-serif', 'font-weight:500', 'text-decoration:none', 'padding:4px 10px', 'border-radius:4px', 'margin-right:4px', 'transition:color 0.15s,background 0.15s', 'white-space:nowrap'].join(';');
    var alreadyTagged = content && content.querySelector( '[data-deva]' );
     function makeHeaderLink(id, href, label) {
     if ( !alreadyTagged ) { translatableSpans = []; tagTextNodes(); }
        var a = document.createElement('a');
    else {
        a.id = id; a.href = href; a.textContent = label; a.style.cssText = linkStyle;
      document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) {
        a.addEventListener('mouseover', function () { this.style.color = '#fff'; this.style.background = 'rgba(255,255,255,0.12)'; });
        var orig = span.textContent; if ( !orig.trim() ) return;
         a.addEventListener('mouseout', function () { this.style.color = 'rgba(255,255,255,0.88)'; this.style.background = 'transparent'; });
         span.setAttribute( 'data-deva', orig ); translatableSpans.push( span );
        return a;
      } );
     }
     }
     var saved = ( function () { try { return localStorage.getItem( LS_SCRIPT_KEY ); } catch ( e ) { return null; } }() );
     function injectHeaderLinks() {
    if ( saved && saved !== 'deva' ) { applyScript( saved ); } else { currentScript = 'deva'; }
        if (document.getElementById('gr-about-link')) return;
    setTimeout( setupToc, 200 );
        var headerEnd = document.querySelector('.vector-header-end') || document.querySelector('#vector-user-links') || document.querySelector('.mw-header');
  }
        if (!headerEnd) return;
        var helpLink = makeHeaderLink('gr-help-link', wikiHref('My_wiki:Help'), 'Help');
        var aboutLink = makeHeaderLink('gr-about-link', wikiHref('My_wiki:About'), 'About');
 
        var userName = window.mw ? mw.config.get('wgUserName') : null;
        var isAnon = !userName || (window.mw && mw.config.get('wgUserId') === null);
 
        // Build the trailing auth element (Login link for anon, dropdown for logged-in)
        var authEl = null;
        if (isAnon) {
            if (!document.getElementById('gr-header-login')) {
                authEl = makeHeaderLink('gr-header-login', wikiHref('Special:UserLogin'), 'Login');
            }
        } else if (!document.getElementById('gr-header-user')) {
            authEl = buildHeaderUserDropdown(userName);
        }


  window.addEventListener( 'gr-script-change', function ( e ) {
        var ul = document.querySelector('.vector-user-links') || document.querySelector('#pt-userpage');
    var script = e && e.detail && e.detail.script;
        if (ul && ul.parentNode === headerEnd) {
    if ( script ) applyScript( script );
            if (authEl) headerEnd.insertBefore(authEl, ul);
  } );
            headerEnd.insertBefore(aboutLink, authEl || ul);
            headerEnd.insertBefore(helpLink, aboutLink);
        } else {
            headerEnd.appendChild(helpLink);
            headerEnd.appendChild(aboutLink);
            if (authEl) headerEnd.appendChild(authEl);
        }
    }


  window.addEventListener( 'gr-new-content', function ( e ) {
     function buildHeaderUserDropdown(userName) {
     var container = e && e.detail && e.detail.container;
        var wrap = document.createElement('div');
    if ( !container ) return;
        wrap.id = 'gr-header-user';
    var walker = document.createTreeWalker( container, NodeFilter.SHOW_TEXT );
        wrap.style.cssText = 'position:relative;display:inline-block;margin-right:4px;';
    var nodes = [];
    while ( walker.nextNode() ) nodes.push( walker.currentNode );
    nodes.forEach( function ( node ) {
      var p = node.parentNode;
      if ( !p || ( p.hasAttribute && p.hasAttribute( 'data-deva' ) ) ) return;
      var orig = node.textContent;
      if ( !orig.trim() ) return;
      var span = document.createElement( 'span' );
      span.setAttribute( 'data-deva', orig );
      span.textContent = currentScript !== 'deva' ? transliterateText( orig, currentScript ) : orig;
      p.replaceChild( span, node );
      translatableSpans.push( span );
    } );
  } );


  try {
        var trigger = document.createElement('button');
    var _grBC = new BroadcastChannel( 'gr-script' );
        trigger.id = 'gr-header-user-trigger';
    _grBC.onmessage = function ( e ) {
        trigger.type = 'button';
      var script = e && e.data && e.data.script;
        trigger.setAttribute('aria-haspopup', 'true');
      if ( script ) { currentScript = script; var sel = document.querySelector( '.gr-script-sel' ); if ( sel ) sel.value = script; applyScript( script ); }
        trigger.setAttribute('aria-expanded', 'false');
    };
        trigger.style.cssText = [
  } catch ( e ) {}
            'display:inline-flex', 'align-items:center', 'gap:5px',
            'color:rgba(255,255,255,0.88)', 'font-size:0.88em',
            'font-family:system-ui,sans-serif', 'font-weight:500',
            'background:transparent', 'border:none', 'cursor:pointer',
            'padding:4px 10px', 'border-radius:4px', 'white-space:nowrap',
            'transition:color 0.15s,background 0.15s'
        ].join(';');
        trigger.innerHTML =
            '<span>' + userName.replace(/</g, '&lt;') + '</span>' +
            '<span id="gr-header-caret" style="font-size:0.8em;transition:transform 0.2s;">\u25be</span>';
        trigger.addEventListener('mouseover', function () { this.style.color = '#fff'; this.style.background = 'rgba(255,255,255,0.12)'; });
        trigger.addEventListener('mouseout', function () { if (menu.style.display === 'none') { this.style.color = 'rgba(255,255,255,0.88)'; this.style.background = 'transparent'; } });
 
        var menu = document.createElement('div');
        menu.id = 'gr-header-user-menu';
        menu.setAttribute('role', 'menu');
        menu.style.cssText = [
            'display:none', 'position:absolute', 'top:100%', 'right:0', 'margin-top:4px',
            'min-width:150px', 'background:#fff', 'border-radius:6px',
            'box-shadow:0 4px 16px rgba(0,0,0,0.18)', 'overflow:hidden', 'z-index:1000'
        ].join(';');


  if ( window.mw ) {
        var itemStyle = 'display:block;padding:10px 16px;font-size:0.9em;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;background:#fff;';
    mw.hook( 'wikipage.content' ).add( function () {
        function makeMenuItem(href, label, id) {
      setTimeout( function () {
            var a = document.createElement('a');
        var content = document.querySelector( '.mw-parser-output' );
            a.href = href; a.setAttribute('role', 'menuitem');
        var alreadyTagged = content && content.querySelector( '[data-deva]' );
            a.textContent = label; a.style.cssText = itemStyle;
        if ( !alreadyTagged ) { translatableSpans = []; tagTextNodes(); }
            if (id) a.id = id;
        else {
            a.addEventListener('mouseover', function () { this.style.background = '#f5efe9'; });
          document.querySelectorAll( '.vector-toc .vector-toc-text:not([data-deva])' ).forEach( function ( span ) {
             a.addEventListener('mouseout', function () { this.style.background = '#fff'; });
            var orig = span.textContent; if ( !orig.trim() ) return;
            return a;
             span.setAttribute( 'data-deva', orig ); translatableSpans.push( span );
          } );
         }
         }
        if ( currentScript !== 'deva' ) applyScript( currentScript );
        setupToc();
      }, 150 );
    } );
  }


  if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', init ); }
        menu.appendChild(makeMenuItem(wikiHref('Special:Profile'), 'Profile'));
  else { init(); }
        menu.appendChild(makeMenuItem('#', 'Log out', 'gr-header-logout'));
 
        function setOpen(open) {
            menu.style.display = open ? 'block' : 'none';
            trigger.setAttribute('aria-expanded', open ? 'true' : 'false');
            var caret = document.getElementById('gr-header-caret');
            if (caret) caret.style.transform = open ? 'rotate(180deg)' : '';
            if (open) { trigger.style.color = '#fff'; trigger.style.background = 'rgba(255,255,255,0.12)'; }
            else { trigger.style.color = 'rgba(255,255,255,0.88)'; trigger.style.background = 'transparent'; }
        }


}() );   /* ← end of main IIFE */
        trigger.addEventListener('click', function (e) {
            e.stopPropagation();
            setOpen(menu.style.display === 'none');
        });
        document.addEventListener('click', function (e) {
            if (!wrap.contains(e.target)) setOpen(false);
        });


        // Logout: POST with CSRF token (same approach as the desktop dropdown)
        menu.querySelector('#gr-header-logout').addEventListener('click', function (e) {
            e.preventDefault();
            if (window.mw && mw.user && mw.user.tokens) {
                var t = mw.user.tokens.get('csrfToken');
                if (t) {
                    var script = (mw.util && mw.util.wikiScript) ? mw.util.wikiScript() : '/index.php';
                    var form = document.createElement('form');
                    form.method = 'post';
                    form.action = script + '?title=Special:UserLogout';
                    form.style.display = 'none';
                    form.innerHTML =
                        '<input type="hidden" name="wpEditToken" value="' + String(t).replace(/"/g, '&quot;') + '">' +
                        '<input type="hidden" name="title" value="Special:UserLogout">' +
                        '<input type="hidden" name="returnto" value="Main Page">';
                    document.body.appendChild(form);
                    form.submit();
                    return;
                }
            }
            if (window.mw && mw.Api) {
                new mw.Api().postWithToken('csrf', { action: 'logout' })
                    .done(function () { location.href = '/Main_Page'; })
                    .fail(function () { location.href = '/index.php?title=Special:UserLogout'; });
            } else {
                location.href = '/index.php?title=Special:UserLogout';
            }
        });


// ── Inject "Help" and "About" links into the header ─────────────────
        wrap.appendChild(trigger);
( function () {
        wrap.appendChild(menu);
  function wikiHref( title ) {
        return wrap;
    if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( title );
     }
    var ap = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1';
     if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', injectHeaderLinks);
    return ap.replace( '$1', title );
    else injectHeaderLinks();
  }
}());
  var linkStyle = [ 'color:rgba(255,255,255,0.88)','font-size:0.88em','font-family:system-ui,sans-serif','font-weight:500','text-decoration:none','padding:4px 10px','border-radius:4px','margin-right:4px','transition:color 0.15s,background 0.15s','white-space:nowrap' ].join( ';' );
  function makeHeaderLink( id, href, label ) {
    var a = document.createElement( 'a' );
    a.id = id; a.href = href; a.textContent = label; a.style.cssText = linkStyle;
    a.addEventListener( 'mouseover', function () { this.style.color = '#fff'; this.style.background = 'rgba(255,255,255,0.12)'; } );
    a.addEventListener( 'mouseout',  function () { this.style.color = 'rgba(255,255,255,0.88)'; this.style.background = 'transparent'; } );
    return a;
  }
  function injectHeaderLinks() {
    if ( document.getElementById( 'gr-about-link' ) ) return;
    var headerEnd = document.querySelector( '.vector-header-end' ) || document.querySelector( '#vector-user-links' ) || document.querySelector( '.mw-header' );
    if ( !headerEnd ) return;
    var helpLink  = makeHeaderLink( 'gr-help-link',  wikiHref( 'My_wiki:Help'  ), 'Help'  );
    var aboutLink = makeHeaderLink( 'gr-about-link', wikiHref( 'My_wiki:About' ), 'About' );
     var ul = document.querySelector( '.vector-user-links' ) || document.querySelector( '#pt-userpage' );
    if ( ul && ul.parentNode === headerEnd ) { headerEnd.insertBefore( aboutLink, ul ); headerEnd.insertBefore( helpLink, aboutLink ); }
     else { headerEnd.appendChild( helpLink ); headerEnd.appendChild( aboutLink ); }
  }
  if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', injectHeaderLinks );
  else injectHeaderLinks();
}() );




// ── Main page: by-Grantha / by-Author toggle ──────────────────────
// ── Main page: by-Grantha / by-Author toggle ──────────────────────
( function () {
(function () {
  function grHomeView( v ) {
    function grHomeView(v) {
    var gView = document.getElementById( 'gr-view-grantha' );
        var gView = document.getElementById('gr-view-grantha');
    var aView = document.getElementById( 'gr-view-author' );
        var aView = document.getElementById('gr-view-author');
    var gBtn = document.getElementById( 'gr-toggle-grantha' );
        var gBtn = document.getElementById('gr-toggle-grantha');
    var aBtn = document.getElementById( 'gr-toggle-author' );
        var aBtn = document.getElementById('gr-toggle-author');
    if ( !gView || !aView || !gBtn || !aBtn ) return;
        if (!gView || !aView || !gBtn || !aBtn) return;
    gView.style.display = ( v === 'grantha' ) ? '' : 'none';
        gView.style.display = (v === 'grantha') ? '' : 'none';
    aView.style.display = ( v === 'author' ) ? '' : 'none';
        aView.style.display = (v === 'author') ? '' : 'none';
    gBtn.className = 'gr-toggle-btn' + ( v === 'grantha' ? ' gr-toggle-active' : '' );
        gBtn.className = 'gr-toggle-btn' + (v === 'grantha' ? ' gr-toggle-active' : '');
    aBtn.className = 'gr-toggle-btn' + ( v === 'author' ? ' gr-toggle-active' : '' );
        aBtn.className = 'gr-toggle-btn' + (v === 'author' ? ' gr-toggle-active' : '');
    try { localStorage.setItem( 'gr_home_view', v ); } catch ( e ) {}
        try { localStorage.setItem('gr_home_view', v); } catch (e) { }
  }
    }
  function initHomeToggle() {
    function initHomeToggle() {
    var gBtn = document.getElementById( 'gr-toggle-grantha' );
        var gBtn = document.getElementById('gr-toggle-grantha');
    var aBtn = document.getElementById( 'gr-toggle-author' );
        var aBtn = document.getElementById('gr-toggle-author');
    if ( !gBtn || !aBtn ) return;
        if (!gBtn || !aBtn) return;
    gBtn.addEventListener( 'click', function () { grHomeView( 'grantha' ); } );
        gBtn.addEventListener('click', function () { grHomeView('grantha'); });
    aBtn.addEventListener( 'click', function () { grHomeView( 'author' ); } );
        aBtn.addEventListener('click', function () { grHomeView('author'); });
    [ gBtn, aBtn ].forEach( function ( btn ) { btn.addEventListener( 'keydown', function ( e ) { if ( e.key === 'Enter' || e.key === ' ' ) btn.click(); } ); } );
        [gBtn, aBtn].forEach(function (btn) { btn.addEventListener('keydown', function (e) { if (e.key === 'Enter' || e.key === ' ') btn.click(); }); });
    var saved; try { saved = localStorage.getItem( 'gr_home_view' ); } catch ( e ) {}
        var saved; try { saved = localStorage.getItem('gr_home_view'); } catch (e) { }
    if ( saved === 'author' ) grHomeView( 'author' );
        if (saved === 'author') grHomeView('author');
  }
    }
  if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', initHomeToggle );
    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initHomeToggle);
  else initHomeToggle();
    else initHomeToggle();
}() );
}());




// ── Ullekha reference link handler ─────────────────────────────────
// ── Ullekha reference link handler ─────────────────────────────────
( function () {
(function () {
  function highlightOnArrival() {
    function highlightOnArrival() {
    var search = window.location.search;
        var search = window.location.search;
    if ( !search ) return;
        if (!search) return;
    var m = search.match( /[?&]hlUllekha=([^&]+)/ );
        var m = search.match(/[?&]hlUllekha=([^&]+)/);
    if ( !m ) return;
        if (!m) return;
    var needle;
        var needle;
    try { needle = decodeURIComponent( m[ 1 ] ); } catch ( e ) { return; }
        try { needle = decodeURIComponent(m[1]); } catch (e) { return; }
    if ( !needle || needle.length < 4 ) return;
        if (!needle || needle.length < 4) return;
    function doHighlight() {
        function doHighlight() {
      var content = document.querySelector( '.mw-parser-output' );
            var content = document.querySelector('.mw-parser-output');
      if ( !content ) return;
            if (!content) return;
      var snippet = needle.slice( 0, 40 );
            var snippet = needle.slice(0, 40);
      var found   = false;
            var found = false;
      var spans = content.querySelectorAll( '[data-deva]' );
            var spans = content.querySelectorAll('[data-deva]');
      for ( var i = 0; i < spans.length && !found; i++ ) {
            for (var i = 0; i < spans.length && !found; i++) {
        var spanEl = spans[ i ];
                var spanEl = spans[i];
        var orig   = spanEl.getAttribute( 'data-deva' ) || '';
                var orig = spanEl.getAttribute('data-deva') || '';
        if ( orig.indexOf( snippet ) === -1 ) continue;
                if (orig.indexOf(snippet) === -1) continue;
        var idx   = orig.indexOf( snippet );
                var idx = orig.indexOf(snippet);
        var hlText = orig.slice( idx, Math.min( idx + needle.length, orig.length ) );
                var hlText = orig.slice(idx, Math.min(idx + needle.length, orig.length));
        var mark   = document.createElement( 'mark' );
                var mark = document.createElement('mark');
        mark.className = 'gr-ullekha-highlight';
                mark.className = 'gr-ullekha-highlight';
        mark.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;';
                mark.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;';
        mark.textContent = hlText;
                mark.textContent = hlText;
        var parent = spanEl.parentNode;
                var parent = spanEl.parentNode;
        if ( !parent ) continue;
                if (!parent) continue;
        var before = document.createTextNode( orig.slice( 0, idx ) );
                var before = document.createTextNode(orig.slice(0, idx));
        var after = document.createTextNode( orig.slice( idx + hlText.length ) );
                var after = document.createTextNode(orig.slice(idx + hlText.length));
        parent.insertBefore( before, spanEl ); parent.insertBefore( mark, spanEl ); parent.insertBefore( after, spanEl ); parent.removeChild( spanEl );
                parent.insertBefore(before, spanEl); parent.insertBefore(mark, spanEl); parent.insertBefore(after, spanEl); parent.removeChild(spanEl);
        setTimeout( function () { mark.scrollIntoView( { behavior: 'smooth', block: 'center' } ); }, 100 );
                setTimeout(function () { mark.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 100);
        found = true;
                found = true;
      }
            }
      if ( !found ) {
            if (!found) {
        var walker = document.createTreeWalker( content, NodeFilter.SHOW_TEXT );
                var walker = document.createTreeWalker(content, NodeFilter.SHOW_TEXT);
        while ( walker.nextNode() && !found ) {
                while (walker.nextNode() && !found) {
          var node = walker.currentNode;
                    var node = walker.currentNode;
          var txt = node.textContent || '';
                    var txt = node.textContent || '';
          if ( txt.indexOf( snippet ) === -1 ) continue;
                    if (txt.indexOf(snippet) === -1) continue;
          var idx2 = txt.indexOf( snippet );
                    var idx2 = txt.indexOf(snippet);
          var mark2 = document.createElement( 'mark' );
                    var mark2 = document.createElement('mark');
          mark2.className = 'gr-ullekha-highlight';
                    mark2.className = 'gr-ullekha-highlight';
          mark2.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;';
                    mark2.style.cssText = 'background:#fff176;border-radius:2px;padding:0 2px;';
          mark2.textContent = txt.slice( idx2, Math.min( idx2 + needle.length, txt.length ) );
                    mark2.textContent = txt.slice(idx2, Math.min(idx2 + needle.length, txt.length));
          var p = node.parentNode;
                    var p = node.parentNode;
          p.insertBefore( document.createTextNode( txt.slice( 0, idx2 ) ), node );
                    p.insertBefore(document.createTextNode(txt.slice(0, idx2)), node);
          p.insertBefore( mark2, node );
                    p.insertBefore(mark2, node);
          p.insertBefore( document.createTextNode( txt.slice( idx2 + mark2.textContent.length ) ), node );
                    p.insertBefore(document.createTextNode(txt.slice(idx2 + mark2.textContent.length)), node);
          p.removeChild( node );
                    p.removeChild(node);
          setTimeout( function () { mark2.scrollIntoView( { behavior: 'smooth', block: 'center' } ); }, 100 );
                    setTimeout(function () { mark2.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 100);
          found = true;
                    found = true;
                }
            }
         }
         }
      }
        doHighlight();
     }
     }
     doHighlight();
     function wireUllekhaLinks() {
  }
        document.querySelectorAll('.gr-ullekha-ref-link').forEach(function (wrap) {
  function wireUllekhaLinks() {
            var anchor = wrap.getAttribute('data-anchor') || '';
    document.querySelectorAll( '.gr-ullekha-ref-link' ).forEach( function ( wrap ) {
            var hl = wrap.getAttribute('data-hl') || '';
      var anchor = wrap.getAttribute( 'data-anchor' ) || '';
            var a = wrap.querySelector('a');
      var hl     = wrap.getAttribute( 'data-hl' )     || '';
            if (!a) return;
      var a = wrap.querySelector( 'a' );
            var base = a.href.split('#')[0];
      if ( !a ) return;
            var encoded = encodeURIComponent(hl);
      var base = a.href.split( '#' )[ 0 ];
            a.href = base + (hl ? '?hlUllekha=' + encoded : '') + (anchor ? '#' + anchor : '');
      var encoded = encodeURIComponent( hl );
        });
      a.href = base + ( hl ? '?hlUllekha=' + encoded : '' ) + ( anchor ? '#' + anchor : '' );
    }
    } );
    if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { highlightOnArrival(); wireUllekhaLinks(); }); }
  }
    else { highlightOnArrival(); wireUllekhaLinks(); }
  if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', function () { highlightOnArrival(); wireUllekhaLinks(); } ); }
}());
  else { highlightOnArrival(); wireUllekhaLinks(); }
}() );


/* ── Search result highlight ──────────────────────────────────── */
/* ── Search result highlight ──────────────────────────────────── */
Line 574: Line 693:
  * identical to the version that was working.
  * identical to the version that was working.
  */
  */
( function () {
(function () {
 
    function storeQueryForLink(url, query) {
        try {
            var a = document.createElement('a');
            a.href = url;
            sessionStorage.setItem('gr_search_hl', JSON.stringify({
                query: query,
                pathname: a.pathname
            }));
        } catch (e) { }
    }
 
    function applyHighlight() {
        var stored;
        try {
            stored = JSON.parse(sessionStorage.getItem('gr_search_hl') || 'null');
        } catch (e) { return; }
        if (!stored || !stored.query) return;
 
        var currentPath = window.location.pathname;
        var storedPath = stored.pathname || '';


  function storeQueryForLink( url, query ) {
        function normPath(p) { return decodeURIComponent(p).replace(/\/+$/, ''); }
    try {
        if (storedPath && normPath(storedPath) !== normPath(currentPath)) {
      var a = document.createElement( 'a' );
            try { sessionStorage.removeItem('gr_search_hl'); } catch (e) { }
      a.href = url;
            return;
      sessionStorage.setItem( 'gr_search_hl', JSON.stringify({
        }
        query:    query,
        pathname: a.pathname
      }) );
    } catch(e) {}
  }


  function applyHighlight() {
        var query = stored.query.trim();
    var stored;
        if (!query) return;
    try {
      stored = JSON.parse( sessionStorage.getItem( 'gr_search_hl' ) || 'null' );
    } catch(e) { return; }
    if ( !stored || !stored.query ) return;


    var currentPath = window.location.pathname;
        try { sessionStorage.removeItem('gr_search_hl'); } catch (e) { }
    var storedPath  = stored.pathname || '';


    function normPath(p) { return decodeURIComponent(p).replace(/\/+$/, ''); }
        var delays = [0, 200, 600];
    if ( storedPath && normPath(storedPath) !== normPath(currentPath) ) {
        delays.forEach(function (ms) {
      try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}
            setTimeout(function () {
      return;
                if (document.querySelector('.gr-search-hl')) return;
                highlightText(query);
            }, ms);
        });
     }
     }


     var query = stored.query.trim();
     function highlightText(query) {
    if ( !query ) return;
        var content = document.querySelector('#mw-content-text .mw-parser-output');
        if (!content) return;


    try { sessionStorage.removeItem( 'gr_search_hl' ); } catch(e) {}
        var raw = query.replace(/^"|"$/g, '').trim();
        if (!raw) return;


    var delays = [ 0, 200, 600 ];
        var patterns = [];
    delays.forEach( function(ms) {
        patterns.push(escapeRegex(raw));
      setTimeout( function() {
        raw.split(/\s+/).forEach(function (w) {
        if ( document.querySelector( '.gr-search-hl' ) ) return;
            if (w.length >= 2) patterns.push(escapeRegex(w));
         highlightText( query );
         });
      }, ms );
    } );
  }


  function highlightText( query ) {
        var matched = false;
    var content = document.querySelector( '#mw-content-text .mw-parser-output' );
        for (var pi = 0; pi < patterns.length; pi++) {
    if ( !content ) return;
            var re;
            try { re = new RegExp('(' + patterns[pi] + ')', 'gi'); }
            catch (e) { continue; }
            var count = wrapMatches(content, re);
            if (count > 0) { matched = true; break; }
        }


    var raw = query.replace( /^"|"$/g, '' ).trim();
        if (!matched) return;
    if ( !raw ) return;


    var patterns = [];
        var first = document.querySelector('.gr-search-hl');
    patterns.push( escapeRegex( raw ) );
        if (first) {
    raw.split( /\s+/ ).forEach( function(w) {
            first.scrollIntoView({ behavior: 'smooth', block: 'center' });
      if ( w.length >= 2 ) patterns.push( escapeRegex( w ) );
            first.classList.add('gr-search-hl-pulse');
    } );
            setTimeout(function () { first.classList.remove('gr-search-hl-pulse'); }, 2000);
        }


    var matched = false;
        showDismissBar(query);
    for ( var pi = 0; pi < patterns.length; pi++ ) {
      var re;
      try { re = new RegExp( '(' + patterns[pi] + ')', 'gi' ); }
      catch(e) { continue; }
      var count = wrapMatches( content, re );
      if ( count > 0 ) { matched = true; break; }
     }
     }


     if ( !matched ) return;
     function escapeRegex(s) {
 
        return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    var first = document.querySelector( '.gr-search-hl' );
    if ( first ) {
      first.scrollIntoView({ behavior: 'smooth', block: 'center' });
      first.classList.add( 'gr-search-hl-pulse' );
      setTimeout( function() { first.classList.remove( 'gr-search-hl-pulse' ); }, 2000 );
     }
     }


     showDismissBar( query );
     function wrapMatches(root, re) {
  }
        var count = 0;
        var walker = document.createTreeWalker(
            root, NodeFilter.SHOW_TEXT, {
            acceptNode: function (node) {
                var p = node.parentElement;
                if (!p) return NodeFilter.FILTER_REJECT;
                var tag = p.tagName.toUpperCase();
                if (tag === 'SCRIPT' || tag === 'STYLE' || tag === 'NOSCRIPT') return NodeFilter.FILTER_REJECT;
                if (p.classList.contains('gr-search-hl')) return NodeFilter.FILTER_REJECT;
                return NodeFilter.FILTER_ACCEPT;
            }
        }, false
        );


  function escapeRegex( s ) {
        var nodes = [];
    return s.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
        var node;
  }
        while ((node = walker.nextNode())) nodes.push(node);


  function wrapMatches( root, re ) {
        nodes.forEach(function (textNode) {
    var count = 0;
            var val = textNode.nodeValue;
    var walker = document.createTreeWalker(
            if (!re.test(val)) return;
      root, NodeFilter.SHOW_TEXT, {
            re.lastIndex = 0;
        acceptNode: function( node ) {
          var p = node.parentElement;
          if ( !p ) return NodeFilter.FILTER_REJECT;
          var tag = p.tagName.toUpperCase();
          if ( tag === 'SCRIPT' || tag === 'STYLE' || tag === 'NOSCRIPT' ) return NodeFilter.FILTER_REJECT;
          if ( p.classList.contains( 'gr-search-hl' ) ) return NodeFilter.FILTER_REJECT;
          return NodeFilter.FILTER_ACCEPT;
        }
      }, false
    );


    var nodes = [];
            var frag = document.createDocumentFragment();
    var node;
            var last = 0;
    while ( ( node = walker.nextNode() ) ) nodes.push( node );
            var m;
            while ((m = re.exec(val)) !== null) {
                if (m.index > last) {
                    frag.appendChild(document.createTextNode(val.slice(last, m.index)));
                }
                var span = document.createElement('span');
                span.className = 'gr-search-hl';
                span.textContent = m[0];
                frag.appendChild(span);
                last = m.index + m[0].length;
                count++;
            }
            if (last < val.length) {
                frag.appendChild(document.createTextNode(val.slice(last)));
            }
            textNode.parentNode.replaceChild(frag, textNode);
        });


    nodes.forEach( function( textNode ) {
        return count;
      var val = textNode.nodeValue;
     }
      if ( !re.test( val ) ) return;
      re.lastIndex = 0;
 
      var frag = document.createDocumentFragment();
      var last = 0;
      var m;
      while ( ( m = re.exec( val ) ) !== null ) {
        if ( m.index > last ) {
          frag.appendChild( document.createTextNode( val.slice( last, m.index ) ) );
        }
        var span = document.createElement( 'span' );
        span.className = 'gr-search-hl';
        span.textContent = m[0];
        frag.appendChild( span );
        last = m.index + m[0].length;
        count++;
      }
      if ( last < val.length ) {
        frag.appendChild( document.createTextNode( val.slice( last ) ) );
      }
      textNode.parentNode.replaceChild( frag, textNode );
     } );


     return count;
     function showDismissBar(query) {
  }
        var existing = document.getElementById('gr-hl-bar');
        if (existing) existing.remove();


  function showDismissBar( query ) {
        var count = document.querySelectorAll('.gr-search-hl').length;
    var existing = document.getElementById( 'gr-hl-bar' );
        if (!count) return;
    if ( existing ) existing.remove();


    var count = document.querySelectorAll( '.gr-search-hl' ).length;
        var isMob = window.innerWidth < 768 || !!document.getElementById('mw-mf-viewport');
    if ( !count ) return;
        var bar = document.createElement('div');
        bar.id = 'gr-hl-bar';


    var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' );
        if (isMob) {
    var bar = document.createElement( 'div' );
            bar.className = 'gr-search-hl-mobile';
    bar.id = 'gr-hl-bar';


    if ( isMob ) {
            bar.innerHTML =
      bar.style.cssText = [
                '<button id="gr-hl-results" class="gr-search-bar-btn">' +
        'position:fixed', 'bottom:0', 'left:0', 'right:0',
                '<span class="gra-icon gra-icon-search" aria-hidden="true"></span>' +
        'z-index:10200', 'background:#b5451b', 'color:#fff',
                '<span>' + count + ' match' + (count === 1 ? '' : 'es') + '</span></button>' +
        'padding:0', 'display:flex', 'align-items:stretch',
                '<button id="gr-hl-prev" class="gr-search-bar-btn">' +
        'font-family:system-ui,sans-serif',
                '<span class="gra-icon gra-icon-prev" aria-hidden="true"></span>' +
        'box-shadow:0 -2px 12px rgba(0,0,0,0.25)', 'height:56px'
                '<span>Prev</span></button>' +
      ].join(';');
                '<button id="gr-hl-next" class="gr-search-bar-btn">' +
                '<span class="gra-icon gra-icon-next" aria-hidden="true"></span>' +
                '<span>Next</span></button>' +
                '<button id="gr-hl-dismiss" class="gr-search-bar-btn">' +
                '<span class="gra-icon gra-icon-dismiss" aria-hidden="true"></span>' +
                '<span>Close</span></button>';
        } else {
            bar.style.cssText = [
                'position:fixed', 'bottom:0', 'left:0', 'right:0', 'z-index:10200',
                'background:#b5451b', 'color:#fff', 'padding:10px 16px',
                'display:flex', 'align-items:center', 'justify-content:space-between',
                'font-family:system-ui,sans-serif', 'font-size:14px',
                'box-shadow:0 -2px 8px rgba(0,0,0,0.2)'
            ].join(';');


      var mbs = 'flex:1;display:flex;flex-direction:column;align-items:center;' +
            var nav = document.createElement('div');
        'justify-content:center;background:none;border:none;color:#fff;cursor:pointer;' +
            nav.style.cssText = 'display:flex;align-items:center;gap:12px;';
        'padding:6px 4px;font-family:system-ui,sans-serif;font-size:11px;font-weight:500;' +
            nav.innerHTML =
        'gap:3px;-webkit-tap-highlight-color:rgba(0,0,0,0.12);';
                '<span>🔍 <strong>' + escHtml(query) + '</strong> — ' + count + ' match' + (count === 1 ? '' : 'es') + '</span>' +
                '<button id="gr-hl-prev" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">↑ Prev</button>' +
                '<button id="gr-hl-next" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">↓ Next</button>' +
                '<button id="gr-hl-results" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">← Results</button>';
            bar.appendChild(nav);


      bar.innerHTML =
            var db = document.createElement('button');
        '<button id="gr-hl-prev" style="' + mbs + '">' +
            db.id = 'gr-hl-dismiss'; db.textContent = '✕ Close';
          '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>' +
            db.style.cssText = 'background:rgba(255,255,255,0.15);border:none;color:#fff;padding:4px 12px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;';
          '<span>Prev</span></button>' +
            bar.appendChild(db);
        '<button id="gr-hl-next" style="' + mbs + '">' +
        }
          '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>' +
          '<span>Next</span></button>' +
        '<button id="gr-hl-results" style="' + mbs + 'flex:1.6;border-left:1px solid rgba(255,255,255,0.2);border-right:1px solid rgba(255,255,255,0.2);">' +
          '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="22" y2="22"/></svg>' +
          '<span>' + count + ' match' + (count===1?'':'es') + '</span></button>' +
        '<button id="gr-hl-dismiss" style="' + mbs + '">' +
          '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>' +
          '<span>Close</span></button>';
    } else {
      bar.style.cssText = [
        'position:fixed', 'bottom:0', 'left:0', 'right:0', 'z-index:10200',
        'background:#b5451b', 'color:#fff', 'padding:10px 16px',
        'display:flex', 'align-items:center', 'justify-content:space-between',
        'font-family:system-ui,sans-serif', 'font-size:14px',
        'box-shadow:0 -2px 8px rgba(0,0,0,0.2)'
      ].join(';');


      var nav = document.createElement( 'div' );
        document.body.appendChild(bar);
      nav.style.cssText = 'display:flex;align-items:center;gap:12px;';
      nav.innerHTML =
        '<span>🔍 <strong>' + escHtml(query) + '</strong> — ' + count + ' match' + (count===1?'':'es') + '</span>' +
        '<button id="gr-hl-prev" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">↑ Prev</button>' +
        '<button id="gr-hl-next" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">↓ Next</button>' +
        '<button id="gr-hl-results" style="background:rgba(255,255,255,0.2);border:none;color:#fff;padding:4px 10px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;">← Results</button>';
      bar.appendChild( nav );


      var db = document.createElement( 'button' );
        var hlEls = Array.from(document.querySelectorAll('.gr-search-hl'));
      db.id = 'gr-hl-dismiss'; db.textContent = '✕ Close';
        var current = 0;
      db.style.cssText = 'background:rgba(255,255,255,0.15);border:none;color:#fff;padding:4px 12px;border-radius:4px;cursor:pointer;font-size:13px;min-height:32px;';
      bar.appendChild( db );
    }


    document.body.appendChild( bar );
        function goTo(idx) {
            hlEls.forEach(function (el) { el.classList.remove('gr-search-hl-current'); });
            current = ((idx % hlEls.length) + hlEls.length) % hlEls.length;
            hlEls[current].classList.add('gr-search-hl-current');
            hlEls[current].scrollIntoView({ behavior: 'smooth', block: 'center' });
        }


    var hlEls = Array.from( document.querySelectorAll( '.gr-search-hl' ) );
        function dismiss() { clearHighlights(); bar.remove(); }
    var current = 0;


    function goTo( idx ) {
        var nb = document.getElementById('gr-hl-next');
      hlEls.forEach( function(el) { el.classList.remove( 'gr-search-hl-current' ); } );
        var pb = document.getElementById('gr-hl-prev');
      current = ( ( idx % hlEls.length ) + hlEls.length ) % hlEls.length;
        var rb = document.getElementById('gr-hl-results');
      hlEls[ current ].classList.add( 'gr-search-hl-current' );
        var db2 = document.getElementById('gr-hl-dismiss');
      hlEls[ current ].scrollIntoView({ behavior: 'smooth', block: 'center' });
        if (nb) nb.onclick = function () { goTo(current + 1); };
        if (pb) pb.onclick = function () { goTo(current - 1); };
        if (db2) db2.onclick = dismiss;
        if (rb) rb.onclick = function () {
            bar.remove(); clearHighlights();
            if (window.showSearchDialog) window.showSearchDialog(query);
        };
     }
     }


     function dismiss() { clearHighlights(); bar.remove(); }
     function clearHighlights() {
        document.querySelectorAll('.gr-search-hl').forEach(function (span) {
            var p = span.parentNode; if (!p) return;
            while (span.firstChild) p.insertBefore(span.firstChild, span);
            p.removeChild(span);
        });
    }


     var nb = document.getElementById( 'gr-hl-next' );
     function escHtml(s) {
    var pb = document.getElementById( 'gr-hl-prev' );
        return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    var rb = document.getElementById( 'gr-hl-results' );
     }
    var db2 = document.getElementById( 'gr-hl-dismiss' );
    if ( nb ) nb.onclick = function() { goTo( current + 1 ); };
    if ( pb ) pb.onclick = function() { goTo( current - 1 ); };
    if ( db2 ) db2.onclick = dismiss;
     if ( rb ) rb.onclick = function() {
      bar.remove(); clearHighlights();
      if ( window.showSearchDialog ) window.showSearchDialog( query );
    };
  }


  function clearHighlights() {
    function injectHighlightCSS() {
    document.querySelectorAll( '.gr-search-hl' ).forEach( function( span ) {
        if (document.getElementById('gr-hl-css')) return;
      var p = span.parentNode; if ( !p ) return;
        var s = document.createElement('style');
      while ( span.firstChild ) p.insertBefore( span.firstChild, span );
        s.id = 'gr-hl-css';
      p.removeChild( span );
        s.textContent = [
     } );
            '.gr-search-hl{background:#fff176;color:#1a1a1a;border-radius:2px;padding:0 1px;box-shadow:0 0 0 1px rgba(181,69,27,0.25);}',
  }
            '.gr-search-hl-current{background:#ffb300!important;box-shadow:0 0 0 2px #b5451b!important;}',
            '@keyframes gr-hl-pulse{0%{background:#ffb300;}50%{background:#fff176;}100%{background:#fff176;}}',
            '.gr-search-hl-pulse{animation:gr-hl-pulse 1.2s ease 2;}',
        ].join('');
        document.head.appendChild(s);
     }


  function escHtml( s ) {
     injectHighlightCSS();
     return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  }


  function injectHighlightCSS() {
     if (document.readyState === 'loading') {
     if ( document.getElementById( 'gr-hl-css' ) ) return;
        document.addEventListener('DOMContentLoaded', applyHighlight);
    var s = document.createElement( 'style' );
     } else {
     s.id = 'gr-hl-css';
        applyHighlight();
    s.textContent = [
     }
      '.gr-search-hl{background:#fff176;color:#1a1a1a;border-radius:2px;padding:0 1px;box-shadow:0 0 0 1px rgba(181,69,27,0.25);}',
      '.gr-search-hl-current{background:#ffb300!important;box-shadow:0 0 0 2px #b5451b!important;}',
      '@keyframes gr-hl-pulse{0%{background:#ffb300;}50%{background:#fff176;}100%{background:#fff176;}}',
      '.gr-search-hl-pulse{animation:gr-hl-pulse 1.2s ease 2;}',
    ].join('');
     document.head.appendChild( s );
  }


  injectHighlightCSS();
    if (window.mw) {
        mw.hook('wikipage.content').add(function () {
            setTimeout(applyHighlight, 100);
        });
    }


  if ( document.readyState === 'loading' ) {
    window.grStoreSearchHL = storeQueryForLink;
    document.addEventListener( 'DOMContentLoaded', applyHighlight );
  } else {
    applyHighlight();
  }


  if ( window.mw ) {
}());
    mw.hook( 'wikipage.content' ).add( function() {
      setTimeout( applyHighlight, 100 );
    } );
  }
 
  window.grStoreSearchHL = storeQueryForLink;
 
}() );


/* ═══════════════════════════════════════════════════════════════
/* ═══════════════════════════════════════════════════════════════
   Mobile addon — only runs on Minerva (mobile) skin
   Mobile addon — only runs on Minerva (mobile) skin
   ═══════════════════════════════════════════════════════════════ */
   ═══════════════════════════════════════════════════════════════ */
( function () {
(function () {
  if ( !document.body.classList.contains( 'skin-minerva' ) ) return;
    if (!document.body.classList.contains('skin-minerva')) return;
  function injectCSS() {
    function injectCSS() {
    if ( document.getElementById( 'gr-mob-css' ) ) return;
        if (document.getElementById('gr-mob-css')) return;
    var s = document.createElement( 'style' );
        var s = document.createElement('style');
    s.id = 'gr-mob-css';
        s.id = 'gr-mob-css';
    s.textContent =
        s.textContent =
      'body,#mw-mf-viewport,#mw-mf-page-center{padding-top:0!important;margin-top:0!important;}' +
            'body,#mw-mf-viewport,#mw-mf-page-center{padding-top:0!important;margin-top:0!important;}' +
      'html,body,#mw-mf-viewport,#mw-mf-page-center{overflow-x:hidden!important;max-width:100vw!important;}' +
            'html,body,#mw-mf-viewport,#mw-mf-page-center{overflow-x:hidden!important;max-width:100vw!important;}' +
      'header.header-container{background:#b5451b!important;position:sticky!important;top:0!important;z-index:300!important;}' +
            'header.header-container{background:#b5451b!important;position:sticky!important;top:0!important;z-index:300!important;}' +
      '.minerva-header{background:#b5451b!important;min-height:54px!important;}' +
            '.minerva-header{background:#b5451b!important;min-height:54px!important;}' +
      '.minerva-header .search-toggle,.minerva-header .minerva-user-notifications{display:none!important;}' +
            '.minerva-header .search-toggle,.minerva-header .minerva-user-notifications{display:none!important;}' +
      '.branding-box a{display:flex!important;align-items:center!important;text-decoration:none!important;max-width:calc(100vw - 80px)!important;}' +
            '.branding-box a{display:flex!important;align-items:center!important;text-decoration:none!important;max-width:calc(100vw - 80px)!important;}' +
      '.branding-box a::before{content:"";display:block;width:30px;height:30px;flex-shrink:0;background:url("/favicon.png") center/contain no-repeat;margin-right:8px;}' +
            '.branding-box a::before{content:"";display:block;width:30px;height:30px;flex-shrink:0;background:url("/favicon.png") center/contain no-repeat;margin-right:8px;}' +
      '.branding-box a span{color:#fff!important;font-size:16px!important;font-weight:700!important;font-family:system-ui,sans-serif!important;line-height:1.2!important;flex:1 1 auto!important;min-width:0!important;}' +
            '.branding-box a span{color:#fff!important;font-size:16px!important;font-weight:700!important;font-family:system-ui,sans-serif!important;line-height:1.2!important;flex:1 1 auto!important;min-width:0!important;}' +
      '.minerva-header svg path,.minerva-header svg rect,.minerva-header svg circle{fill:#fff!important;}' +
            '.minerva-header svg path,.minerva-header svg rect,.minerva-header svg circle{fill:#fff!important;}' +
      '.minerva-header label{color:#fff!important;}' +
            '.minerva-header label{color:#fff!important;}' +
      '.minerva-tabs,.mw-portlet-associated-pages,.page-actions-menu,#page-secondary-actions,.last-modified-bar,.minerva-anon-talk-link{display:none!important;}' +
            '.minerva-tabs,.mw-portlet-associated-pages,.page-actions-menu,#page-secondary-actions,.last-modified-bar,.minerva-anon-talk-link{display:none!important;}' +
      '#gr-mob-menu-items{display:block!important;}' +
            '#gr-mob-menu-items{display:block!important;}' +
      '.mw-footer.minerva-footer,.footer-places,.footer-info,.minerva-footer-logo,#footer-places-about,#footer-places-disclaimers,#footer-places-privacy{display:none!important;}' +
            '.mw-footer.minerva-footer,.footer-places,.footer-info,.minerva-footer-logo,#footer-places-about,#footer-places-disclaimers,#footer-places-privacy{display:none!important;}' +
      '#gr-static-bar{position:sticky!important;top:54px!important;z-index:200!important;}' +
            '#gr-static-bar{position:sticky!important;top:54px!important;z-index:200!important;}' +
      '.mf-section-0,.mf-section-1,.mf-section-2,.mf-section-3,.mf-section-4,.mf-section-5,.mf-section-6,.mf-section-7,.mf-section-8,.mf-section-9,.mf-section-10{display:block!important;visibility:visible!important;}' +
            '.mf-section-0,.mf-section-1,.mf-section-2,.mf-section-3,.mf-section-4,.mf-section-5,.mf-section-6,.mf-section-7,.mf-section-8,.mf-section-9,.mf-section-10{display:block!important;visibility:visible!important;}' +
      '.collapsible-block{display:block!important;}' +
            '.collapsible-block{display:block!important;}' +
      '.section-heading .indicator,.collapsible-heading .indicator{display:none!important;}' +
            '.section-heading .indicator,.collapsible-heading .indicator{display:none!important;}' +
      '.section-heading,.collapsible-heading{pointer-events:none!important;}' +
            '.section-heading,.collapsible-heading{pointer-events:none!important;}' +
      '.gr-home-grid{flex-direction:column!important;flex-wrap:nowrap!important;gap:12px!important;width:100%!important;}' +
            '.gr-home-grid{flex-direction:column!important;flex-wrap:nowrap!important;gap:12px!important;width:100%!important;}' +
      '.gr-home-card{width:100%!important;max-width:100%!important;min-width:unset!important;box-sizing:border-box!important;flex:none!important;}' +
            '.gr-home-card{width:100%!important;max-width:100%!important;min-width:unset!important;box-sizing:border-box!important;flex:none!important;}' +
      '.gr-home-toggle{flex-wrap:wrap!important;}' +
            '.gr-home-toggle{flex-wrap:wrap!important;}' +
      '.mw-parser-output{font-size:18px!important;line-height:1.8!important;}' +
            '.mw-parser-output{font-size:18px!important;line-height:1.8!important;}' +
      '.mw-parser-output h2,.mw-parser-output h3{width:100%!important;}' +
            '.mw-parser-output h2,.mw-parser-output h3{width:100%!important;}' +
      '.bhashyam-block{margin-left:8px!important;}' +
            '.bhashyam-block{margin-left:8px!important;}' +
      '#footer,.mw-footer,.catlinks,#catlinks{display:none!important;}' +
            '#footer,.mw-footer,.catlinks,#catlinks{display:none!important;}' +
      '.gr-mob-toc-panel{position:fixed!important;top:0!important;left:0!important;bottom:0!important;width:82vw!important;max-width:340px!important;background:#fff!important;z-index:10400!important;box-shadow:4px 0 28px rgba(0,0,0,0.22)!important;overflow-y:auto!important;padding:0 0 40px!important;transform:translateX(-110%)!important;transition:transform 0.26s cubic-bezier(0.4,0,0.2,1)!important;display:block!important;}' +
            '.gr-mob-toc-panel{position:fixed!important;top:0!important;left:0!important;bottom:0!important;width:82vw!important;max-width:340px!important;background:#fff!important;z-index:10400!important;box-shadow:4px 0 28px rgba(0,0,0,0.22)!important;overflow-y:auto!important;padding:0 0 40px!important;transform:translateX(-110%)!important;transition:transform 0.26s cubic-bezier(0.4,0,0.2,1)!important;display:block!important;}' +
      '.gr-mob-toc-panel.open{transform:translateX(0)!important;}' +
            '.gr-mob-toc-panel.open{transform:translateX(0)!important;}' +
      '.gr-mob-toc-backdrop{display:none!important;position:fixed!important;inset:0!important;background:rgba(0,0,0,0.4)!important;z-index:10399!important;}' +
            '.gr-mob-toc-backdrop{display:none!important;position:fixed!important;inset:0!important;background:rgba(0,0,0,0.4)!important;z-index:10399!important;}' +
      '.gr-mob-toc-backdrop.open{display:block!important;}' +
            '.gr-mob-toc-backdrop.open{display:block!important;}' +
      '.gr-mob-toc-header{position:sticky!important;top:0!important;background:#fff!important;display:flex!important;align-items:center!important;justify-content:space-between!important;padding:16px 16px 12px!important;border-bottom:1px solid #f0ebe6!important;z-index:1!important;}' +
            '.gr-mob-toc-header{position:sticky!important;top:0!important;background:#fff!important;display:flex!important;align-items:center!important;justify-content:space-between!important;padding:16px 16px 12px!important;border-bottom:1px solid #f0ebe6!important;z-index:1!important;}' +
      '.gr-mob-toc-title{font-size:13px!important;font-weight:700!important;text-transform:uppercase!important;letter-spacing:0.08em!important;color:#b5451b!important;font-family:system-ui,sans-serif!important;}' +
            '.gr-mob-toc-title{font-size:13px!important;font-weight:700!important;text-transform:uppercase!important;letter-spacing:0.08em!important;color:#b5451b!important;font-family:system-ui,sans-serif!important;}' +
      '.gr-mob-toc-close{background:none!important;border:none!important;font-size:22px!important;color:#999!important;cursor:pointer!important;padding:4px 8px!important;}' +
            '.gr-mob-toc-close{background:none!important;border:none!important;font-size:22px!important;color:#999!important;cursor:pointer!important;padding:4px 8px!important;}' +
      '.gr-mob-toc-body{padding:12px 16px!important;}' +
            '.gr-mob-toc-body{padding:12px 16px!important;}' +
      '.gr-mob-toc-body a{display:block!important;font-size:16px!important;line-height:1.6!important;color:#2c1810!important;text-decoration:none!important;padding:8px 0!important;border-bottom:1px solid #f5f0ed!important;}';
            '.gr-mob-toc-body a{display:block!important;font-size:16px!important;line-height:1.6!important;color:#2c1810!important;text-decoration:none!important;padding:8px 0!important;border-bottom:1px solid #f5f0ed!important;}';
    document.head.appendChild( s );
        document.head.appendChild(s);
  }
    }
  function expandSections() {
    function expandSections() {
    document.querySelectorAll( '[class*="mf-section-"], .collapsible-block' ).forEach( function ( el ) { el.removeAttribute( 'hidden' ); el.style.setProperty( 'display', 'block', 'important' ); el.style.setProperty( 'visibility', 'visible', 'important' ); el.removeAttribute( 'aria-hidden' ); } );
        document.querySelectorAll('[class*="mf-section-"], .collapsible-block').forEach(function (el) { el.removeAttribute('hidden'); el.style.setProperty('display', 'block', 'important'); el.style.setProperty('visibility', 'visible', 'important'); el.removeAttribute('aria-hidden'); });
    document.querySelectorAll( '.section-heading, .collapsible-heading' ).forEach( function ( el ) { el.setAttribute( 'aria-expanded', 'true' ); el.style.setProperty( 'pointer-events', 'none', 'important' ); } );
        document.querySelectorAll('.section-heading, .collapsible-heading').forEach(function (el) { el.setAttribute('aria-expanded', 'true'); el.style.setProperty('pointer-events', 'none', 'important'); });
  }
    }
  function watchSections() {
    function watchSections() {
    var t = null;
        var t = null;
    var obs = new MutationObserver( function ( ms ) { if ( ms.some( function(m){ return m.attributeName === 'hidden'; } ) ) { clearTimeout(t); t = setTimeout( expandSections, 30 ); } } );
        var obs = new MutationObserver(function (ms) { if (ms.some(function (m) { return m.attributeName === 'hidden'; })) { clearTimeout(t); t = setTimeout(expandSections, 30); } });
    obs.observe( document.querySelector( '#mw-content-text' ) || document.body, { subtree:true, attributes:true, attributeFilter:['hidden','aria-hidden'] } );
        obs.observe(document.querySelector('#mw-content-text') || document.body, { subtree: true, attributes: true, attributeFilter: ['hidden', 'aria-hidden'] });
  }
    }
  function watchBodyPadding() {
    function watchBodyPadding() {
    new MutationObserver( function () { if ( document.body.style.paddingTop && document.body.style.paddingTop !== '0px' ) document.body.style.paddingTop = ''; } ).observe( document.body, { attributes:true, attributeFilter:['style'] } );
        new MutationObserver(function () { if (document.body.style.paddingTop && document.body.style.paddingTop !== '0px') document.body.style.paddingTop = ''; }).observe(document.body, { attributes: true, attributeFilter: ['style'] });
  }
    }
  function injectMenuLinks() {
    function injectMenuLinks() {
    if ( document.getElementById( 'gr-mob-menu-items' ) ) return;
        if (document.getElementById('gr-mob-menu-items')) return;
    var navDrawer = document.querySelector( '.navigation-drawer' );
        var navDrawer = document.querySelector('.navigation-drawer');
    if ( !navDrawer ) return;
        if (!navDrawer) return;
    var wrap = document.createElement( 'div' ); wrap.id = 'gr-mob-menu-items'; wrap.style.cssText = 'width:100%;background:#fff;margin-top:8px;';
        var wrap = document.createElement('div'); wrap.id = 'gr-mob-menu-items'; wrap.style.cssText = 'width:100%;background:#fff;margin-top:8px;';
    var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px;font-size:16px;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;border-bottom:1px solid #f0ebe6;background:#fff;';
        var itemStyle = 'display:flex;align-items:center;gap:14px;padding:15px 20px;font-size:16px;color:#2c1810;text-decoration:none;font-family:system-ui,sans-serif;border-bottom:1px solid #f0ebe6;background:#fff;';
    function makeItem( href, label ) { var a = document.createElement( 'a' ); a.href = href; a.style.cssText = itemStyle; a.innerHTML = '<span>' + label + '</span>'; return a; }
        function makeItem(href, label) { var a = document.createElement('a'); a.href = href; a.style.cssText = itemStyle; a.innerHTML = '<span>' + label + '</span>'; return a; }
    wrap.appendChild( makeItem( '/Main_Page', 'Home' ) );
        wrap.appendChild(makeItem('/Main_Page', 'Home'));
    wrap.appendChild( makeItem( '/My_wiki:Help', 'Help' ) );
        wrap.appendChild(makeItem('/My_wiki:Help', 'Help'));
    wrap.appendChild( makeItem( '/My_wiki:About', 'About' ) );
        wrap.appendChild(makeItem('/My_wiki:About', 'About'));
    var userName = window.mw ? mw.config.get( 'wgUserName' ) : null;
        var userName = window.mw ? mw.config.get('wgUserName') : null;
    if ( userName ) {
        if (userName) {
      wrap.appendChild( makeItem( ( window.mw && mw.util && mw.util.getUrl ) ? mw.util.getUrl( 'Special:Profile' ) : '/Special:Profile', 'Profile' ) );
            wrap.appendChild(makeItem((window.mw && mw.util && mw.util.getUrl) ? mw.util.getUrl('Special:Profile') : '/Special:Profile', 'Profile'));
      var la = document.querySelector( 'a[href*="action=logout"]' );
            var la = document.querySelector('a[href*="action=logout"]');
      wrap.appendChild( makeItem( la ? la.href : '/index.php?title=Special:UserLogout', 'Log out' ) );
            wrap.appendChild(makeItem(la ? la.href : '/index.php?title=Special:UserLogout', 'Log out'));
        }
        else wrap.appendChild(makeItem('/index.php?title=Special:UserLogin', 'Log in'));
        var pageLeft = document.getElementById('mw-mf-page-left');
        if (pageLeft) { while (pageLeft.firstChild) pageLeft.removeChild(pageLeft.firstChild); pageLeft.style.removeProperty('display'); pageLeft.appendChild(wrap); }
        else navDrawer.appendChild(wrap);
    }
    var _tocDone = false;
    function initToc() {
        if (_tocDone) return;
        var tocList = document.querySelector('.vector-toc-contents, .vector-toc .vector-toc-list');
        if (!tocList || !tocList.querySelector('li')) return;
        _tocDone = true;
        var bd = document.createElement('div'); bd.className = 'gr-mob-toc-backdrop'; document.body.appendChild(bd);
        var panel = document.createElement('div'); panel.className = 'gr-mob-toc-panel';
        var hdr = document.createElement('div'); hdr.className = 'gr-mob-toc-header';
        var ttl = document.createElement('div'); ttl.className = 'gr-mob-toc-title'; ttl.textContent = 'विषयसूची';
        var cls = document.createElement('button'); cls.className = 'gr-mob-toc-close'; cls.textContent = '✕';
        hdr.appendChild(ttl); hdr.appendChild(cls); panel.appendChild(hdr);
        var body = document.createElement('div'); body.className = 'gr-mob-toc-body'; body.appendChild(tocList.cloneNode(true)); panel.appendChild(body); document.body.appendChild(panel);
        var btn = document.createElement('button'); btn.id = 'gr-mob-toc-btn'; btn.innerHTML = '☰ &nbsp;Contents';
        btn.style.cssText = 'position:fixed;bottom:148px;left:16px;z-index:9100;background:#fff;border:1.5px solid #b5451b;border-radius:24px;padding:10px 16px;font-size:15px;font-family:system-ui,sans-serif;color:#b5451b;font-weight:600;box-shadow:0 3px 14px rgba(0,0,0,0.15);cursor:pointer;';
        document.body.appendChild(btn);
        function open() { panel.classList.add('open'); bd.classList.add('open'); document.body.style.overflow = 'hidden'; }
        function close() { panel.classList.remove('open'); bd.classList.remove('open'); document.body.style.overflow = ''; }
        btn.onclick = open; cls.onclick = close; bd.onclick = close;
        body.querySelectorAll('a').forEach(function (a) { a.onclick = close; });
    }
    function injectMoolaUllekhaLinks() {
        if (document.getElementById('gr-mob-doc-nav')) return;
        var pageName = (window.mw && mw.config && mw.config.get('wgPageName')) || '';
        if (pageName === 'Main_Page' || !pageName) return;
        function wikiUrl(slug) { if (window.mw && mw.util && mw.util.getUrl) return mw.util.getUrl(slug); return ((window.mw && mw.config.get('wgArticlePath')) || '/wiki/$1').replace('$1', encodeURIComponent(slug).replace(/%2F/g, '/')); }
        var teekaPage = document.querySelector('.gr-teeka-page');
        var primarySlug = teekaPage ? (teekaPage.getAttribute('data-primary') || pageName.split('/')[0]) : pageName.split('/')[0];
        var docTitleEl = document.querySelector('.gr-doc-title');
        var hasMoolaPage = docTitleEl && docTitleEl.getAttribute('data-has-moola') === '1';
        var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute('data-has-ullekha') === '1';
        var showMoolam = !!teekaPage || hasMoolaPage, showUllekha = hasUllekhaPage || !!teekaPage;
        if (!showMoolam && !showUllekha) return;
        var nav = document.createElement('div'); nav.id = 'gr-mob-doc-nav';
        nav.style.cssText = 'display:flex;gap:10px;padding:10px 16px 8px;background:#fdf8f5;border-bottom:1px solid #f0e0d6;font-family:system-ui,sans-serif;';
        function makeLink(href, label) { var a = document.createElement('a'); a.href = href; a.textContent = label; a.style.cssText = 'display:inline-flex;align-items:center;padding:5px 16px;border-radius:20px;background:#fff;border:1.5px solid #e8cfc4;color:#b5451b;font-size:14px;font-weight:600;text-decoration:none;'; return a; }
        if (teekaPage) nav.appendChild(makeLink(wikiUrl(primarySlug), 'मूल'));
        else if (hasMoolaPage) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Moola'), 'मूलम्'));
        if (showUllekha) nav.appendChild(makeLink(wikiUrl(primarySlug + '/Ullekha'), 'उल्लेख'));
        var h1 = document.getElementById('firstHeading') || document.querySelector('.page-heading, h1.firstHeading, .mw-first-heading');
        if (h1 && h1.parentNode) h1.parentNode.insertBefore(nav, h1.nextSibling);
        else { var ct = document.getElementById('mw-content-text'); if (ct) ct.insertBefore(nav, ct.firstChild); }
     }
     }
     else wrap.appendChild( makeItem( '/index.php?title=Special:UserLogin', 'Log in' ) );
     injectCSS(); watchBodyPadding();
    var pageLeft = document.getElementById( 'mw-mf-page-left' );
    function boot() { expandSections(); watchSections(); injectMenuLinks(); injectMoolaUllekhaLinks();[100, 400, 900, 1800].forEach(function (ms) { setTimeout(expandSections, ms); }); setTimeout(initToc, 700); }
    if ( pageLeft ) { while ( pageLeft.firstChild ) pageLeft.removeChild( pageLeft.firstChild ); pageLeft.style.removeProperty( 'display' ); pageLeft.appendChild( wrap ); }
    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
    else navDrawer.appendChild( wrap );
    else boot();
  }
    if (window.mw) mw.hook('wikipage.content').add(function () { setTimeout(function () { expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); }, 300); });
  var _tocDone = false;
}());
  function initToc() {
    if ( _tocDone ) return;
    var tocList = document.querySelector( '.vector-toc-contents, .vector-toc .vector-toc-list' );
    if ( !tocList || !tocList.querySelector( 'li' ) ) return;
    _tocDone = true;
    var bd = document.createElement( 'div' ); bd.className = 'gr-mob-toc-backdrop'; document.body.appendChild( bd );
    var panel = document.createElement( 'div' ); panel.className = 'gr-mob-toc-panel';
    var hdr = document.createElement( 'div' ); hdr.className = 'gr-mob-toc-header';
    var ttl = document.createElement( 'div' ); ttl.className = 'gr-mob-toc-title'; ttl.textContent = 'विषयसूची';
    var cls = document.createElement( 'button' ); cls.className = 'gr-mob-toc-close'; cls.textContent = '✕';
    hdr.appendChild( ttl ); hdr.appendChild( cls ); panel.appendChild( hdr );
    var body = document.createElement( 'div' ); body.className = 'gr-mob-toc-body'; body.appendChild( tocList.cloneNode( true ) ); panel.appendChild( body ); document.body.appendChild( panel );
    var btn = document.createElement( 'button' ); btn.id = 'gr-mob-toc-btn'; btn.innerHTML = '☰ &nbsp;Contents';
    btn.style.cssText = 'position:fixed;bottom:148px;left:16px;z-index:9100;background:#fff;border:1.5px solid #b5451b;border-radius:24px;padding:10px 16px;font-size:15px;font-family:system-ui,sans-serif;color:#b5451b;font-weight:600;box-shadow:0 3px 14px rgba(0,0,0,0.15);cursor:pointer;';
    document.body.appendChild( btn );
    function open()  { panel.classList.add('open'); bd.classList.add('open'); document.body.style.overflow='hidden'; }
    function close() { panel.classList.remove('open'); bd.classList.remove('open'); document.body.style.overflow=''; }
    btn.onclick = open; cls.onclick = close; bd.onclick = close;
    body.querySelectorAll('a').forEach(function(a){ a.onclick = close; });
  }
  function injectMoolaUllekhaLinks() {
    if ( document.getElementById( 'gr-mob-doc-nav' ) ) return;
    var pageName = ( window.mw && mw.config && mw.config.get( 'wgPageName' ) ) || '';
    if ( pageName === 'Main_Page' || !pageName ) return;
    function wikiUrl( slug ) { if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( slug ); return ( ( window.mw && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1' ).replace( '$1', encodeURIComponent( slug ).replace( /%2F/g, '/' ) ); }
    var teekaPage = document.querySelector( '.gr-teeka-page' );
    var primarySlug = teekaPage ? ( teekaPage.getAttribute( 'data-primary' ) || pageName.split('/')[0] ) : pageName.split('/')[0];
    var docTitleEl = document.querySelector( '.gr-doc-title' );
    var hasMoolaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-moola' ) === '1';
    var hasUllekhaPage = docTitleEl && docTitleEl.getAttribute( 'data-has-ullekha' ) === '1';
    var showMoolam = !!teekaPage || hasMoolaPage, showUllekha = hasUllekhaPage || !!teekaPage;
    if ( !showMoolam && !showUllekha ) return;
    var nav = document.createElement( 'div' ); nav.id = 'gr-mob-doc-nav';
    nav.style.cssText = 'display:flex;gap:10px;padding:10px 16px 8px;background:#fdf8f5;border-bottom:1px solid #f0e0d6;font-family:system-ui,sans-serif;';
    function makeLink( href, label ) { var a = document.createElement( 'a' ); a.href = href; a.textContent = label; a.style.cssText = 'display:inline-flex;align-items:center;padding:5px 16px;border-radius:20px;background:#fff;border:1.5px solid #e8cfc4;color:#b5451b;font-size:14px;font-weight:600;text-decoration:none;'; return a; }
    if ( teekaPage ) nav.appendChild( makeLink( wikiUrl( primarySlug ), 'मूल' ) );
    else if ( hasMoolaPage ) nav.appendChild( makeLink( wikiUrl( primarySlug + '/Moola' ), 'मूलम्' ) );
    if ( showUllekha ) nav.appendChild( makeLink( wikiUrl( primarySlug + '/Ullekha' ), 'उल्लेख' ) );
    var h1 = document.getElementById( 'firstHeading' ) || document.querySelector( '.page-heading, h1.firstHeading, .mw-first-heading' );
    if ( h1 && h1.parentNode ) h1.parentNode.insertBefore( nav, h1.nextSibling );
    else { var ct = document.getElementById( 'mw-content-text' ); if ( ct ) ct.insertBefore( nav, ct.firstChild ); }
  }
  injectCSS(); watchBodyPadding();
  function boot() { expandSections(); watchSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); [100,400,900,1800].forEach(function(ms){ setTimeout(expandSections,ms); }); setTimeout(initToc,700); }
  if ( document.readyState === 'loading' ) document.addEventListener( 'DOMContentLoaded', boot );
  else boot();
  if ( window.mw ) mw.hook( 'wikipage.content' ).add(function(){ setTimeout(function(){ expandSections(); injectMenuLinks(); injectMoolaUllekhaLinks(); initToc(); },300); });
}() );




( function () {
(function () {
  'use strict';
    'use strict';
  mw.hook( 'wikipage.content' ).add( function () {
    mw.hook('wikipage.content').add(function () {
    setTimeout( function () {
        setTimeout(function () {
      var blocks = document.querySelectorAll( '.collapsible-block, .toggle-list' );
            var blocks = document.querySelectorAll('.collapsible-block, .toggle-list');
      Array.prototype.forEach.call( blocks, function ( el ) { if ( !el.parentNode ) { try { el.remove(); } catch(e) {} } } );
            Array.prototype.forEach.call(blocks, function (el) { if (!el.parentNode) { try { el.remove(); } catch (e) { } } });
    }, 0 );
        }, 0);
  } );
    });
  if ( mw.config.get( 'wgPageName' ) !== 'Main_Page' ) return;
    if (mw.config.get('wgPageName') !== 'Main_Page') return;
  mw.loader.using( 'mediawiki.util' ).done( function () {
    mw.loader.using('mediawiki.util').done(function () {
    $( function () { applyHomeToggleOffset(); window.addEventListener( 'resize', applyHomeToggleOffset, { passive: true } ); setTimeout( applyHomeToggleOffset, 300 ); setTimeout( applyHomeToggleOffset, 800 ); } );
        $(function () { applyHomeToggleOffset(); window.addEventListener('resize', applyHomeToggleOffset, { passive: true }); setTimeout(applyHomeToggleOffset, 300); setTimeout(applyHomeToggleOffset, 800); });
  } );
    });
  function applyHomeToggleOffset() {
    function applyHomeToggleOffset() {
    var bar = document.getElementById( 'gr-static-bar' ); if ( !bar ) return;
        var bar = document.getElementById('gr-static-bar'); if (!bar) return;
    var barBottom = Math.round( bar.getBoundingClientRect().bottom );
        var barBottom = Math.round(bar.getBoundingClientRect().bottom);
    [ document.getElementById('gr-home'), document.getElementById('gr-home-toggle'), document.querySelector('#mw-content-text .mw-parser-output > .gr-home, #mw-content-text .mw-parser-output > *:first-child') ].forEach( function(el){ if(el) el.style.scrollMarginTop=(barBottom+4)+'px'; } );
        [document.getElementById('gr-home'), document.getElementById('gr-home-toggle'), document.querySelector('#mw-content-text .mw-parser-output > .gr-home, #mw-content-text .mw-parser-output > *:first-child')].forEach(function (el) { if (el) el.style.scrollMarginTop = (barBottom + 4) + 'px'; });
    var isMob = window.innerWidth < 768 || !!document.getElementById( 'mw-mf-viewport' );
        var isMob = window.innerWidth < 768 || !!document.getElementById('mw-mf-viewport');
    if ( isMob ) { var toggleEl = document.getElementById('gr-home-toggle'); if ( toggleEl ) { var tr = toggleEl.getBoundingClientRect(); if ( tr.top < barBottom ) { var cp = parseInt(window.getComputedStyle(document.body).paddingTop,10)||0; document.body.style.paddingTop=(cp+(barBottom-tr.top)+4)+'px'; } } }
        if (isMob) { var toggleEl = document.getElementById('gr-home-toggle'); if (toggleEl) { var tr = toggleEl.getBoundingClientRect(); if (tr.top < barBottom) { var cp = parseInt(window.getComputedStyle(document.body).paddingTop, 10) || 0; document.body.style.paddingTop = (cp + (barBottom - tr.top) + 4) + 'px'; } } }
  }
    }
  $( function () {
    $(function () {
    var $toggle=$('#gr-home-toggle'),$viewG=$('#gr-view-grantha'),$viewA=$('#gr-view-author'),$btnG=$('#gr-toggle-grantha'),$btnA=$('#gr-toggle-author');
        var $toggle = $('#gr-home-toggle'), $viewG = $('#gr-view-grantha'), $viewA = $('#gr-view-author'), $btnG = $('#gr-toggle-grantha'), $btnA = $('#gr-toggle-author');
    if(!$toggle.length||!$viewG.length||!$viewA.length)return; if($toggle.data('gr-wired'))return; $toggle.data('gr-wired',true);
        if (!$toggle.length || !$viewG.length || !$viewA.length) return; if ($toggle.data('gr-wired')) return; $toggle.data('gr-wired', true);
    function showView(which){ if(which==='grantha'){$viewG.show();$viewA.hide();$btnG.addClass('gr-toggle-active');$btnA.removeClass('gr-toggle-active');}else{$viewA.show();$viewG.hide();$btnA.addClass('gr-toggle-active');$btnG.removeClass('gr-toggle-active');} try{localStorage.setItem('grantha_home_tab',which);}catch(e){} }
        function showView(which) { if (which === 'grantha') { $viewG.show(); $viewA.hide(); $btnG.addClass('gr-toggle-active'); $btnA.removeClass('gr-toggle-active'); } else { $viewA.show(); $viewG.hide(); $btnA.addClass('gr-toggle-active'); $btnG.removeClass('gr-toggle-active'); } try { localStorage.setItem('grantha_home_tab', which); } catch (e) { } }
    $btnG.on('click keydown',function(e){if(e.type==='keydown'&&e.key!=='Enter'&&e.key!==' ')return;showView('grantha');});
        $btnG.on('click keydown', function (e) { if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') return; showView('grantha'); });
    $btnA.on('click keydown',function(e){if(e.type==='keydown'&&e.key!=='Enter'&&e.key!==' ')return;showView('author');});
        $btnA.on('click keydown', function (e) { if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') return; showView('author'); });
    try{var saved=localStorage.getItem('grantha_home_tab');if(saved==='author')showView('author');else showView('grantha');}catch(e){showView('grantha');}
        try { var saved = localStorage.getItem('grantha_home_tab'); if (saved === 'author') showView('author'); else showView('grantha'); } catch (e) { showView('grantha'); }
  } );
    });
}() );
}());
// ── Replace MediaWiki user links with a single username dropdown (Profile + Logout) ──
// ── Replace MediaWiki user links with a single username dropdown (Profile + Logout) ──
( function () {
(function () {
  function wikiHref( title ) {
    function wikiHref(title) {
    if ( window.mw && mw.util && mw.util.getUrl ) return mw.util.getUrl( title );
        if (window.mw && mw.util && mw.util.getUrl) return mw.util.getUrl(title);
    var ap = ( window.mw && mw.config && mw.config.get( 'wgArticlePath' ) ) || '/wiki/$1';
        var ap = (window.mw && mw.config && mw.config.get('wgArticlePath')) || '/wiki/$1';
    return ap.replace( '$1', title );
        return ap.replace('$1', title);
  }
    }


  function buildLogoutForm( token ) {
    function buildLogoutForm(token) {
    token = token || '';
        token = token || '';
    var esc = String( token ).replace( /"/g, '&quot;' );
        var esc = String(token).replace(/"/g, '&quot;');
    var script = ( window.mw && mw.util && mw.util.wikiScript ) ? mw.util.wikiScript() : '/index.php';
        var script = (window.mw && mw.util && mw.util.wikiScript) ? mw.util.wikiScript() : '/index.php';
    var form = document.createElement( 'form' );
        var form = document.createElement('form');
    form.method = 'post';
        form.method = 'post';
    form.action = script + '?title=Special:UserLogout';
        form.action = script + '?title=Special:UserLogout';
    form.style.display = 'none';
        form.style.display = 'none';
    form.innerHTML =
        form.innerHTML =
      '<input type="hidden" name="wpEditToken" value="' + esc + '">' +
            '<input type="hidden" name="wpEditToken" value="' + esc + '">' +
      '<input type="hidden" name="title" value="Special:UserLogout">' +
            '<input type="hidden" name="title" value="Special:UserLogout">' +
      '<input type="hidden" name="returnto" value="Main Page">';
            '<input type="hidden" name="returnto" value="Main Page">';
    document.body.appendChild( form );
        document.body.appendChild(form);
    return form;
        return form;
  }
 
  function injectUserDropdown() {
    if ( document.getElementById( 'gr-user-dropdown' ) ) return;
 
    var userName = window.mw ? mw.config.get( 'wgUserName' ) : null;
    var isAnon = !userName || ( window.mw && mw.config.get( 'wgUserId' ) === null );
 
    var container = document.querySelector( '.vector-user-links-main' )
                || document.querySelector( '.vector-user-links' );
    if ( !container ) return;
 
    // Logged-out: show a single Login/Signup link, nothing else
    if ( isAnon ) {
        // Remove MediaWiki's native account links so only our button shows
        [ '#pt-createaccount', '#pt-login', '#pt-anoncontribs',
          '#pt-anontalk', '#pt-anonuserpage' ].forEach( function ( sel ) {
            document.querySelectorAll( sel ).forEach( function ( el ) {
                if ( el && el.parentNode ) el.parentNode.removeChild( el );
            } );
        } );
        if ( document.getElementById( 'gr-login-link' ) ) return;
        var loginA = document.createElement( 'a' );
        loginA.id = 'gr-login-link';
        loginA.href = wikiHref( 'Special:UserLogin' );
        loginA.textContent = 'Login/Signup';
        loginA.style.cssText = 'color:#fff;font-size:0.9em;font-weight:500;' +
            'text-decoration:none;padding:6px 12px;border-radius:6px;' +
            'background:rgba(255,255,255,0.12);white-space:nowrap;';
        loginA.addEventListener( 'mouseover', function(){ this.style.background='rgba(255,255,255,0.2)'; } );
        loginA.addEventListener( 'mouseout',  function(){ this.style.background='rgba(255,255,255,0.12)'; } );
        container.appendChild( loginA );
        return;
     }
     }
 
}());
    // Logout token (csrf token works for logout in modern MW)
    var token = ( window.mw && mw.user && mw.user.tokens )
      ? mw.user.tokens.get( 'csrfToken' ) : '+\\';
 
    var wrap = document.createElement( 'div' );
    wrap.id = 'gr-user-dropdown';
    wrap.innerHTML =
      '<button id="gr-user-trigger" type="button" aria-haspopup="true" aria-expanded="false">' +
        '<span>' + (userName.replace(/</g,'&lt;')) + '</span>' +
        '<span class="gr-caret">▾</span>' +
      '</button>' +
      '<div id="gr-user-menu" role="menu">' +
        '<a href="' + wikiHref( 'Special:Profile' ) + '" role="menuitem">Profile</a>' +
        '<a href="#" id="gr-logout-link" role="menuitem">Log out</a>' +
      '</div>';
 
    container.appendChild( wrap );
 
    var trigger = document.getElementById( 'gr-user-trigger' );
    var menu    = document.getElementById( 'gr-user-menu' );
 
    trigger.addEventListener( 'click', function ( e ) {
      e.stopPropagation();
      var open = menu.classList.toggle( 'gr-open' );
      trigger.setAttribute( 'aria-expanded', open ? 'true' : 'false' );
    } );
 
    document.addEventListener( 'click', function ( e ) {
      if ( !wrap.contains( e.target ) ) {
        menu.classList.remove( 'gr-open' );
        trigger.setAttribute( 'aria-expanded', 'false' );
      }
    } );
 
    document.getElementById( 'gr-logout-link' ).addEventListener( 'click', function ( e ) {
      e.preventDefault();
      // Fetch a fresh CSRF token at click time (more reliable than at load time)
      if ( window.mw && mw.user && mw.user.tokens ) {
        var t = mw.user.tokens.get( 'csrfToken' );
        if ( t ) { buildLogoutForm( t ).submit(); return; }
      }
      // Fallback: use the API to get a logout token, then submit
      if ( window.mw && mw.Api ) {
        new mw.Api().postWithToken( 'csrf', { action: 'logout' } )
          .done( function () { location.href = '/Main_Page'; } )
          .fail( function () { location.href = '/index.php?title=Special:UserLogout'; } );
      } else {
        location.href = '/index.php?title=Special:UserLogout';
      }
    } );
  }
 
  if ( document.readyState === 'loading' ) {
    document.addEventListener( 'DOMContentLoaded', injectUserDropdown );
  } else {
    injectUserDropdown();
  }
}() );