Jump to content

MediaWiki:Common.js: Difference between revisions

From Systemicwiki contributors
No edit summary
No edit summary
 
Line 1: Line 1:
$( function () {
$( function () {
     // Colour the sidebar counts.
     if ( mw.config.get( 'wgAction' ) !== 'history' ) {
     document.querySelectorAll( 'a' ).forEach( function ( link ) {
        return;
         var match = link.textContent.trim().match(
    }
             /^(Account requests|Review requests) \((\d+)\)$/
 
         );
     document.querySelectorAll( '#pagehistory li' ).forEach( function ( row ) {
         var links = Array.from( row.querySelectorAll( 'a' ) );
 
        var approve = links.find( function ( link ) {
             return /^(approve|Approve this version)$/i.test(
                link.textContent.trim()
            );
        } );
 
        var talk = links.find( function ( link ) {
            return link.textContent.trim().toLowerCase() === 'talk';
         } );


         if ( !match ) {
         if ( !approve || !talk ) {
             return;
             return;
         }
         }


         var number = Number( match[ 2 ] );
         var url = new URL( talk.href, window.location.href );
         link.textContent = match[ 1 ] + ' ';
        url.searchParams.set( 'action', 'edit' );
        url.searchParams.set( 'section', 'new' );
         url.searchParams.set(
            'preloadtitle',
            'Review of ' + mw.config.get( 'wgPageName' ).replaceAll( '_', ' ' )
        );


         var count = document.createElement( 'span' );
         var request = document.createElement( 'a' );
         count.textContent = '(' + number + ')';
         request.href = url.toString();
         count.style.color = number > 0 ? '#c33' : '#36c';
         request.textContent = 'Request changes or suggest wording';
        link.appendChild( count );
    } );


    // Use plain language on page history screens.
         row.append( ' · ', request );
    if ( mw.config.get( 'wgAction' ) !== 'history' ) {
        return;
    }
 
    document.querySelectorAll( '#pagehistory a' ).forEach( function ( link ) {
        if ( link.textContent.trim() === 'prev' ) {
            link.textContent = 'Compare this change';
            link.title = 'See the earlier and newer wording side by side';
         } else if ( link.textContent.trim() === 'cur' ) {
            link.textContent = 'Compare with latest';
        }
     } );
     } );
    document.querySelectorAll( 'input[type="submit"], button[type="submit"]' )
        .forEach( function ( button ) {
            if ( button.value === 'Compare selected revisions' ) {
                button.value = 'Compare two selected versions';
            } else if ( button.textContent.trim() === 'Compare selected revisions' ) {
                button.textContent = 'Compare two selected versions';
            }
        } );
} );
} );

Latest revision as of 23:54, 26 September 2026

$( function () {
    if ( mw.config.get( 'wgAction' ) !== 'history' ) {
        return;
    }

    document.querySelectorAll( '#pagehistory li' ).forEach( function ( row ) {
        var links = Array.from( row.querySelectorAll( 'a' ) );

        var approve = links.find( function ( link ) {
            return /^(approve|Approve this version)$/i.test(
                link.textContent.trim()
            );
        } );

        var talk = links.find( function ( link ) {
            return link.textContent.trim().toLowerCase() === 'talk';
        } );

        if ( !approve || !talk ) {
            return;
        }

        var url = new URL( talk.href, window.location.href );
        url.searchParams.set( 'action', 'edit' );
        url.searchParams.set( 'section', 'new' );
        url.searchParams.set(
            'preloadtitle',
            'Review of ' + mw.config.get( 'wgPageName' ).replaceAll( '_', ' ' )
        );

        var request = document.createElement( 'a' );
        request.href = url.toString();
        request.textContent = 'Request changes or suggest wording';

        row.append( ' · ', request );
    } );
} );