MediaWiki:AjaxRedirect.js

/* * AjaxRedirect * @description Redirects the current page quickly. * @author Ozuzanna */

mw.loader.using([   'mediawiki.api',    'mediawiki.user' ], function {    var config = mw.config.get([ 'wgCanonicalNamespace', 'wgCanonicalSpecialPageName', 'wgPageName' ]);   if ( config.wgCanonicalNamespace === "Thread" || config.wgCanonicalSpecialPageName || window.AjaxRedirectLoaded ) {       return;    }

window.AjaxRedirectLoaded = true;

function respHandler(res) { if (res === true) { console.log('Redirect successfully made!'); new BannerNotification('Redirect successfully made!', 'confirm').show; setTimeout(function {               window.location.reload;            }, 3000); } else { console.log('Failed to edit page!'); new BannerNotification('Failed to edit page!', 'error').show; }   }

function click { var redir = prompt('Please enter the page you want to redirect to:');

if (!redir) { console.log('You need to specify the page to redirect to!'); return; }

new mw.Api.post({           action: 'edit',            watchlist: 'nochange',            title: config.wgPageName,            text: '#REDIRECT ' + redir.charAt(0).toUpperCase + redir.slice(1) + '',            token: mw.user.tokens.get('editToken')        }).done(function(d) {            respHandler(!d.error);        }).fail(function {            respHandler(false);        }); }

function init { $('#cosmos-actionsList-list').first.append(           $('').attr('id', 'ca-redirect').append( $('', {                   css: {                        cursor: 'pointer'                    },                    text: 'Ajax Redirect',                    click: click                }) )       );    }    init; });