User:StupendousStupdiity/common.js

// DATA / VARIABLES var CheckboxText = document.getElementById("CheckboxText"); var Checkbox = document.createElement('input'); var SpoiledBadges = ""; var BadgesList = [ "Se_hace_camino_al_andar", "The_World_as_an_Idea", "Sworn_Enemy_of_Reality", "Repercussions_of_Fissure", "Humble_Beginnings", "From_the_bottom_of_one's_heart", "Cautionary_Tale", "Stealth_Pilot", "Eye_of_The_Storm", "Death_Wielded", "Net_The_Creator", "Killing_Machine_1991", "Pie_Hiker", "5",   "Cycloid", "Each_day_better_than_the_last", "A_Painful_Temple", "What_Poets_Used_To_Know", "Final_Transmission", "Return_To_Axis", "More_of_This_Desolate_World", "Wary_Citizen", "The_Sickness_unto_Death", "Canon_but_improbable.", "Carried_Out_Exorcism", "Preternatural_Society", "Sunshower", ]; // END DATA / VARIABLES

// FUNCTIONS function HiddenIndicator(Text) {   var PageContent = document.getElementsByClassName("mw-parser-output"); var Indicator = document.createElement("div"); Indicator.innerHTML = "Some content on this page were hidden due to spoilers for the following badges:" + Text + " See Badges page to adjust these options."; Indicator.classList.add("HiddenSpoilerIndicator"); PageContent[0].insertBefore(Indicator,PageContent[0].firstChild); }

function ToggleCheckbox {   var DreamsphereData = localStorage.getItem("DreamsphereBadges"); if (Checkbox.checked == true) {       if (DreamsphereData) {           localStorage.setItem("DreamsphereBadges", DreamsphereData + "HideSpoilers"); }       else {           localStorage.setItem("DreamsphereBadges","HideSpoilers"); }   }    else {       var StringData = (localStorage.getItem("DreamsphereBadges")); StringData = StringData.replace("HideSpoilers",""); if (StringData == '') {           localStorage.removeItem("DreamsphereBadges"); }       else {           localStorage.setItem("DreamsphereBadges",StringData); }   } }

function BadgeChecklist(Badge) {   Identifier = (document.getElementById(Badge)); // Refers to the button if (localStorage.getItem("DreamsphereBadges")) // Checks if they already have this entry or not. {       var StringData = (localStorage.getItem("DreamsphereBadges")); if (StringData.match(Badge)) // Checks if they checked this badge {           Identifier.classList.remove("badgechecked"); StringData = StringData.replace(Badge,""); localStorage.setItem("DreamsphereBadges",StringData); Identifier.classList.add("badgeunchecked"); if (StringData == '') {               localStorage.removeItem("DreamsphereBadges"); // If the deletion makes the key blank, just delete it. }       }        else // If not, add it. {           Identifier.classList.remove("badgeunchecked"); Identifier.classList.add("badgechecked"); StringData = StringData + Badge; localStorage.setItem("DreamsphereBadges",StringData); }   }    else {       Identifier.classList.remove("badgeunchecked"); localStorage.setItem("DreamsphereBadges",Badge); // First creation with the badge added. Identifier.classList.add("badgechecked"); } }

// END FUNCTIONS

// PAGELOAD CODE BadgesList.forEach(function (Badge,_) {   var BadgeButton = (document.getElementById(Badge)); // Checks for buttons. Uses ID since there should be only one instance.    if (BadgeButton) {        BadgeButton.setAttribute("onclick","BadgeChecklist('" + Badge + "')");    }    if (localStorage.getItem("DreamsphereBadges") && localStorage.getItem("DreamsphereBadges").match(Badge) && BadgeButton)    {        BadgeButton.classList.remove("badgeunchecked");        BadgeButton.classList.add("badgechecked");    }    if (localStorage.getItem("DreamsphereBadges") && localStorage.getItem("DreamsphereBadges").match("HideSpoilers"))    {        var Spoiler = (document.getElementsByClassName(Badge + "Spoiler"));        if (Spoiler.length != 0 && localStorage.getItem("DreamsphereBadges").match(Badge)) // Hide items if localStorage doesn't have this badge        {}        else        {            for (i=0; i < Spoiler.length; i++) {               Spoiler[i].classList.add("spoilerhide"); if (NoRepeat == 0) {                   SpoiledBadges = (" - " + (Badge.replaceAll("_"," ")) + SpoiledBadges); NoRepeat = 1; }           }            NoRepeat = 0; }   } } );

// Checkbox creation for HideSpoilers toggle if (CheckboxText) {   Checkbox.type = 'checkbox'; // Enable/disable checkbox initial depending on if stuff was found or not. if (localStorage.getItem("DreamsphereBadges") && localStorage.getItem("DreamsphereBadges").match("HideSpoilers")); {       Checkbox.checked = true; }   Checkbox.setAttribute("onclick","ToggleCheckbox"); CheckboxText.insertBefore(Checkbox, CheckboxText.firstChild); }

// Indicator creation if content was hidden due to spoilers if (SpoiledBadges != "") {   HiddenIndicator(SpoiledBadges); }