Jump to content

MediaWiki:Common.js: Difference between revisions

From Systemicwiki contributors
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
$( function () {
$( function () {
     document.querySelectorAll( 'a' ).forEach( function ( link ) {
    if ( mw.config.get( 'wgAction' ) !== 'history' ) {
         var match = link.textContent.trim().match(
        return;
             /^(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 label = match[ 1 ];
         var url = new URL( talk.href, window.location.href );
         var number = Number( match[ 2 ] );
         url.searchParams.set( 'action', 'edit' );
 
         url.searchParams.set( 'section', 'new' );
         link.textContent = label + ' ';
        url.searchParams.set(
 
            'preloadtitle',
        var count = document.createElement( 'span' );
            'Review of ' + mw.config.get( 'wgPageName' ).replaceAll( '_', ' ' )
        );


         if ( number === 0 ) {
         var request = document.createElement( 'a' );
            count.textContent = '(0)';
         request.href = url.toString();
            count.style.cssText =
         request.textContent = 'Request changes or suggest wording';
                'color:#36c !important;background:transparent !important;' +
                'font-weight:normal !important;padding:0 !important;' +
                'border-radius:0 !important;display:inline !important;';
         } else if ( label === 'Account requests' ) {
            count.textContent = String( number );
            count.style.cssText =
                'display:inline-block;margin-left:7px;padding:1px 6px;' +
                'border-radius:12px;background:#c33;color:white;' +
                'font-size:12px;font-weight:bold;line-height:1.5;';
         } else {
            count.textContent = '(' + number + ')';
            count.style.cssText = 'color:#c33;font-weight:bold;';
        }


         link.appendChild( count );
         row.append( ' · ', request );
     } );
     } );
} );
} );

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 );
    } );
} );