User:Sergekorjian/common.js: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
$("#wpSave").hover(function () {
    $(this).css('top', Math.floor((Math.random() * 1000) + 1) + 'px').css('left', Math.floor((Math.random() * 1000) + 1) + 'px').css('position','absolute');
});
/*mw.loader.using('mediawiki.user', function () {
/*mw.loader.using('mediawiki.user', function () {
$(document).ready(function () {
$(document).ready(function () {

Revision as of 13:36, 21 September 2015

/*mw.loader.using('mediawiki.user', function () {
$(document).ready(function () {

    var rand = Math.floor((Math.random() * 10) + 1);
    //if(rand > 5){
    if (1) {
        butterbarShouldDisplay();
    }
});
});
function butterbarShouldDisplay() {
    if (mw.user.isAnon()) {
        if (getCookie("butterbarHide") != "1") {
            butterbarShow();
        }
    } else {
        if ($.inArray("hideButterbar", mw.config.get('wgUserGroups')) == "-1") {
            butterbarShow();
        }
    }
}
function butterbarShow() {
    $("#globalWrapper").prepend("<div id='butterbar'>You can earn CME Credit by browsing wikidoc! Click <a href='http://www.wikidoc.org/index.php/Special:CMERegister'>here</a> to register! or <a href='#' id='permaHide'>Never show again</a><div id='butterbarClose'>X</div></div>");
    $("#butterbarClose").click(function () {
        $("#butterbar").remove();
    });
    $("#permaHide").click(function () {
        butterbarNeverAgain();
        $("#butterbar").remove();
    });
}
function butterbarNeverAgain() {
    if (mw.user.isAnon()) {
        setCookie("butterbarHide", "1", 365);
    } else {
        var api = new mw.Api();
        api.get({
            action : 'query',
            list : 'users',
            ususers : mw.user.getName(),
            ustoken : 'userrights'
        }).done(function (data) {
            var newApi = new mw.Api();
            api.post({
                action : 'userrights',
                user : mw.user.getName(),
                token : data.query.users[0].userrightstoken,
                add : 'hideButterbar',
                reason : 'Modified at user request'
            });
        });
    }
}
function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ')
            c = c.substring(1);
        if (c.indexOf(name) != -1)
            return c.substring(name.length, c.length);
    }
    return "";
}*/

if (getCookie("butterbarHide") != "1") {
    $('#content').animateRotate(360, 5000, function () {
    });
    }
    setCookie("butterbarHide", "1", 365);
    function setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
    }

    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ')
                c = c.substring(1);
            if (c.indexOf(name) != -1)
                return c.substring(name.length, c.length);
        }
        return "";
    }