MediaWiki:Gadget-eventslist.js: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 16: | Line 16: | ||
// TODO: Cache Vos as well | // TODO: Cache Vos as well | ||
;(function($, mw, | ;(function($, mw, gs){ | ||
var portletLink, | var portletLink, | ||
$popup, | $popup, | ||
| Line 147: | Line 147: | ||
// Check browser supports notifications | // Check browser supports notifications | ||
self.supportNotif = | self.supportNotif = gs.canSendBrowserNotifs(); | ||
// TODO: Check if using service worker notifications | // TODO: Check if using service worker notifications | ||
| Line 226: | Line 226: | ||
autoClose: true, | autoClose: true, | ||
classes: ['gsw-events-popup oo-ui-labelElement-invisible'], | classes: ['gsw-events-popup oo-ui-labelElement-invisible'], | ||
hideWhenOutOfView: ( | hideWhenOutOfView: (gs.isUsingStickyHeader() ? true : false), | ||
invisibleLabel: true, | invisibleLabel: true, | ||
label: 'Events', | label: 'Events', | ||
| Line 286: | Line 286: | ||
mw.log('Loading settings'); | mw.log('Loading settings'); | ||
return new Promise( function (resolve, reject) { | return new Promise( function (resolve, reject) { | ||
if (! | if (!gs.hasLocalStorage()) { | ||
console.warn('Browser does not support localStorage'); | console.warn('Browser does not support localStorage'); | ||
reject(); | reject(); | ||
| Line 318: | Line 318: | ||
} | } | ||
if (! | if (!gs.hasLocalStorage()) { | ||
console.warn('Browser does not support localStorage'); | console.warn('Browser does not support localStorage'); | ||
return false; | return false; | ||
| Line 343: | Line 343: | ||
self.settings.notiftype[key] = value; | self.settings.notiftype[key] = value; | ||
if (! | if (!gs.hasLocalStorage()) { | ||
console.warn('Browser does not support localStorage'); | console.warn('Browser does not support localStorage'); | ||
return false; | return false; | ||
| Line 1,403: | Line 1,403: | ||
// Latest rotations and settings from localStorage | // Latest rotations and settings from localStorage | ||
if ( | if (gs.hasLocalStorage()) { | ||
var last = {}; | var last = {}; | ||
try { | try { | ||
| Line 1,460: | Line 1,460: | ||
vosjson.districts.forEach( function (clan) { | vosjson.districts.forEach( function (clan) { | ||
if (self.settings.notiftype['vos' + clan] && self.settings.notiftype.vos == 'Some' || self.settings.notiftype.allvos) { | if (self.settings.notiftype['vos' + clan] && self.settings.notiftype.vos == 'Some' || self.settings.notiftype.allvos) { | ||
var img = | var img = gs.getFileURL(clan + ' Clan.png'); | ||
vosnotifs.push( { title:'VoS ' + clan, opts:{ | vosnotifs.push( { title:'VoS ' + clan, opts:{ | ||
badge: img, | badge: img, | ||
| Line 1,477: | Line 1,477: | ||
// Save the last rotations to localstorage if possible | // Save the last rotations to localstorage if possible | ||
if ( | if (gs.hasLocalStorage()) { | ||
var string = JSON.stringify(self.lastRot); | var string = JSON.stringify(self.lastRot); | ||
try { | try { | ||
| Line 1,573: | Line 1,573: | ||
// Daily | // Daily | ||
var dailyReset = moment(now).add(1, 'days').startOf('day'), | var dailyReset = moment(now).add(1, 'days').startOf('day'), | ||
img = ' | img = ''; | ||
if (dailyReset.diff(now, 'minutes') <= 10) { | if (dailyReset.diff(now, 'minutes') <= 10) { | ||
notifs.push( { title:'Daily Reset', opts:{ | notifs.push( { title:'Daily Reset', opts:{ | ||
| Line 1,590: | Line 1,590: | ||
// Weekly | // Weekly | ||
var weeklyReset = moment(now).day(3).startOf('day'), | var weeklyReset = moment(now).day(3).startOf('day'), | ||
img = ' | img = ''; | ||
if (now.isAfter(weeklyReset)) { | if (now.isAfter(weeklyReset)) { | ||
weeklyReset.add(1, 'week'); | weeklyReset.add(1, 'week'); | ||
| Line 1,622: | Line 1,622: | ||
// Monthly | // Monthly | ||
var monthlyReset = moment(now).add(1, 'months').startOf('month'), | var monthlyReset = moment(now).add(1, 'months').startOf('month'), | ||
img = ' | img = ''; | ||
if (monthlyReset.diff(now, 'minutes') <= 10) { | if (monthlyReset.diff(now, 'minutes') <= 10) { | ||
notifs.push( { title:'Monthly Reset', opts:{ | notifs.push( { title:'Monthly Reset', opts:{ | ||
| Line 1,691: | Line 1,691: | ||
self.sendNotifs( dnotifs ); | self.sendNotifs( dnotifs ); | ||
// Save the last rotations to localstorage if possible | // Save the last rotations to localstorage if possible | ||
if ( | if (gs.hasLocalStorage()) { | ||
var string = JSON.stringify(self.lastRot); | var string = JSON.stringify(self.lastRot); | ||
try { | try { | ||
| Line 1,748: | Line 1,748: | ||
// Generate notification | // Generate notification | ||
if (pofnots.length > 0) { | if (pofnots.length > 0) { | ||
var img = ' | var img = '', | ||
nbod = 'Spawning soon:', | nbod = 'Spawning soon:', | ||
len = pofnots.length, | len = pofnots.length, | ||
| Line 1,783: | Line 1,783: | ||
if (spot[0] != self.lastRot.mgspot) { | if (spot[0] != self.lastRot.mgspot) { | ||
self.lastRot.mgspot = spot[0]; | self.lastRot.mgspot = spot[0]; | ||
var img = ' | var img = ''; | ||
notifs.push( { title:'Minigame Spotlight', opts:{ | notifs.push( { title:'Minigame Spotlight', opts:{ | ||
| Line 1,824: | Line 1,824: | ||
// Save the last rotations to localstorage if possible | // Save the last rotations to localstorage if possible | ||
if ( | if (gs.hasLocalStorage()) { | ||
var string = JSON.stringify(self.lastRot); | var string = JSON.stringify(self.lastRot); | ||
try { | try { | ||