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

мНет описания правки
Метка: отменено
мНет описания правки
Метка: отменено
Строка 9: Строка 9:


   function incrementThemeCounter(themeName) {
   function incrementThemeCounter(themeName) {
    if (mw.user.isAnon && mw.user.isAnon()) {
      console.warn('123');
      return;
    }
     const pageTitle = 'Обсуждение участника:Pok';
     const pageTitle = 'Обсуждение участника:Pok';
     const validThemes = ['light', 'normal', 'dark', 'ss14'];
     const validThemes = ['light', 'normal', 'dark', 'ss14'];
Строка 29: Строка 24:
       const page = data.query.pages[0];
       const page = data.query.pages[0];
       const rev = page.revisions && page.revisions[0];
       const rev = page.revisions && page.revisions[0];
       let content = rev
       let content = rev ? (rev.slots ? rev.slots.main['*'] : rev['*']) : '';
        ? (rev.slots ? rev.slots.main['*'] : rev['*'])
        : '';


       const counts = {};
       const counts = {};
       validThemes.forEach(t => counts[t] = 0);
       validThemes.forEach(t => counts[t] = 0);
       if (content && content.trim()) {
       if (content.trim()) {
         content.split('\n').forEach(line => {
         content.split('\n').forEach(line => {
           const [name, cnt] = line.split('=');
           const [name, cnt] = line.split('=');
           if (name in counts) {
           if (validThemes.includes(name)) {
             counts[name] = parseInt(cnt, 10) || 0;
             counts[name] = parseInt(cnt, 10) || 0;
           }
           }
Строка 46: Строка 39:
       counts[themeName] = (counts[themeName] || 0) + 1;
       counts[themeName] = (counts[themeName] || 0) + 1;


       const updated = validThemes.map(t => `${t}=${counts[t]}`).join('\n');
       const updatedText = validThemes.map(t => `${t}=${counts[t]}`).join('\n');


       api.postWithToken('csrf', {
       api.postWithToken('csrf', {
         action: 'edit',
         action: 'edit',
         title: pageTitle,
         title: pageTitle,
         text: updated,
         text: updatedText,
         summary: `Increment ${themeName} theme counter`
         summary: `Increment ${themeName} theme counter`,
        createonly: false
       }).done(() => {
       }).done(() => {
         console.log(`Theme "${themeName}" count updated.`);
         console.log(`Theme "${themeName}" count updated.`);
Строка 67: Строка 61:
     const validThemes = ['light', 'normal', 'dark', 'ss14'];
     const validThemes = ['light', 'normal', 'dark', 'ss14'];


     console.log('Current cookies:', document.cookie);
     console.log('Loaded theme-counter script. Cookies:', document.cookie);
     const theme = getCookie(COOKIE_NAME);
     const theme = getCookie(COOKIE_NAME);
 
     if (!theme || !validThemes.includes(theme)) {
     if (!theme || validThemes.indexOf(theme) === -1) {
       console.warn('Unknown or missing theme cookie:', theme);
       console.warn('Unknown or missing theme cookie:', theme);
       return;
       return;