User:TheTechie/sandbox2

// mw.loader.load( 'User:TheTechie/tut.css', 'text/css' ); const archtml = ` Archive page  Yay `;

const smile = ` Send a smile to a user Publicly send a smile to this user? Yes No `;

importStylesheet( 'User:Mseingth2133444/mut.css' );

var wikitext;

function getText(title){ $.getJSON(	mw.util.wikiScript('api'),	{		format: 'json',		action: 'query',		prop: 'revisions',		rvprop: 'content',		rvlimit: 1,		titles: title	} ) .then(function ( data ) {		var page;		try {			for ( page in data.query.pages ) {				wikitext = data.query.pages[page].revisions[0]['*'];				return wikitext;			}		} catch ( e ) {			alert("An error occured")		}	}) .catch(function(err) {		alert("An error occured, namely: " + err);	}); }

function arcTo(input){ let toPage = input.value; let fromPage = mw.config.get('wgPageName'); alert("fromPage: " + fromPage + "; toPage:" + toPage); let text = getText(fromPage); alert("Text: " + text); summary = "Archiving page at " + fromPage + " using User:TheTechie/UserTools."; alert("Summary: " + summary); editPage(toPage, wikitext, summary); } function editPage(title, text, summary) { var api = new mw.Api; api.postWithToken("csrf", {		action: 'edit',		title: title,		text: text, // will replace entire page content		summary: summary	} ).done(function( data ) {		alert('Page edited!');	} ).fail( function(code, data) {		alert( api.getErrorMessage( data ).text);	} ); }

function arch{ $("#bodyContent").prepend(archtml); }

mw.loader.using( ['mediawiki.util', "mediawiki.api"], function {

// Wait for the page to be parsed $( document ).ready( function {         mw.util.addPortlet('p-tut', 'TUT', '#p-cactions');		arc = mw.util.addPortletLink('p-tut', '#', 'Arc');		mw.util.addPortletLink('p-tut', '#', 'TBD2');		$(arc).on("click", function(e){ arch; });   } ); } );

//