Jump to content

User:Aidan9382/scripts/citation-error-banner.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Add alert to the top when there are citation maintanence or error messages (Like in show preview, yet more hackily coded)

var maintCount = document.getElementsByClassName("cs1-maint").length;
var errorCount = document.getElementsByClassName("error").length;
var CS1errorCount = document.getElementsByClassName("cs1-visible-error").length + document.getElementsByClassName("cs1-hidden-error").length;
if (errorCount + CS1errorCount > 0 && document.getElementById("bodyContent") && !document.getElementById("wikiPreview")) {
	var notice = document.createElement("div");
	notice.className = "mw-message-box mw-message-box-warning";
	var finalText = "<span style='float:right'>X</span>";
	if (errorCount > 0) {
		finalText += "<p>"+errorCount+" <span style=\"color:#d33\"><b>strong error message(s)</b></span> are present</p>";
	}
	if (CS1errorCount > 0) {
		finalText += "<p>"+CS1errorCount+" <span style=\"color:#d33\">error message(s)</span> are present</p>";
	}
	if (maintCount > 0) {
		finalText += "<p>"+maintCount+" <span style=\"color:#3a3\">maintenance message(s)</span> are present</p>";
	}
	notice.innerHTML = finalText+"<a href=\"#References\">→ Go to references</a>";
	notice.firstChild.onclick = function(){notice.remove();};
	var bc = document.getElementById("bodyContent");
	bc.insertBefore(notice,bc.children[0]);
}