User:TheTechie/tut.js

// $(function{	version = [0, 0, 1]; // to get version number, join numbers with periods. For example, "0, 0, 1" is version 0.0.1	mw.loader.using(['mediawiki.util', "mediawiki.api"], function { class textBlocks { constructor{ this.smile = `

You've been smiled upon!
~				`;				this.teahouse = `

You're invited!
~				`;				this.warning1 = ` %warning% ~`; this.warning2 = ` %warning% ~`; this.warning3 = ` %warning% ~`; this.warning4 = "30px|alt=Stop icon %warning% ~";			}		}		class editSummaries {			constructor{				this.smile = "Sending this user a smile using TheTechie's User Tools";				this.archive = "Archiving this page using TheTechie's User Tools";				this.custom = "Using a custom warning created using TheTechie's User Tools";				this.teahouse = "Inviting this user to the Teahouse using TheTechie's User Tools";			}		}		blocks = new textBlocks;		es = new editSummaries;		function wait(secs) {			let msecs = secs * 1000;			setTimeout(function {        		location.reload;    		}, msecs);		}		function replacePage( info ) {			var api = new mw.Api;			api.postWithToken("csrf", {				action: 'edit',				title: info.title,				text: info.text, // will replace entire page content				summary: info.summary			} ).done(function( data ) {				alert("Done! This page will reload in a few seconds.");			} ).fail( function(code, data) {				alert(api.getErrorMessage(data).text);			} );		}		function appendToPage( info ) {			var api = new mw.Api;			api.postWithToken("csrf", {				action: 'edit',				title: info.title,				appendtext: info.text, // will not replace entire page content				summary: info.summary			} ).done(function( data ) {				alert("Done! This page will reload in a few seconds.");			} ).fail( function(code, data) {				alert(api.getErrorMessage(data).text);			} );		}		function smileAtUser{			if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User_talk') {				appendToPage({					title: mw.config.get('wgPageName'),					text: blocks.smile,					summary: es.smile				});				wait(3);			}			else {				alert("TUT: This option can only be used on user talk pages.");			}		}		function inviteToTeahouse{			if ( mw.config.get( 'wgCanonicalNamespace' ) === 'User_talk') {				appendToPage({					title: mw.config.get('wgPageName'),					text: blocks.teahouse,					summary: es.teahouse				});				wait(3);			}			else {				alert("TUT: This option can only be used on user talk pages.");			}		}		mw.util.addPortlet('p-ttut', 'TUT', '#p-cactions');		smile_button = mw.util.addPortletLink(portletId='p-ttut', href='#', text='Smile', tooltip="Send this user a smile");		$(smile_button).on("click", function(e) {			if (confirm("Publicly send a smile to this user?")) {				smileAtUser;			}			e.preventDefault;		});		teahouse = mw.util.addPortletLink(portletId='p-ttut', href='#', text='TH', tooltip="Invite this user to the Teahouse");		$(teahouse).on("click", function(e) {			if (confirm("Publicly send a Teahouse invitation to this user?")) {				inviteToTeahouse;			}			e.preventDefault;		});	}); }); //