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 var VersionNumber = "0.4+"; //importArticle({type: "script", article:"User:Documentalist/Utilities.js"}); /*Ruler--- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

/***************************************************************************************** Ultitilies /*--*/ function CreateAttribute(Name, Value) { var Att = document.createAttribute(Name); Att.value = Value; return Att; } /*--*/ function GetCookie(Name) { var Value = document.cookie; var Start = Value.indexOf(" " + Name + "="); if (Start == -1) { Start = Value.indexOf(Name + "="); } if (Start == -1) { Value = null; } else { Start = Value.indexOf("=", Start) + 1; var End = Value.indexOf(";", Start); if (End == -1) { End = Value.length; }   Value = unescape(Value.substr(Start, End - Start)); } return Value; } /*--*/ function Search(SearchThis, In) { for (var Index = 0; Index < In.length; ++Index) { if (In.substr(Index, SearchThis.length) == SearchThis) return true; } return false; } /*--*/ function SetCookie(Name, Value, ExpiryDays) { var ExpiryDate = new Date; ExpiryDate.setDate(ExpiryDate.getDate + ExpiryDays); var CookieValue = escape(Value) + ((ExpiryDays == null)? "": "; expires="+ExpiryDate.toUTCString); document.cookie= Name + "=" + CookieValue; }

//importArticle({type: "script", article:"User:Documentalist/StyleGuardRules.js"}); /*Ruler--- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

/***************************************************************************************** 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; }

/*======================================================================================== Event Handlers

=
===========================================================================*/ var Icon = document.createElement("IMG"); Icon.setAttributeNode(CreateAttribute( "src", "http://static3.wikia.nocookie.net/elderscrolls/images/7/73/Transparent_bulldog.png")); Icon.style.position = "relative"; Icon.style.cssFloat = "right"; Icon.style.height = "32px"; Icon.style.width = "32px";

//var Tooltip = document.createElement("DIV"); //Tooltip.style.display = "hidden"; //Tooltip.style.background = "#7F7F3F"; //Tooltip.style.position = "absolute"; //Tooltip.style.left = "16px"; //Tooltip.style.top = "16px"; //Tooltip.style.zIndex = "1000"; //Tooltip.style.minWidth = "170px"; //Tooltip.style.height = "auto"; //Tooltip.style.padding = "5px"; //Tooltip.style.color = "black"; //Tooltip.innerHTML = "Style GuardCurrent mode: Auto ExpandClick to change.";

var OptionDisabled = document.createElement("OPTION"); OptionDisabled.setAttributeNode(CreateAttribute("value", "disabled")); OptionDisabled.innerHTML = "Disabled";

var OptionCollapsed = document.createElement("OPTION"); OptionCollapsed.setAttributeNode(CreateAttribute("value", "collapsed")); OptionCollapsed.innerHTML = "Collapsed";

var OptionExpanded = document.createElement("OPTION"); OptionExpanded.setAttributeNode(CreateAttribute("value", "expanded")); OptionExpanded.innerHTML = "Expanded";

var OptionAutomatic = document.createElement("OPTION"); OptionAutomatic.setAttributeNode(CreateAttribute("value", "automatic")); OptionAutomatic.innerHTML = "Automatic";

var Mode = document.createElement("SELECT"); Mode.setAttributeNode(CreateAttribute("name", "mode")); Mode.appendChild(OptionDisabled); Mode.appendChild(OptionCollapsed); Mode.appendChild(OptionExpanded); Mode.appendChild(OptionAutomatic); Mode.onchange=function{ModeOnChange};

var Control = document.createElement("FORM"); Control.style.display = "table"; Control.style.position = "relative"; Control.style.cssFloat = "left"; Control.style.width = "32px"; Control.style.height = "32px"; Control.style.borderWidth = "1px"; Control.style.borderStyle = "solid"; Control.style.borderColor = "yellow"; Control.appendChild(Icon); Control.appendChild(Mode); //Control.appendChild(Tooltip); //Control.onchange=function{ControlOnChange}; //Control.onclick=function{ControlOnClick};

/*--*/ function ControlOnClick { Control.style.width = "32px"; Control.style.height = "96px"; } /*--*/ function ControlOnMouseOver { console.log ("Begin of ControlOnMouseOver."); Tooltip.style.display = "table"; } /*--*/ function ControlOnMouseOut { console.log ("Begin of ControlOnMouseOut."); Tooltip.style.display = "none"; } /*--*/ function DocumentOnLoad { console.log ("Begin of DocumentOnLoad."); Tooltip.style.display = "table"; } /*--*/ function ModeOnChange { console.log ("Begin of ModeOnChange."); console.log (Mode.nodeValue); }

/*======================================================================================== Main

=
===========================================================================*/ console.log ("Begin of main."); var Cookie = GetCookie("CodeGuardMode"); if (Cookie == null) SetCookie("CodeGuardMode", "Auto expand"); console.log("Cookie: \"" + GetCookie("CodeGuardMode") + "\".");

var Success = true; var Message1; if (ApplyRule1) { Message1 = document.createElement("DIV"); Success = CheckRule1(Message1) && Success; } var Message2; if (ApplyRule2) { Message2 = document.createElement("DIV"); Success = CheckRule2(Message2) && 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")); } /*--Generate HTML---*/ var Title = document.createElement("H2"); Title.appendChild(document.createTextNode("Style Guard"));

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

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); if (typeof Message1 != "undefined") { StyleGuard.appendChild(Message1); } if (typeof Message2 != "undefined") { StyleGuard.appendChild(Message2); } StyleGuard.appendChild(Control);

var StyleGuardSpaceReservation = document.createElement("DIV"); StyleGuardSpaceReservation.style.position = "relative"; StyleGuardSpaceReservation.style.cssFloat = "right"; StyleGuardSpaceReservation.style.width = "15%"; StyleGuardSpaceReservation.style.height = "50px"; StyleGuardSpaceReservation.style.backgroundColor = "transparent"; 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(StyleGuard, WikiaPage); WikiaPage.parentNode.insertBefore(StyleGuardSpaceReservation, StyleGuard);