User:Borithel/wikia.js

// create darkmode on/off switch in page header $(function {     function getStyleSheet {        if($('link[rel=stylesheet][href*="darkmode.css"]').length === 0) {            importArticle({type: "style", article: "User:CephHunter/darkmode.css"});        }    }    var darkModeCookie = 'dark-mode-status';    if ($.cookie(darkModeCookie) === null) {        $.cookie(darkModeCookie, false, {expires:7, path:'/'});    }    var darkModeStatus = $.cookie(darkModeCookie) === "true";    function darkmode(status) {        if (status) {            $("#darkModeButton #greenBackground").animate({width: "100%"}, 200);            $.cookie(darkModeCookie, true, {expires:7, path:'/'});            getStyleSheet;            $('link[rel=stylesheet][href*="darkmode.css"]').prop('disabled', false);        } else {            $("#darkModeButton #greenBackground").animate({width: "57.5%"}, 200);            $.cookie(darkModeCookie, false, {expires:7, path:'/'}); $('link[rel=stylesheet][href*="darkmode.css"]').prop('disabled', true); }   }    //create the button var darkModeButton = $(" "); var dmSwitchMoving = $(" ").css({"background":"#262626", "border-radius":"5px", "height":"10px", "width":"23px", "position":"relative", "float":"right"}); var greenBackground = $(" ").append(dmSwitchMoving); var dmSwitchStationary = $(" ").css({"background":"red", "border":"solid 4px grey", "border-radius":"10px", "height":"10px", "width":"40px"}).append(greenBackground); $(darkModeButton).addClass("wds-button wds-is-squished wds-is-secondary").append(dmSwitchStationary) .css({"margin-left":"3px", "margin-right":"3px"}) .click(function {       darkModeStatus = $.cookie(darkModeCookie) === "true";        if(darkModeStatus) {            darkmode(false);        } else {            darkmode(true);        }    }); //add the button to the pages //normal buton $(".page-header__contribution-buttons").append(darkModeButton); //button on edit pages $(darkModeButton).clone(true).css({"display":"inline-block", "float":"left", "margin":"4px 5px 5px 0px"}).prependTo("#EditPageRail > div.module.module_page_controls .wpSummaryFields"); $('.EditPage .module_page_controls label[for="wpSummary"].wpSummary_canMinorEdit').css("margin-top", "0px"); //button on preview of edit pages $('.EditPage .module_page_controls .preview_box .preview_icon svg').click(function {       setTimeout( function { $(darkModeButton).clone(true).css({"float":"right", "margin":"12px 30px 0px 0px"}).insertAfter('.modalWrapper button'); if ($.cookie(darkModeCookie) === "true") { darkmode(true); }           }, 1000);    });        //button on user profile pages $(darkModeButton).clone(true).css({"float":"right", "margin":"0px 15px 0px 0px"}).appendTo("#WikiaUserPagesHeader > div > ul"); //auto activate darkmode if the cookie returned true when the page loaded if (darkModeStatus) { darkmode(true); }   //auto switch old tabs to correct darkmode state document.addEventListener("visibilitychange", function {       darkModeStatus = $.cookie(darkModeCookie) === "true";        if(darkModeStatus) {            darkmode(true);        } else {            darkmode(false);        }    }); });