MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(73 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=User:Gurwinder/Edittool.js&action=raw&ctype=text/javascript');
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=User:Gurwinder/Edittool.js&action=raw&ctype=text/javascript');


Line 59: Line 60:
}
}
if( mw.config.get('wgPageName').split( '/' ).length > 1 ){
if (
var tempPageName = mw.config.get('wgPageName').split( '/' )[0];
    mw.config.get('wgPageName').includes('/') &&
var tempLink ='&#60; <a href="https://wiki.ekatrafoundation.org/wiki/' + tempPageName + '">' + tempPageName.replaceAll("_", " ") + '</a>';
    mw.config.get('skin') !== 'minerva'
$("#top").after(  $( '<p>').css( 'font-size', '17px').html( tempLink ) );
) {
}
 
    var tempPageName =
        mw.config.get('wgPageName').split('/')[0];
 
    var breadcrumb =
        $('<div>')
            .addClass('ekatra-breadcrumb')
            .css({
                'font-size': '17px',
                'margin-bottom': '8px'
            });
 
    breadcrumb.html(
        '&lt; <a href="/index.php/' +
        tempPageName +
        '">' +
        tempPageName.replaceAll('_', ' ') +
        '</a>'
    );
 
    $('#firstHeading').before(breadcrumb);
}
 
if( mw.config.get('wgUserName') === null  ){
if( mw.config.get('wgUserName') === null  ){
$('body').bind('cut copy', function(e) {
$('body').bind('cut copy', function(e) {
Line 75: Line 98:
mw.loader.load( '/index.php?title=MediaWiki:PoemButtons.js&action=raw&ctype=text/javascript');
mw.loader.load( '/index.php?title=MediaWiki:PoemButtons.js&action=raw&ctype=text/javascript');
}
}
if( $(".wikiaudioplayer").length ){
if( $(".wikiaudioplayer").length ){
Line 263: Line 287:




$( function(){
$(function () {
// toggled by toggle button. also determines which toggle button image to use
var useCustom = false;
var useCustom = false;
 
// toggleImgs[0] to switch to custom, toggleImgs[1] to revert to default
var zoomInSVG =
var toggleImgs = [
'<svg width="22" height="22" viewBox="0 0 24 24">' +
'//storage.googleapis.com/material-icons/external-assets/v4/icons/svg/ic_search_black_24px.svg',
'<path d="M15.5 14h-.8l-.3-.3a6.5 6.5 0 1 0-.7.7l.3.3v.8L20 21.5 21.5 20z ' +
'//storage.googleapis.com/material-icons/external-assets/v4/icons/svg/ic_youtube_searched_for_black_24px.svg'
'M10 14a4 4 0 1 1 0-8 4 4 0 0 1 0 8z ' +
];
'M11 7H9v2H7v2h2v2h2v-2h2V9h-2z"/>' +
var zoomInImg = '//storage.googleapis.com/material-icons/external-assets/v4/icons/svg/ic_zoom_in_black_24px.svg';
'</svg>';
var zoomOutImg = '//storage.googleapis.com/material-icons/external-assets/v4/icons/svg/ic_zoom_out_black_24px.svg';
 
var zoomOutSVG =
// create DOM elements
'<svg width="22" height="22" viewBox="0 0 24 24">' +
$('#content').prepend('<div id="zoomButtons" style="z-index: 9999;">\
'<path d="M15.5 14h-.8l-.3-.3a6.5 6.5 0 1 0-.7.7l.3.3v.8L20 21.5 21.5 20z ' +
<img id="zoomInIcon" src="' + zoomInImg + '" alt="zoom in"">\
'M7 9h6v2H7z"/>' +
<img id="zoomOutIcon" src="' + zoomOutImg + '" alt="zoom out"">\
'</svg>';
<img id="toggleButton" src="' + toggleImgs[+ useCustom] + '" alt="toggle zoom">&nbsp</div>');
 
$('#zoomButtons').css({'float': 'right'});
var toggleSVG =
'<svg width="22" height="22" viewBox="0 0 24 24">' +
// find DOM elements used later
'<path d="M5 4h14v2H5zm4 4h6l-2 12h-2z"/>' +
'</svg>';
 
$('#content').prepend(
'<div id="zoomButtons" style="z-index:9999; float:right; display:flex; gap:2px; cursor:pointer;">' +
'<span id="zoomInIcon">' + zoomInSVG + '</span>' +
'<span id="zoomOutIcon">' + zoomOutSVG + '</span>' +
'<span id="toggleButton">' + toggleSVG + '</span>' +
'</div>'
);
 
var $bodyContent = $('.mw-body-content');
var $bodyContent = $('.mw-body-content');
var $toggleButton = $('#toggleButton');
 
var sizes = [parseFloat($bodyContent.css('font-size'))];
// sizes[0] is default, sizes[1] is custom
var sizes = [parseFloat($('.mw-body-content').css('font-size'))];
// default custom zoom of 2
sizes[1] = sizes[0] + 2;
sizes[1] = sizes[0] + 2;
 
// the + converts bool to 0 or 1 to use as array index
function updateSize() {
function updateSize() {
$bodyContent.css({'font-size':(sizes[+ useCustom] + 'pt')});
$bodyContent.css('font-size', sizes[+useCustom] + 'pt');
}
}
function toggle() {
function toggle() {
useCustom = !useCustom;
useCustom = !useCustom;
$toggleButton.attr('src',toggleImgs[+ useCustom]);
updateSize();
updateSize();
}
}
function zoom(dif) {
function zoom(dif) {
sizes[1] += dif;
sizes[1] += dif;
Line 308: Line 338:
}
}
}
}
 
$( '#zoomInIcon' ).on( 'click', function(){
$('#zoomInIcon').on('click', function () {
console.log("Zoom +");
zoom(1);
zoom(1);
});
});
 
$( '#zoomOutIcon' ).on( 'click', function(){
$('#zoomOutIcon').on('click', function () {
console.log("Zoom -");
zoom(-1);
zoom(-1);
});
});
 
$( '#toggleButton' ).on( 'click', toggle );
$('#toggleButton').on('click', toggle);
});
});




Line 697: Line 726:
});
});


if (mw.user.isAnon() === true) { // Check if the user is anonymous
// Wait for the mediawiki.user module to load
    $(function () {
mw.loader.using('mediawiki.user').then(function() {
        $('.ext-wikisource-download-button').hide(); // Hide the button for anonymous users
    // Now mw.user.isAnon() exists safely
    });
    if (mw.user.isAnon()) {
}
        // Wait until the DOM is ready
        $(function() {
            $('.ext-wikisource-download-button').hide();
        });
    }
});




Line 779: Line 813:
         }
         }
     });
     });
});
// ==UserScript==
// @name        MediaWiki Smart Single Quotes
// @namespace    http://your.local/
// @version      1.0
// @description  Convert straight single quotes to typographic single quotes on MediaWiki pages (visual only).
// @match        https://ekatra-wiki.eastus2.cloudapp.azure.com/*
// @grant        none
// ==/UserScript==
(function () {
    'use strict';
    function convertSingleQuotesText(text) {
        if (!text || text.indexOf("'") === -1) return text;
        text = text.replace(/([A-Za-z0-9])'([A-Za-z0-9])/g, "$1’$2"); // contractions/possessives
        text = text.replace(/(^|[\s\(\[\{\<\u2014\u2013"“'«])'(?=\S)/g, "$1‘"); // opening quotes
        text = text.replace(/'/g, "’"); // remaining closing quotes
        return text;
    }
    function walkAndReplace(root) {
        if (!root) return;
        try {
            var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
            var n;
            var blacklist = new Set(["CODE", "PRE", "SCRIPT", "STYLE", "TEXTAREA", "NOSCRIPT", "MATH", "INPUT"]);
            while ((n = walker.nextNode())) {
                var parent = n.parentNode;
                if (!parent) continue;
                var anc = parent, skip = false;
                while (anc && anc.nodeType === 1) {
                    if (blacklist.has(anc.nodeName)) { skip = true; break; }
                    anc = anc.parentNode;
                }
                if (skip) continue;
                var orig = n.nodeValue;
                var rep = convertSingleQuotesText(orig);
                if (rep !== orig) n.nodeValue = rep;
            }
        } catch (e) {
            console.error('smartQuotes error', e);
        }
    }
    function applyOnce() {
        var root = document.querySelector('.mw-parser-output') || document.body;
        walkAndReplace(root);
    }
    // run after window.load, also watch for AJAX content
    window.addEventListener('load', function () {
        setTimeout(applyOnce, 150);
        var obs = new MutationObserver(function (mutations) {
            mutations.forEach(function (m) {
                m.addedNodes && m.addedNodes.forEach(function (n) {
                    if (n.nodeType === 1) walkAndReplace(n);
                    else if (n.nodeType === 3 && n.parentNode) walkAndReplace(n.parentNode);
                });
            });
        });
        obs.observe(document.body, { childList: true, subtree: true });
    }, false);
})();
/*--------------------------------------------------21-05-2026---------------------------*/
/* Remove Convert Numerals from mobile menu */
mw.loader.using( ['mediawiki.util'] ).then( function () {
    function removeNumeralMenu() {
        // Mobile only
        if ( mw.config.get('skin') !== 'minerva' ) {
            return;
        }
        // Remove menu item
        $('#pt-numconvert').remove();
    }
    // Run multiple times because gadget loads late
    $(document).ready(function () {
        removeNumeralMenu();
        setTimeout(removeNumeralMenu, 1000);
        setTimeout(removeNumeralMenu, 2000);
        setTimeout(removeNumeralMenu, 4000);
    });
});
/*--------------------------------------------------21-05-2026---------------------------*/
/*
*
* ---------------------------------------------------------
* Ekatra Wiki - Breadcrumb + Heading Handling
* ---------------------------------------------------------
*/
$(document).ready(function () {
var breadcrumb = $('.ekatra-breadcrumb').first();
    var heading = $('#firstHeading');
    if (!breadcrumb.length || !heading.length) {
        return;
    }
    var breadcrumbText = breadcrumb.text().trim()
        .replace(/^<\s*/, '');
    var headingText = heading.text().trim();
    // Extract first path part
    var headingRoot = headingText.split('/')[0].trim();
    // SAME ROOT PAGE
    if (breadcrumbText === headingRoot) {
        heading.hide();
        breadcrumb.css({
            'border-bottom': 'none',
            'margin-bottom': '0',
            'padding-bottom': '0'
        });
    }
    // DIFFERENT ROOT
    else {
        breadcrumb.css({
            'border-bottom': '1px solid #a2a9b1',
            'padding-bottom': '8px',
            'margin-bottom': '12px'
        });
    }
});
/*----------------------------------25-05-2026-------------------------------*/
$(function () {
    // Wait until page fully loads
    setTimeout(function () {
        // Avoid duplicate icon
        if ($('#custom-share-icon').length) {
            return;
        }
        // Create share icon
        const shareIcon = $(`
    <span id="custom-share-icon"
        class="minerva-icon minerva-icon--share"
        style="
            cursor:pointer;
            width:32px;
            height:32px;
            display:inline-flex;
            align-items:center;
            justify-content:center;
        ">
    </span>
`);
        /* Desktop */
        if ( mw.config.get('skin') !== 'minerva' ) {
            $('#toggleButton').after(shareIcon);
        }
        /* Mobile */
        else {
            var shareLi = $('<li class="page-actions-menu__list-item" id="custom-share-li">')
                .append(shareIcon);
            // If 3-dot menu exists
            if ($('#page-actions-overflow').length) {
                $('#page-actions-overflow').closest('li').before(shareLi);
            }
            // Fallback for logged-out users
            else {
                $('.page-actions-menu__list').append(shareLi);
            }
        }
        // Trigger original share button
        /*$('#custom-share-icon').on('click', function () {
            $('#top-share-button button').trigger('click');
        });*/
       
        $('#custom-share-icon').on('click', function () {
    // Mobile
    if (mw.config.get('skin') === 'minerva') {
        $('#top-share-button button').trigger('click');
    }
    // Desktop
    else {
        if (navigator.share) {
            navigator.share({
                title: document.title,
                url: window.location.href
            });
        } else {
            navigator.clipboard.writeText(window.location.href);
            alert('Page link copied');
        }
    }
});
        // Hide original floating share button ONLY
        $('#top-share-button').hide();
    }, 500);
});
/*-------------------------------------swati---------------------------*/
mw.hook('wikipage.content').add(function () {
    if (
        mw.config.get('skin') !== 'minerva' ||
        mw.config.get('wgPageName') !== 'એકત્ર_ગ્રંથાલય' ||
        window.innerWidth > 768
    ) {
        return;
    }
    var section = $('.mf-section-0');
    // Target paragraph
    var firstText = section.children('p').filter(function () {
        return $(this).text().trim().length > 100;
    }).first();
    // Table block
    var tableBlock = section.children('table').first();
    if (tableBlock.length && firstText.length) {
        // Move BEFORE browser fully paints
        firstText.insertAfter(tableBlock);
    }
});
/*-------------------------------------Chirag---------------------------*/
/* Homepage mobile order final */
$(document).ready(function () {
    if (
        mw.config.get('skin') === 'minerva' &&
        mw.config.get('wgIsMainPage') &&
        $(window).width() <= 768
    ) {
        var section = $('.mf-section-0');
        // Ignore empty <p> and <p><br></p>
        var firstText = section.children('p').filter(function () {
            return $.trim($(this).text()).length > 50;
        }).first();
        var videoBlock = section.children('figure').eq(0);
        var logoBlock = section.children('figure').eq(1);
        var arrowBlock = section.find('.heading-detail-page').first();
        // Order:
        // 1 Video
        // 2 Logo
        // 3 Arrows
        // 4 Text
        if (videoBlock.length && logoBlock.length) {
            videoBlock.after(logoBlock);
        }
        if (logoBlock.length && arrowBlock.length) {
            logoBlock.after(arrowBlock);
        }
        if (arrowBlock.length && firstText.length) {
            arrowBlock.after(firstText);
        }
    }
});
/*-------------------------------------Chirag---------------------------*/
$(document).ready(function () {
    if (
        mw.config.get('skin') === 'minerva' &&
        mw.config.get('wgIsMainPage') &&
        $(window).width() <= 768
    ) {
        var section = $('.mf-section-0');
        // REMOVE EMPTY P TAGS
        section.children('p').each(function () {
            if ($.trim($(this).text()) === '') {
                $(this).remove();
            }
        });
        // REAL TEXT ONLY
        var firstText = section.children('p').filter(function () {
            return $.trim($(this).text()).length > 50;
        }).first();
        var videoBlock = section.children('figure').eq(0);
        var logoBlock = section.children('figure').eq(1);
        var arrowBlock = section.find('.heading-detail-page').first();
        if (videoBlock.length && logoBlock.length) {
            videoBlock.after(logoBlock);
        }
        if (logoBlock.length && arrowBlock.length) {
            logoBlock.after(arrowBlock);
        }
        if (arrowBlock.length && firstText.length) {
            arrowBlock.after(firstText);
        }
    }
});
/*-----------------------------------------28-05-2026--------------------------------*/
/*--------------------------------------swati---------------------------------------*/
/* hide sub suggestion in global searchbox */
/*$(function () {
    function removeSubpageResults() {
        // Old search suggestions
        $('a.mw-searchSuggest-link').each(function () {
            var title = $(this).attr('title') || '';
            if (title.indexOf('/') !== -1) {
                $(this).hide();
            }
        });
        // Mobile overlay suggestions
        $('.cdx-menu-item').each(function () {
            var title = $(this).attr('title') || $(this).text();
            if (title.indexOf('/') !== -1) {
                $(this).hide();
            }
        });
    }
    // Run once
    removeSubpageResults();
    // Run instantly when suggestions are added
    new MutationObserver(removeSubpageResults).observe(document.body, {
        childList: true,
        subtree: true
    });
});
*/
/* hide sub suggestion in search page */
/*$(document).ready(function () {
    // Inject CSS instantly
    $('head').append(`
        <style>
            .oo-ui-menuOptionWidget.subpage-hidden {
                display: none !important;
            }
        </style>
    `);
    function hideSubSuggestions() {
        $('.oo-ui-menuOptionWidget').each(function () {
            var text = $(this).text().trim();
            // Hide subpages containing "/"
            if (text.includes('/')) {
                $(this).addClass('subpage-hidden');
            }
        });
    }
    // Watch dropdown continuously
    const observer = new MutationObserver(function () {
        hideSubSuggestions();
    });
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
    hideSubSuggestions();
});
*/
/*$(document).ready(function () {
    // Override broken REST API search
    if (mw.config.get('skin') === 'minerva') {
        $(document).on('focus keyup', 'input[type="search"]', function () {
            // Replace REST API endpoint with old api.php
            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    if (
                        settings.url &&
                        settings.url.indexOf('/rest.php/v1/search/title') !== -1
                    ) {
                        settings.url =
                            mw.util.wikiScript('api') +
                            '?action=query&format=json&formatversion=2' +
                            '&generator=prefixsearch' +
                            '&gpsnamespace=0&gpslimit=50';
                    }
                }
            });
        });
    }
});
*/
/*
$(function () {
    function cleanSearchSuggestions() {
        $('.oo-ui-menuOptionWidget').each(function () {
            if ($(this).text().indexOf('/') !== -1) {
                $(this).hide();
            }
        });
        $('.oo-ui-menuSelectWidget').css({
            'height': 'auto',
            'max-height': 'none',
            'overflow-y': 'hidden'
        });
    }
    new MutationObserver(cleanSearchSuggestions).observe(document.body, {
        childList: true,
        subtree: true
    });
});
*/
/*--------------------------------------chirag---------------------------------------*/
$(function () {
    $('video[src*="Ekatra_Logo.mp4"]').attr(
        'poster',
        'https://wiki.ekatrafoundation.org/static/Ekatra-Poster.png'
    );
});
/*----------------------------5-6-2026---------------------------------------*/
$(function () {
    if (mw.config.get('skin') !== 'minerva') {
        return;
    }
    var title = mw.config.get('wgTitle') || '';
    if (title.indexOf('/') !== -1) {
        $('head').append(
            '<style>@media only screen and (max-width:767px){#firstHeading{display:none!important;}}</style>'
        );
    }
});
/*----------------------------8-6-2026---------------------------------------*/
$(function () {
    if (mw.config.get('skin') !== 'minerva') {
        return;
    }
    var title = $('p').filter(function () {
        return $(this).text().trim() === 'કાવ્ય, ભજન';
    }).first();
    var booksHeading = $('.wst-center.tiInherit').first();
    if (title.length && booksHeading.length) {
        title.insertAfter(booksHeading);
    }
});
/*---------------------------22-06-2026---------------------------------------*/
$(function () {
    $('.ekatra-right-author').each(function () {
        // Remove blank <p> inside Poem2 after author
        $(this).nextAll('p').each(function () {
            var html = $.trim($(this).html());
            if (html === '' || html === '<br>' || html === '<br/>' || html === '<br />') {
                $(this).remove();
            } else {
                return false;
            }
        });
        // Remove blank <p><br></p> after Poem2 block
        var p = $(this).closest('.Poem2-Ekatra').next('p');
        if (p.length && p.find('br').length) {
            p.remove();
        }
    });
});
/*-----------------------------------------01-07-2026-------------------------------------------*/
/* Keep WikiEditor toolbar sticky below the Ekatra toolbar */
$(function () {
    function stickyToolbar() {
        var $toolbar = $('.wikiEditor-ui-top');
        if (!$toolbar.length) {
            return;
        }
        $toolbar.css({
            position: 'sticky',
            top: $('#editpage-specialchars').outerHeight() + 'px',
            zIndex: 999,
            background: '#fff'
        });
        clearInterval(timer);
    }
    var timer = setInterval(stickyToolbar, 100);
    $(window).on('resize', stickyToolbar);
});
/*----------------------------------08-07-2026----------------------------------*/
/* Remove blank <p><br></p> after Author template without removing TemplateStyles */
$(function () {
    $('.ekatra-author').next('p').each(function () {
        var $p = $(this);
        // Move TemplateStyles outside the paragraph
        $p.children('style[data-mw-deduplicate]').each(function () {
            $(this).insertBefore($p);
        });
        // Remove only <br>
        $p.children('br').remove();
        // Remove the paragraph only if it is now empty
        if (
            $.trim($p.text()) === '' &&
            $p.children().length === 0
        ) {
            $p.remove();
        }
    });
});
});