You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.8 KiB
JavaScript
64 lines
2.8 KiB
JavaScript
$(function() {
|
|
if (!mw.user.isAnon()) {
|
|
var storeKey = 'isekai-userpoints-dailysign-lastSignDate';
|
|
var lastSignDate = localStorage.getItem(storeKey);
|
|
|
|
function getDateWithTimezone(deltaMinutes) {
|
|
var date = new Date();
|
|
var offset = date.getTimezoneOffset();
|
|
var offsetMilliSeconds = offset * 60 * 1000;
|
|
var deltaMilliSeconds = deltaMinutes * 60 * 1000;
|
|
var newDate = new Date(date.getTime() + offsetMilliSeconds + deltaMilliSeconds);
|
|
return newDate;
|
|
}
|
|
|
|
function getDateString(dateObj) {
|
|
var year = dateObj.getFullYear();
|
|
var month = dateObj.getMonth() + 1;
|
|
var date = dateObj.getDate();
|
|
return year + '-' + month + '-' + date;
|
|
}
|
|
|
|
var timezoneOffset = mw.config.get('wgTimezoneOffsetMinutes');
|
|
var today = getDateString(getDateWithTimezone(timezoneOffset));
|
|
|
|
if (lastSignDate !== today) {
|
|
var mwApi = new mw.Api();
|
|
mwApi.postWithToken('csrf', {
|
|
action: 'userdailysign',
|
|
}).done(function(data) {
|
|
if (data.userdailysign && data.userdailysign.success) {
|
|
if (Array.isArray(data.userdailysign.point_delta)) {
|
|
var pointDelta = data.userdailysign.point_delta;
|
|
var pointMsgList = [];
|
|
pointDelta.forEach(function (pointDeltaInfo) {
|
|
var msg = mw.msg('isekai-userpoints-point-name-num', pointDeltaInfo.name, pointDeltaInfo.icon, pointDeltaInfo.points);
|
|
pointMsgList.push(msg);
|
|
});
|
|
var separator = mw.msg('comma-separator');
|
|
var pointMsg = pointMsgList.join(separator);
|
|
|
|
var notificationMsg = mw.msg('isekai-userpoints-dailysign-notify-success', pointMsg);
|
|
mw.notify('', {
|
|
title: mw.msg('isekai-userpoints-dailysign-notify-title'),
|
|
tag: 'isekai-userpoints-dailysign',
|
|
id: 'isekai-userpoints-dailysign-notify',
|
|
});
|
|
|
|
function changeNotifyContent() {
|
|
var notifyDom = document.querySelector('#isekai-userpoints-dailysign-notify');
|
|
if (notifyDom) {
|
|
notifyDom.querySelector('.mw-notification-content').innerHTML = notificationMsg;
|
|
} else {
|
|
requestAnimationFrame(changeNotifyContent);
|
|
}
|
|
}
|
|
|
|
changeNotifyContent();
|
|
}
|
|
localStorage.setItem(storeKey, today);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}); |