MediaWiki:Gadget-theme.js: различия между версиями

мНет описания правки
Метка: отменено
мНет описания правки
Метка: отменено
Строка 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 pages = data.query.pages;
       const page = data.query.pages[0];
      const page = pages[0];
       const rev = page.revisions && page.revisions[0];
       const rev = page.revisions && page.revisions[0];
       const content = rev
       let content = rev
         ? (rev.slots ? rev.slots.main['*'] : rev['*'])
         ? (rev.slots ? rev.slots.main['*'] : rev['*'])
         : '';
         : '';


       const lines = content.split('\n');
       const counts = {};
      const updated = lines.map(line => {
      validThemes.forEach(t => counts[t] = 0);
        const parts = line.split('=');
      if (content && content.trim()) {
        if (parts[0] === themeName) {
        content.split('\n').forEach(line => {
          const count = parseInt(parts[1], 10) || 0;
          const [name, cnt] = line.split('=');
           return `${themeName}=${count + 1}`;
          if (name in counts) {
        }
            counts[name] = parseInt(cnt, 10) || 0;
        return line;
           }
       }).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_${theme}`;
     const flagKey = `ss14_themeCounted_${thЙeme}`;
     if (!window.localStorage.getItem(flagKey)) {
     if (!window.localStorage.getItem(flagKey)) {
       incrementThemeCounter(theme);
       incrementThemeCounter(theme);