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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 39: Строка 39:
     ];
     ];


     function createRecipeElement(recipe) {
     function createRecipeCard(recipe) {
       var div = document.createElement('div');
       var card = document.createElement('div');
       div.className = 'chem-recipe';
       card.className = 'chem-recipe';


       var title = document.createElement('h3');
       var header = document.createElement('div');
       title.textContent = recipe.name;
       header.className = 'chem-header';
       div.appendChild(title);
      header.textContent = recipe.name;
       card.appendChild(header);
 
      var content = document.createElement('div');
      content.className = 'chem-content';


       if (recipe.inputs.length) {
       if (recipe.inputs.length) {
Строка 54: Строка 58:
           inList.appendChild(li);
           inList.appendChild(li);
         }
         }
         div.appendChild(document.createTextNode('Рецепт:'));
         content.appendChild(document.createElement('hr'));
         div.appendChild(inList);
        content.appendChild(document.createTextNode('Рецепт:'));
         content.appendChild(inList);
       }
       }


Строка 61: Строка 66:
         var out = document.createElement('p');
         var out = document.createElement('p');
         out.textContent = 'Выход: ' + (typeof recipe.output === 'string' ? recipe.output : recipe.output.join(', '));
         out.textContent = 'Выход: ' + (typeof recipe.output === 'string' ? recipe.output : recipe.output.join(', '));
         div.appendChild(out);
         content.appendChild(out);
       }
       }


Строка 71: Строка 76:
           effectList.appendChild(ef);
           effectList.appendChild(ef);
         }
         }
         div.appendChild(document.createTextNode('Эффекты:'));
         content.appendChild(document.createTextNode('Эффекты:'));
         div.appendChild(effectList);
         content.appendChild(effectList);
       }
       }


Строка 78: Строка 83:
         var ap = document.createElement('p');
         var ap = document.createElement('p');
         ap.textContent = 'На вид: ' + recipe.appearance;
         ap.textContent = 'На вид: ' + recipe.appearance;
         div.appendChild(ap);
         content.appendChild(ap);
       }
       }


       return div;
      card.appendChild(content);
 
      // Скрытие/открытие по клику
      header.addEventListener('click', function () {
        content.style.display = content.style.display === 'none' ? 'block' : 'none';
      });
 
      content.style.display = 'none';
 
       return card;
     }
     }


     for (var k = 0; k < recipes.length; k++) {
     for (var k = 0; k < recipes.length; k++) {
       container.appendChild(createRecipeElement(recipes[k]));
       container.appendChild(createRecipeCard(recipes[k]));
     }
     }
   });
   });
});
});

Версия от 23:50, 19 апреля 2025

mw.loader.using('mediawiki.util', function () {
  $(function () {
    var container = document.getElementById('chemistry-recipes');
    if (!container) return;

    var recipes = [
      {
        name: 'Маннитол',
        inputs: ['Водород [1]', 'Сахар [1]', 'Вода [1]'],
        output: 'Маннитол [3]',
        effects: ['Эффективно устраняет повреждения мозга.'],
        appearance: 'Непрозрачное'
      },
      {
        name: 'Хлор',
        inputs: ['Столовая соль [2]'],
        output: ['Натрий [1]', 'Хлор [1]'],
        effects: ['Poison (0.5 ед/сек)', 'Наносит 4 Poison за единицу.'],
        appearance: 'Жёлто-зелёный газ, токсичный для человека. Газообразное'
      },
      {
        name: 'Фтор',
        inputs: [],
        output: null,
        effects: ['Poison (0.5 ед/сек)', 'Наносит 1 Caustic и 1 Poison за единицу.'],
        appearance: 'Высокотоксичный бледно-жёлтый газ. Чрезвычайно реактивный. Газообразное'
      },
      {
        name: 'Железо',
        inputs: ['Кровь [20]', 'Вода [11]', 'Сахар [2]', 'Диоксид углерода [3]'],
        output: ['Железо [0.5]', 'Протеины [4]'],
        effects: [
          'Medicine (0.5 ед/сек)',
          'Poison (0.1 ед/сек)',
          'Наносит 1 Poison за единицу при метаболизме Arachnid органами.'
        ],
        appearance: 'Серебристо-серый металл. Металлическое'
      }
    ];

    function createRecipeCard(recipe) {
      var card = document.createElement('div');
      card.className = 'chem-recipe';

      var header = document.createElement('div');
      header.className = 'chem-header';
      header.textContent = recipe.name;
      card.appendChild(header);

      var content = document.createElement('div');
      content.className = 'chem-content';

      if (recipe.inputs.length) {
        var inList = document.createElement('ul');
        for (var i = 0; i < recipe.inputs.length; i++) {
          var li = document.createElement('li');
          li.textContent = recipe.inputs[i];
          inList.appendChild(li);
        }
        content.appendChild(document.createElement('hr'));
        content.appendChild(document.createTextNode('Рецепт:'));
        content.appendChild(inList);
      }

      if (recipe.output) {
        var out = document.createElement('p');
        out.textContent = 'Выход: ' + (typeof recipe.output === 'string' ? recipe.output : recipe.output.join(', '));
        content.appendChild(out);
      }

      if (recipe.effects.length) {
        var effectList = document.createElement('ul');
        for (var j = 0; j < recipe.effects.length; j++) {
          var ef = document.createElement('li');
          ef.textContent = recipe.effects[j];
          effectList.appendChild(ef);
        }
        content.appendChild(document.createTextNode('Эффекты:'));
        content.appendChild(effectList);
      }

      if (recipe.appearance) {
        var ap = document.createElement('p');
        ap.textContent = 'На вид: ' + recipe.appearance;
        content.appendChild(ap);
      }

      card.appendChild(content);

      // Скрытие/открытие по клику
      header.addEventListener('click', function () {
        content.style.display = content.style.display === 'none' ? 'block' : 'none';
      });

      content.style.display = 'none';

      return card;
    }

    for (var k = 0; k < recipes.length; k++) {
      container.appendChild(createRecipeCard(recipes[k]));
    }
  });
});