MediaWiki:Gadget-TheOfficialiserTM.js

From SmashWiki, the Super Smash Bros. wiki
Revision as of 21:38, March 31, 2024 by Toomai (talk | contribs) (this should fix infobox images being killed (also standardised to tabs))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function getRandomDongle() {
	var randomDongles = ["","®","™","®™","™®"];
	return randomDongles[Math.floor(Math.random()*randomDongles.length)];
}

function af2024(node,articleName,specifier,canTagline) {
	var text = node.textContent;
	if (!text || text === "\n") {
		return;
	}
	var tagline = "from SmashWiki, the Super Smash Bros. wiki";
	var extraTagline = "from SmashWiki, the Super Smash Bros. wiki that anyone can edit";
	if (specifier !== null) {
		node.textContent = 'The "'+text+'"'+getRandomDongle()+' '+specifier;
	} else {
		node.textContent = text+getRandomDongle();
	}
	if (articleName !== null && Math.random() > 0.75) {
		node.textContent += ' of the "'+articleName+'"'+getRandomDongle()+' SmashWiki article';
	}
	var tagRandom = Math.random();
	if (!canTagline) {
		tagRandom = 0;
	}
	if (tagRandom > 0.95) {
		node.textContent += " "+extraTagline;
	} else if (tagRandom > 0.75) {
		node.textContent += " "+tagline;
	}
}

var articleName = document.querySelectorAll("#firstHeading")[0].textContent;
document.querySelectorAll("#firstHeading").forEach(function(node) {
	af2024(node,null,"SmashWiki article",true);
});
document.querySelectorAll(".mw-headline").forEach(function(node) {
	af2024(node,articleName,"section",true);
});
document.querySelectorAll(".infobox th").forEach(function(node) {
	af2024(node,null,null,false);
});
document.querySelectorAll(".infobox td > b").forEach(function(node) {
	af2024(node,null,null,false);
});
document.querySelectorAll("#pt-userpage > a").forEach(function(node) {
	af2024(node,null,"user",false);
});