User:Crispyshill/test.js

// Adds a link to the applications UI at the top of the page $('#p-vector-user-menu-overflow > .vector-menu-content > .vector-menu-content-list').prepend(''); $("#sh-citation-button-container").append('citationFixer ');

let portletOpen = false; let jsonData; // title is the location of the json which holds the recorded cites with their corresponding access levels let title = "User:Crispyshill/citationtable.json"; // This JQuery function grabs the JSON object from the file $.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title='+title, function(data){			   $('#bodyContent').append(' Supported Sites: ');			    // Adds to the end of each page each of the url's of the supported cites FOR TESTING ONLY, REMOVE FOR FINAL VERSION	data.forEach(x=>{ $('#bodyContent').append(' '+JSON.stringify(x.url)+' ');

})	// Saves the json object for further use	jsonData = data; });

// Controlls functionality when the UI button is pressed $("#sh-citation-button").click(=>{ if(portletOpen){	$(".sh-portlet").remove;	portletOpen = false; } else{ portletOpen = true; // working on portlet funcitonality $('#sh-citation-button-container').append(' '); $('.sh-portlet').append(' '); $("#sh-form").append(' Enter new source URL '); $("#sh-form").append(' '); $("#sh-form").append(' Enter access type '); $("#sh-form").append(' '); $(".sh-portlet").append('Update Database ');

}

});

function editPage( info ) { $.ajax({		url: mw.util.wikiScript( 'api' ),		type: 'POST',		dataType: 'json',		data: {			format: 'json',			action: 'edit',			title: info.title,			text: info.text, // will replace entire page content			summary: info.summary,			token: mw.user.tokens.get( 'csrfToken' )		}	}) .then (function( data ) {		if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {			alert( 'Page edited!' );		} else {			alert( 'The edit query returned an error. =(' );		}	})	.catch ( function { alert( 'The ajax request failed.' ); }); } $("#p-vector-user-menu-overflow > .vector-menu-content > .vector-menu-content-list").on('click', '#sh-button-add-to-json', function { $("#bodyContent").append(" Test "); if(confirm("Do you want to submit?")){ //	let myInfo = {"title": "This is my title", "text": "This is my new text"}; editPage({	title: mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title='+'User:Crispyshill/sandbox',	text: 'Cool! It works! :-) ' + '', summary: 'Trying to edit my sandbox using AJAX...' });	} });