User:TheTechie/tut.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:TheTechie/tut and an accompanying .css page at User:TheTechie/tut.css. |
//<nowiki>
$(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 = `
<br>
==You've been smiled upon!==
{{subst:smile}} ~~~~
`;
this.teahouse = `
<br>
==You're invited!==
{{subst:Teahouse invitation}} ~~~~
`;
this.warning1 = `[[File:Information.svg|25px|alt=Information icon]] %warning% ~~~~`;
this.warning2 = `[[File:Information orange.svg|25px|alt=Information icon]] %warning% ~~~~`;
this.warning3 = `[[File:Nuvola apps important.svg|25px|alt=Warning icon]] %warning% ~~~~`;
this.warning4 = "[[[[File:Stop hand nuvola.svg|30px|alt=Stop icon]] %warning% ~~~~";
}
}
class editSummaries {
constructor(){
this.smile = "Sending this user a smile using [[User:TheTechie/tut|TheTechie's User Tools]]";
this.archive = "Archiving this page using [[User:TheTechie/tut|TheTechie's User Tools]]";
this.custom = "Using a custom warning created using [[User:TheTechie/tut|TheTechie's User Tools]]";
this.teahouse = "Inviting this user to the Teahouse using [[User:TheTechie/tut|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();
});
});
});
//</nowiki>