User:Czar/delsort+findvgsources.js

// importScript( 'User:Enterprisey/delsort.js' ); // Backlink: User:APerson/delsort.js // Deletion sorting script, used to use WP:FWDS, see WikiProject Deletion sorting

// hook to change to  at relevant video game AfDs, by Enterprisey, see User talk:Enterprisey

window.delsortDoneHook = function { var SUMMARY = "Swapping the regular find sources template for the video game-specific one"; var VG_DELSORT_PAGE = "Wikipedia:WikiProject Deletion sorting/Video games";

$.getJSON(       mw.util.wikiScript('api'),        {            format: 'json',            action: 'query',            prop: 'revisions',            rvprop: 'content',            rvlimit: 1,            titles: mw.config.get( 'wgPageName' )        }    ).done( function (data) {        try {            var pageId = Object.keys(data.query.pages)[0];            wikitext = data.query.pages[pageId].revisions[0]['*'];

// Check if page has been delsorted into the video games list if( wikitext.indexOf( VG_DELSORT_PAGE ) >= 0 ) {

// Swap find sources template with the VG-specific one wikitext = wikitext.replace( "{{Find sources AFD|", "{{Find video game sources|" );

// Save page $.ajax( {                   url: mw.util.wikiScript( 'api' ),                    type: 'POST',                    dataType: 'json',                    data: {                        format: 'json',                        action: 'edit',                        title: mw.config.get( 'wgPageName' ),                        summary: SUMMARY,                        token: mw.user.tokens.get( 'csrfToken' ),                        text: wikitext                    }                } ).done ( function ( data ) {                    if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {                        mw.notify( "Find sources template swapped!" );                   } else {                        mw.notify( "Error swapping find sources template!" );                   }                } )            }        } catch ( e ) { mw.notify( "Error swapping find sources template!" ); console.log( "post-DELSORT content request error: " + e.message ); console.log( "post-DELSORT content request response: " + JSON.stringify( data ) ); }   } ); }; //