Jump to content

MediaWiki:Common.js: Difference between revisions

From Systemicwiki contributors
No edit summary
No edit summary
 
(4 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;
         }
         }


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


         count.style.cssText = match[ 1 ] === 'Review requests'
         var request = document.createElement( 'a' );
            ? 'color:#c33;font-weight:bold;'
        request.href = url.toString();
            : 'display:inline-block;margin-left:7px;padding:1px 6px;' +
        request.textContent = 'Request changes or suggest wording';
              'border-radius:12px;background:#c33;color:white;' +
              'font-size:12px;font-weight:bold;line-height:1.5;';


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