File size: 4,519 Bytes
76230df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d1fcd1
76230df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d1fcd1
76230df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
const select = document.querySelector("#task");
const example = document.querySelector("#example");
const statusLine = document.querySelector("#status");
const languages = {
  ru: { builds:["Лёгкая", "Средняя", "Тяжёлая"], positions:["сверху слева","сверху справа","снизу слева","снизу справа"], clips:["Первая запись","Вторая запись"], truth:"Правильная ячейка", selected:"выбрана инструкцией", task:"Задание", ok:"верно", error:"ошибка", image:"Экран с четырьмя значками", loadError:"Не удалось загрузить примеры. Обновите страницу." },
  en: { builds:["Light", "Medium", "Heavy"], positions:["top left","top right","bottom left","bottom right"], clips:["First clip","Second clip"], truth:"Correct cell", selected:"selected by the instruction", task:"Task", ok:"correct", error:"wrong", image:"Panel with four icons", loadError:"The examples could not be loaded. Refresh the page to retry." }
};
const keys = ["light","medium","heavy"];
let language = navigator.language?.toLowerCase().startsWith("ru") ? "ru" : "en";
let data;
function node(tag, value, className) {
  const el = document.createElement(tag);
  if (value !== undefined) el.textContent = value;
  if (className) el.className = className;
  return el;
}
function renderTask() {
  const row = data.tasks[select.selectedIndex];
  const labels = languages[language];
  const panel = document.querySelector("#panel");
  panel.src = "examples/" + row.image;
  panel.alt = labels.image + " · " + row.task;
  document.querySelector("#truth").textContent = labels.truth + " — " + labels.positions[row.expected];
  document.querySelector("#command").textContent = row.command;
  const clips = document.querySelector("#clips");
  const texts = document.querySelector("#transcripts");
  clips.replaceChildren();
  texts.replaceChildren();
  row.audio.forEach((file, index) => {
    const entry = data.recordings[file];
    const title = labels.clips[index] + (index === row.order ? " · " + labels.selected : "");
    const player = node("audio");
    player.controls = true;
    player.preload = "metadata";
    player.src = "examples/" + file;
    player.setAttribute("aria-label",title);
    clips.append(node("span",title,"clip"),player);
    texts.append(node("p",labels.clips[index] + " — «" + entry.source + "»"));
    const list = node("ul");
    keys.forEach((key,i) => { const li=node("li"); li.append(node("b",labels.builds[i] + " — "),node("bdi",entry[key])); list.append(li); });
    texts.append(list);
  });
  const table = document.querySelector("#decisions");
  table.replaceChildren();
  keys.forEach((key,i) => {
    const tr=node("tr");
    const th=node("th", labels.builds[i]);
    th.scope="row";
    tr.append(th);
    for (const mode of ["before","after"]) {
      const current=row[key][mode];
      const ok=current === row.expected;
      const td=node("td",(ok ? "✓ " : "× ") + labels.positions[current],ok ? "correct" : "wrong");
      td.setAttribute("aria-label",(ok ? labels.ok : labels.error) + ", " + labels.positions[current]);
      tr.append(td);
    }
    table.append(tr);
  });
}
function setLanguage(next) {
  language = next;
  document.documentElement.lang = next;
  document.title = next === "ru" ? "Нейроконструктор · LOPATA AI Hub" : "Neuroconstructor · LOPATA AI Hub";
  document.querySelectorAll("[data-ru]").forEach(el => { el.textContent=el.dataset[next]; });
  document.querySelectorAll("[data-lang]").forEach(el => { el.setAttribute("aria-pressed",String(el.dataset.lang===next)); });
  if (data) {
    Array.from(select.options).forEach((option,i) => { option.textContent=String(i+1) + " / " + data.tasks.length; });
    renderTask();
  }
}
for (const btn of document.querySelectorAll("[data-lang]")) btn.addEventListener("click",()=>setLanguage(btn.dataset.lang));
select.addEventListener("change",renderTask);
setLanguage(language);
fetch("data.json").then(async res => {
  if (!res.ok) throw new Error(String(res.status));
  data=await res.json();
  data.tasks.forEach(row => { const option=node("option"); option.value=String(row.task); select.append(option); });
  select.value="6";
  select.disabled=false;
  example.hidden=false;
  statusLine.hidden=true;
  setLanguage(language);
}).catch(() => { statusLine.textContent=languages[language].loadError; });