Jump to content

User:Sohom Datta/PageTriageUserspaceLogger.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sohom Datta (talk | contribs) at 13:47, 6 November 2023 (Created page with '** * Untested, do not install: const standardError = 'If you are seeing this on enwiki, something is very wrong, ping {{ping|Sohom Datta}} or interface administators.'; function convertTagsToTwinkleFormat( tag ) { const { params } = tag; const keys = Object.keys(params); let templateParams = {}; for( var i = 0; i < keys.length; i++ ) { templateParams[keys[i]] = params[keys[i]].value; } return { normalized: tag[ 'cod...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/***
 * Untested, do not install
 */
 
 const standardError = 'If you are seeing this on enwiki, something is very wrong, ping {{ping|Sohom Datta}} or interface administators.';

function convertTagsToTwinkleFormat( tag ) {
    const { params } = tag;
    const keys = Object.keys(params);
    let templateParams = {};
    for( var i = 0; i < keys.length; i++ ) {
        templateParams[keys[i]] = params[keys[i]].value;
    }
    return { normalized: tag[ 'code' ].toLowerCase(), templateParams } 
} 

mw.loader.using( [ 'ext.gadget.Twinkle' ] ).then( function () {
    if ( !Twinkle ) {
        mw.notify( 'User:Sohom_Datta/PageTriageCSDLog.js requires twinkle to be installed on your wiki.' + standardError );
    }

    if ( !Twinkle.speedy ) {
        mw.notify( 'User:Sohom_Datta/PageTriageCSDLog.js requires the twinkle speedy deletion module to function correctly' + standardError );
    }
    mw.hook( 'ext.pageTriage.toolbar.ready' ).add( function ( queue ) {
        queue.add( 'delete', function ( data ) {
            const { tags } = data;
            const keys = Object.keys(tags);
            let twinkleParams = { normalizeds: [], templateParams: [] };
            for ( var i = 0; i < keys.length; i++ ) {
                const { normalizedTag, templateParams } = convertTagsToTwinkleFormat( tags[ keys[ i ] ] );
                twinkleParams.normalizeds.append( normalizedTag );
                twinkleParams.normalizeds.append( templateParams );
            }

            Twinkle.speedy.addToLog( twinkleParams, data.creator );
        } );
    } );
} );