User:Sophivorus/common.js

/* $( document ).on( 'click', '.wikidebate-add-objection-button a', function ( event ) {	event.preventDefault;

// Define the form var form = $( ' ' ); var input = $( ' ' ); var submit = $( ' Publish ' ); form.append( input, submit );

// Bind events submit.click( function {		var form = $( this ).closest( '.wikidebate-objection-form' );		var parent = form.closest( '.wikidebate-argument' );		var firstTextNode = parent.contents.filter( function  { return this.nodeType === Node.TEXT_NODE && this.nodeValue.trim; } ).first.text;		var parentDepth = parent.parents( 'li' ).length;		var objectionDepth = parentDepth + 1;		var inputText = form.find( '.wikidebate-objection-form-input' ).val;		var objectionText = '\n' + '*'.repeat( objectionDepth ) + ' ' + inputText;		var page = mw.config.get( 'wgPageName' );		new mw.Api.edit( page, function ( revision ) { var regexp = new RegExp( '(' + firstTextNode + '.*)' ); return revision.content.replace( regexp, '$1' + objectionText ); } ).then( function { // Reload the page to show the published objection to the user window.location.reload( true ); } ).fail( function ( errorCode ) { // Something went wrong } );	} );

// Add to the DOM var button = $( this ).parent; var item = $( '' ).html( form ); var objections = button.next; if ( objections.length ) { objections.prepend( item ); } else { var list = $( '' ).html( item ); button.after( list ); } } );