User:Documentalist/StyleGuardRules.js

/***************************************************************************************** Style Guard Rules /* Rule: Every WikiaPage shall have a category. function ApplyRule1 { var URL = document.URL; console.log(URL); var Exception = false /*Special page.*/ || (URL.substr(0, 43) == "http://elderscrolls.wikia.com/wiki/Special:") /*User talk page.*/ || (URL.substr(0, 45) == "http://elderscrolls.wikia.com/wiki/User_talk:") /*Edit page.*/ || (Search("?action=edit", URL)) /*Forum board page.*/ || (URL.substr(0, 41) == "http://elderscrolls.wikia.com/wiki/Board:") /*Forum thread page.*/ || (URL.substr(0, 42) == "http://elderscrolls.wikia.com/wiki/Thread:") /*User subpage.*/ || (URL.substr(0, 40) == "http://elderscrolls.wikia.com/wiki/User:") && Search("/", URL.substr(40)) /*Style page.*/ || (URL.substr(URL.length - 4) == ".css") /*Script page.*/ || (URL.substr(URL.length - 3) == ".js"); return ! Exception; } function CheckRule1(Message) { var Categories = document.getElementById("WikiaArticleCategories"); var Success = (Categories != null); Message.style.position = "relative"; Message.style.width = "100%"; if (Success) { Message.appendChild(document.createTextNode("This page has at least one category.")); Message.style.color = "green"; } else { Message.appendChild(document.createTextNode("This page has no category.")); Message.style.color = "red"; } return Success; } /* Rule: Every WikiaPage shall have no links to redirection pages. function ApplyRule2 { var URL = document.URL; console.log(URL); return (Search("\?action=edit", URL) == false); } function CheckRule2(Message) { var Redirects = document.getElementsByClassName("mw-redirect"); for (var i = 0; i != Redirects.length; ++i) Redirects[i].style.background = "red"; var Success = (Redirects.length == 0); Message.style.position = "relative"; Message.style.width = "100%"; if (Success) { Message.appendChild(document.createTextNode( "This page has no links to redirection pages.")); Message.style.color = "green"; } else { Message.appendChild(document.createTextNode("This page has " + Redirects.length.toString + " links to redirection pages." +     " Style Guard highlighted these links with a red background.")); Message.style.color = "red"; } return Success; }