MediaWiki:Gadget-theme.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки Метка: отменено |
Pok (обсуждение | вклад) мНет описания правки Метка: отменено |
||
| Строка 15: | Строка 15: | ||
const pageTitle = 'Обсуждение участника:Pok'; | const pageTitle = 'Обсуждение участника:Pok'; | ||
const validThemes = ['light', 'normal', 'dark', 'ss14']; | |||
const api = new mw.Api(); | const api = new mw.Api(); | ||
| Строка 26: | Строка 27: | ||
format: 'json' | format: 'json' | ||
}).done(data => { | }).done(data => { | ||
const | const page = data.query.pages[0]; | ||
const rev = page.revisions && page.revisions[0]; | const rev = page.revisions && page.revisions[0]; | ||
let content = rev | |||
? (rev.slots ? rev.slots.main['*'] : rev['*']) | ? (rev.slots ? rev.slots.main['*'] : rev['*']) | ||
: ''; | : ''; | ||
const | const counts = {}; | ||
validThemes.forEach(t => counts[t] = 0); | |||
if (content && content.trim()) { | |||
content.split('\n').forEach(line => { | |||
const [name, cnt] = line.split('='); | |||
if (name in counts) { | |||
counts[name] = parseInt(cnt, 10) || 0; | |||
} | |||
}).join('\n'); | }); | ||
} | |||
counts[themeName] = (counts[themeName] || 0) + 1; | |||
const updated = validThemes.map(t => `${t}=${counts[t]}`).join('\n'); | |||
api.postWithToken('csrf', { | api.postWithToken('csrf', { | ||
| Строка 64: | Строка 69: | ||
console.log('Current cookies:', document.cookie); | console.log('Current cookies:', document.cookie); | ||
const theme = getCookie(COOKIE_NAME); | const theme = getCookie(COOKIE_NAME); | ||
if (!theme || validThemes.indexOf(theme) === -1) { | if (!theme || validThemes.indexOf(theme) === -1) { | ||
console.warn('Unknown or missing theme cookie:', theme); | console.warn('Unknown or missing theme cookie:', theme); | ||
| Строка 69: | Строка 75: | ||
} | } | ||
const flagKey = `ss14_themeCounted_${ | const flagKey = `ss14_themeCounted_${thЙeme}`; | ||
if (!window.localStorage.getItem(flagKey)) { | if (!window.localStorage.getItem(flagKey)) { | ||
incrementThemeCounter(theme); | incrementThemeCounter(theme); | ||