משתמש:שבת מנשה/userInfo.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
Date.prototype.toMwDate = () => { // converting to mw timestamp
    let format = self.format;
    return this.getFullYear() + format(this.getMonth() + 1) + format(this.getDate()) + format(this.getHours()) + format(this.getMinutes()) + '00';
};

this.format = (str) => {
    let num = '00' + str;
    return num.substr(num.length - 2);
};

let ThisDate = new Date();
let BNday = new Date();
BNday.setDate(BNday.getDate() - 90);

var params = {
    "action": "query",
    "format": "json",
    "list": "usercontribs",
    "uclimit": "100",
    //"ucuser": mw.config.get('wgRelevantUserName'),
    "ucuser": mw.config.get('wgUserName'),
    "ucdir": "older",
    "ucnamespace": '0|6|8|10|12|14|100',
    "ucprop": "timestamp"
};

$.getJSON('/w/api.php', params, (res) => {
    let contribs = res.query.usercontribs;
    let contribsLength = contribs.length;
    let left = (100 - contribsLength);

    if (left <= 0) {
        let date = new Date(contribs[99].timestamp);
        date = new Date(date.setDate(date.getDate() + 90));
        let formatted_date = formatDate(date);
        var label = "יש זכות הצבעה עד " + formatted_date;
        var color = "#19f0196e";
    } 
    else {
        var label = left + " עריכות לז\"ה";
        var color = "#ff00008a";
    }

    let new_NavTop = [{
        label: label,
        color: color,
        url: "",
        index: 1
    }];

    let ppersonal = document.getElementById("p-personal");
    let NavTop = ppersonal ? ppersonal.getElementsByTagName("ul")[0] : null;
    if (!NavTop) return;

    for (let i = 0; i < new_NavTop.length; i++) {
        let newListItem = document.createElement("li");
        let newLink = document.createElement("b");

        if (new_NavTop[i].hasOwnProperty("title")) {
            newLink.setAttribute("title", new_NavTop[i].title);
        }
        newLink.appendChild(document.createTextNode(new_NavTop[i].label));
        newLink.style.backgroundColor = new_NavTop[i].color;
        newLink.onclick = new_NavTop[i].onclick;
        newListItem.appendChild(newLink);

        if (new_NavTop[i].hasOwnProperty("index")) {
            NavTop.insertBefore(newListItem, NavTop.childNodes[new_NavTop[i].index]);
        } else {
            NavTop.appendChild(newListItem);
        }
    }
});

function formatDate(date) {
    let year = date.getFullYear();
    let month = padZero(date.getMonth() + 1);
    let day = padZero(date.getDate());
    let hours = padZero(date.getHours());
    let minutes = padZero(date.getMinutes());
    let seconds = padZero(date.getSeconds());

    return day + "." + month + "." + year + " " + hours + ":" + minutes + ":" + seconds;
}

function padZero(num) {
    return ("00" + num).slice(-2);
}