User:Muhandes/sync-template-from-sandbox.js

$( function {   // 10 is "Template:" and 828 is "Module:"    if ( ( mw.config.get( "wgNamespaceNumber" ) === 10 || mw.config.get( "wgNamespaceNumber" ) === 828 ) && mw.config.get( "wgPageName" ).includes( "/sandbox" ) ) {        var link = mw.util.addPortletLink( "p-cactions", "#",           "Sync to main", "ca-sync", "Copy the sandbox code to the main template" );       mw.loader.using( "mediawiki.api", function  { link.addEventListener( "click", function {                var api = new mw.Api;                api.get( { prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: mw.config.get( "wgPageName" ) } ).done( function ( data ) { if ( !data.query || !data.query.pages ) return; var pageid = Object.getOwnPropertyNames( data.query.pages )[0], text = data.query.pages[pageid].revisions[0]["*"]; api.postWithEditToken( {                       action: "edit",                        title: mw.config.get( "wgPageName" ).replace( "/sandbox", "" ),                        summary: "Syncing sandbox to with main template",                        text: text                    } ).done ( function ( data ) {                        if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {                            mw.notify( "Synced successfully!" );                           window.setTimeout( function  {}, 5000 );                        }                    } ); } );           } );        } );    } } );