User:Monster Domosed/common.js: Difference between revisionsGive feedback
No edit summary |
nop Tag: Undo |
||
| Line 1: | Line 1: | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
var availableIcons = [ | var availableIcons = [ | ||
| Line 52: | Line 50: | ||
function getCachedIcon() { | function getCachedIcon() { | ||
return localStorage.getItem(PREFERENCE_KEY); | return localStorage.getItem(PREFERENCE_KEY) || 'rem'; | ||
} | } | ||
| Line 65: | Line 63: | ||
} | } | ||
// ========================= | |||
// FAST LOAD (NO WAIT) | |||
// ========================= | |||
function applyStoredIcon() { | function applyStoredIcon() { | ||
applyIcon(getCachedIcon()); | |||
// background sync (keeps devices in sync) | |||
var api = new mw.Api(); | |||
api.get({ | |||
action: 'query', | |||
meta: 'userinfo', | |||
uiprop: 'options' | |||
}).done(function (data) { | |||
var serverIcon = | |||
data.query.userinfo.options[PREFERENCE_KEY] || 'rem'; | |||
if (serverIcon !== getCachedIcon()) { | |||
setCachedIcon(serverIcon); | |||
applyIcon(serverIcon); | |||
} | |||
} | |||
}); | }); | ||
} | } | ||
// ========================= | // ========================= | ||
// ICON SELECTOR | // ICON SELECTOR UI | ||
// ========================= | // ========================= | ||
function createIconSelector() { | function createIconSelector() { | ||
var currentIcon = getCachedIcon() | var currentIcon = getCachedIcon(); | ||
var html = '<div id="usericon-selector">' + | var html = '<div id="usericon-selector">' + | ||
| Line 141: | Line 128: | ||
applyIcon(iconId); | applyIcon(iconId); | ||
var api = new mw.Api(); | |||
api.saveOption(PREFERENCE_KEY, iconId) | |||
.done(function () { | |||
mw.notify('Icon updated successfully!', { | |||
type: 'success' | |||
}); | }); | ||
}) | |||
.fail(function () { | |||
mw.notify('Failed to save icon.', { | |||
type: 'error' | |||
}); | |||
}); | |||
} | } | ||
| Line 161: | Line 146: | ||
// INIT | // INIT | ||
// ========================= | // ========================= | ||
mw.loader.using(['mediawiki.util'], function () { | mw.loader.using(['mediawiki.api', 'mediawiki.util'], function () { | ||
applyStoredIcon(); | applyStoredIcon(); | ||