User:TimeMaster18/common.js

/** * Automatically uncheck the "Leave a redirect behind" button on the move page */ var inputObject = $('#wpLeaveRedirect > .oo-ui-inputWidget-input'); if (inputObject.length > 0) { inputObject[0]['checked'] = false; }

/** * Click Bold Feature with keybinding */ $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 'B'.charCodeAt(0)) {     console.log("Hey! Ctrl+B event captured!");    $("#wikiEditor-section-main > div.group.group-format > a[rel=bold]").click;    event.preventDefault;   } });

/** * Ctrl+S for Saving Page and for Uploading Page and for Moving Page */ $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 'S'.charCodeAt(0)) {     console.log("Hey! Ctrl+S event captured!");    $("input[name*='wpSave']").click;    $("input[name='wpUpload']").click;    $("button[name='wpMove']").click;    event.preventDefault;   } });

/** * Ctrl+D for confirming deleting Page */ $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 'D'.charCodeAt(0)) {     console.log("Hey! Ctrl+D event captured!");    $("#wpConfirmB").click;    event.preventDefault;   } });

/** * Replace selected text by keybinding via pure js CTRL+Q */ $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 'Q'.charCodeAt(0))   {    console.log("Hey! Ctrl+Q event captured!");    // obtain the object reference for the textarea>    var txtarea = document.getElementById("wpTextbox1");    // obtain the index of the first selected character    var start = txtarea.selectionStart;    // obtain the index of the last selected character    var finish = txtarea.selectionEnd;    //obtain all Text    var allText = txtarea.value;    // obtain the selected text    var sel = allText.substring(start, finish);    //append the text;    var newText=allText.substring(0, start)+""+sel.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase + txt.substr(1).toLowerCase;})+""+allText.substring(finish, allText.length);

txtarea.value=newText; console.log(newText); // do something with the selected content event.preventDefault; } });

/** * Replace selected text by keybinding via mw CTRL+P */ $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 'P'.charCodeAt(0)) {     console.log("Hey! Ctrl+P event captured!");    mw.toolbar.insertTags(,,'');    event.preventDefault;   } });

/** * API Purge * * Performs a purge with the API to avoid the confirmation form */ mw.loader.using( 'mediawiki.api' ).then( function {	$( '#ca-purge a' ).on( 'click', function( e ) { new mw.Api.post( {			action: 'purge',			titles: mw.config.get( 'wgPageName' )		} ).then( function {			location.reload;		}, function {			mw.notify( 'Purge failed', { type: 'error' } );		} ); e.preventDefault; } ); } );