User:Machine Maker/common.js

$('.tutorial-button').each(function(i, div) {	$(div).replaceWith('' + $(div).text + ' '); });

function startTutorial(num) { var api = new mw.Api; api.getToken('csrf').then(function(token) {		api.post({ action: 'edit', token: token, text: levels[String(num)].incorrect, title: 'User:' + mw.user.getName + '/tutorial' + num, summary: mw.user.getName + ' starts tutorial' + num }).then(function(res) { window.location.pathname = 'User:' + mw.user.getName + '/tutorial' + num; }).fail(function(err) { console.error(err); });	}).fail(function(err) {		console.error(err);	}); }

function checkTutorial(num) { var api = new mw.Api; api.getToken('csrf').then(function(token) {		api.get({ action: 'parse', page: 'User:' + mw.user.getName + '/tutorial' + num, prop: 'wikitext', format: 'json' }).then(function(res) { switch (String(num)) { case '1': var text = res.parse.wikitext['*']; if (text.includes('comon') || text.includes('txture') || text.includes('bocks')) alert('I think you missed one or two...'); else if (text.includes(levels['1'].correct)) { var r = confirm('Success! You fixed the errors!\n\nClick OK to move onto the next level!'); if (!r) return; console.log('startTutorial(2)'); } else console.log('incorrect!'); break; }		}).fail(function(err) { console.error(err) });	}); }

var levels = { '1': {		'incorrect': "=Tutorial Stage 1= \nYour job here will be to correct the 3 in the following \"page\". Click the 'Edit' button on the top of the page or the 'Edit' button to the right of the header! Click the I am done! button on the bottom of the page when you have finished!\n\n \n==Cobblestone==\nCobblestone is a comon block, obtained from mining stone. Its txture resembles block of stone with a largely cracked surface.\n\nMossy cobblestone is a variant of cobblestone with moss growing in its cracks. \nBoth bocks are mainly used for crafting or as building blocks.\n\n\n\nI am done! ",		'correct': "==Cobblestone==\nCobblestone is a common block, obtained from mining stone. Its texture resembles block of stone with a largely cracked surface.\n\nMossy cobblestone is a variant of cobblestone with moss growing in its cracks. \nBoth blocks are mainly used for crafting or as building blocks."	} };