User:Documentalist/common.js

/*Ruler--- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

/*Object Browser.*/ //importArticle({type: "script", article:"User:Documentalist/Objects.js"}); //importArticle({type: "script", article:"User:Documentalist/ObjectBrowser.js"}); //importArticle({type: "script", article:"User:Documentalist/StyleGuard.js"}); /*Ruler--- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

/***************************************************************************************** Style Guard function CreateAttribute(Name, Value) { var Att = document.createAttribute(Name); Att.value = Value; return Att; } /* Rule: Every WikiaPage shall have a category. function CheckRule1(Message) { var Categories = document.getElementById("WikiaArticleCategories"); var Success = (Categories != null); Message = document.createElement("DIV"); 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 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= document.createElement("DIV"); 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; } /* Check the page. The result of this check is a overall flag Success and a message for each rule. var Success = true; console.log("1", Success); var Message1; Success = CheckRule1(Message) && Success; console.log("2", Success); var Message2; Success = CheckRule2(Message) && Success; console.log("3", Success);

/*Create the appropriate kind of dog.*/ var Dog; if (Success) { Dog = document.createElement("IMG"); Dog.setAttributeNode(CreateAttribute( "src", "http://static3.wikia.nocookie.net/elderscrolls/images/7/73/Transparent_bulldog.png")); Dog.setAttributeNode(CreateAttribute("height", "32px")); Dog.setAttributeNode(CreateAttribute("width", "32px")); Dog.style.position = "relative"; Dog.style.cssFloat = "right"; } else { Dog = document.createElement("IMG"); Dog.setAttributeNode(CreateAttribute( "src", "http://static2.wikia.nocookie.net/elderscrolls/images/0/0c/Transparent_mean_bulldog.png")); }

var Title = document.createElement("H2"); Title.appendChild(document.createTextNode("Style Guard"));

var Version = document.createElement("P"); Version.appendChild(document.createTextNode("version 0.2"));

var StyleGuard = document.createElement("DIV"); StyleGuard.style.position = "fixed"; StyleGuard.style.left = "86%"; StyleGuard.style.top= "57px"; StyleGuard.style.width = "14%"; StyleGuard.style.height = "auto"; StyleGuard.style.minHeight = "50px"; StyleGuard.style.backgroundColor = "black"; StyleGuard.setAttributeNode(CreateAttribute("id", "StyleGuard")); StyleGuard.appendChild(Dog); StyleGuard.appendChild(Title); StyleGuard.appendChild(Version); StyleGuard.appendChild(Message1); StyleGuard.appendChild(Message2);

var StyleGuardSpaceReservation = document.createElement("DIV"); StyleGuardSpaceReservation .style.position = "relative"; StyleGuardSpaceReservation .style.cssFloat = "right"; StyleGuardSpaceReservation .style.width = "15%"; StyleGuardSpaceReservation .style.height = "50px"; StyleGuardSpaceReservation .style.backgroundColor = "black"; StyleGuard.setAttributeNode(CreateAttribute("id", "StyleGuard-SpaceReservation"));

var WikiaPage = document.getElementById("WikiaPage"); WikiaPage.style.marginLeft = "0px"; WikiaPage.style.width = "85%"; WikiaPage.style.maxWidth = "1600px"; WikiaPage.parentNode.insertBefore(StyleGuardSpaceReservation, WikiaPage); WikiaPage.parentNode.insertBefore(StyleGuard, WikiaPage);