Difference between revisions of "MediaWiki:Common.js"

From Digimon Masters Online Wiki - DMO Wiki
Jump to navigation Jump to search
Line 25: Line 25:
         }
         }
         console.log(cookieValue);
         console.log(cookieValue);
         document.cookie = cookieValue;
         document.cookie = cookieValue + "; secure";


         // window.location.reload();
         // window.location.reload();

Revision as of 23:36, 6 February 2021

/* Any JavaScript here will be loaded for all users on every page load. */


function getCookieValue(a) {
    var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');

    return b ? b.pop() : '';
}

$(function () {

    $("#p-navigation .body ul")
        .append('<li><a href="https://twitter.com/DMOWiki" target="_blank"><img src="https://dmowiki.com/images/9/92/Twitter_Icon.png" title="DMO Wiki at Twitter" alt="Twitter" /> @DMOWiki</a></li>')
        .append('<li><a href="/" class="js-toggle-dark-mode">Toggle dark mode</a></li>')
    ;


    $('.js-toggle-dark-mode').on('click', function (e) {
        e.preventDefault();
        var useTheme = getCookieValue('usetheme');

        var cookieValue = "usetheme=dark; expires=Sun, 25 Aug 2030 00:00:00 GMT";
        if (useTheme.length > 0) {
            cookieValue = "usetheme=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
        }
        console.log(cookieValue);
        document.cookie = cookieValue + "; secure";

        // window.location.reload();
    });

    $("h3#p-navigation-label").css({
        'display': 'block',
        'padding': '0px 1.75em 0.25em 0.25em',
        'border': 'medium none',
    });

    $("#mw-panel div.portal div.body").css({
        "margin": "0px 0px 0px 1.25em",
        "background-image": "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIwAAAABCAAAAAAphRnkAAAAJ0lEQVQIW7XFsQEAIAyAMPD/b7uLWz8wS5youFW1UREfiIpH1Q2VBz7fGPS1dOGeAAAAAElFTkSuQmCC')",
    });

});