User:BEANS X2/vector.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. |
The accompanying .css page for this skin is at User:BEANS X2/vector.css. |
$(function() {
pageTitle = mw.config.values.wgCanonicalNamespace+":"+mw.config.values.wgTitle;
// [APPEARANCE] Custom styles for my userpage
if (pageTitle.split("/")[0] === "User:BEANS X2") {
var stylesheets = ["User:BEANS X2/Userpage/index.css","User:BEANS_X2/Userpage/mdl.css"];
$("#beans").css("display","block");
stylesheets.forEach(function(style) {
$.ajax({
url: "https://en.wikipedia.org/w/index.php?title="+style.replace("_"," ")+"&action=raw"
})
.done(function( data ) {
mw.util.addCSS(data);
});
});
}
// [UTILITY] Alt+click page title to fill it into Search
$("#firstHeading").on("click", function(ctx){
if(ctx.altKey) {
$("#searchInput")
.val(pageTitle)
.focus();
}
});
// [BETA] Enable bracket matching
mw.config.values.wgCodeMirrorEnableBracketMatching = true;
// [APPEARANCE] Make the "edit saved" popup a snackbar
if (mw.config.values.wgPostEdit == "saved") {
$(".postedit").hide(); // Hide the classic popup
var undoLastEdit = function() {
// Adapted from [[User:Enterprisey/undo-last-edit.js]]
var api = new mw.Api();
api.get( {
prop: 'revisions',
rvprop: 'content',
rvlimit: 2,
titles: mw.config.get( "wgPageName" )
} ).done( function ( data ) {
if ( !data.query || !data.query.pages ) return;
var pageid = Object.getOwnPropertyNames( data.query.pages )[0],
text = data.query.pages[pageid].revisions[1]["*"];
api.postWithToken( "csrf", {
action: "edit",
title: mw.config.get( "wgPageName" ),
summary: "Undoing my last edit [semi-automated]",
text: text
} ).done ( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
console.log("Edit undone")
document.location.reload( true );
}
} );
} );
}
waitForRW = setInterval( function() {
try{
var snackbarContainer = document.querySelector('#rw-toast');
var data = {
message: 'Edit saved',
timeout: 5000,
actionHandler: undoLastEdit,
actionText: 'Undo'
};
snackbarContainer.MaterialSnackbar.showSnackbar(data);
clearInterval(waitForRW)
}
catch(err){null}
},500)
}
// [UTILITY] Get the RPM easily
mw.util.addPortletLink( 'p-tb', '#0', 'View RPM').innerHTML = "<a href='#0' id='rpm-link'>↩️ View RPM</a>"
$("#rpm-link").on("click", function(ctx) {
$.getJSON("https://redwarn.toolforge.org/tools/rpmInfo.php").done( function(data) {
mw.notify("Reverts per minute: "+data[0].totalRPM)
})
})
// [UTILITY] "Silent pages" - Add a blacklist of pages to not be added to your watchlist.
var silentPages = ["Project:Sandbox"]
var allowedActions = ["edit","submit"]
if (silentPages.includes(pageTitle) && allowedActions.includes(wgAction)) {
$("#wpWatchthis").prop('checked', false);
}
console.log("Hello from user JS!");
});