Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions templates/back.html
Original file line number Diff line number Diff line change
Expand Up @@ -692,24 +692,6 @@ <h1 class="clean-pill">{{Themes}}</h1>
.join('/');
}

// i18n: detected once at module scope so all functions share lang/dict
const lang = (navigator.language || navigator.userLanguage || 'en').slice(0, 2).toLowerCase();
const labels = {
fr: { white: "Trait aux blancs", black: "Trait aux noirs", coords: "Coords" },
de: { white: "Weiß am Zug", black: "Schwarz am Zug", coords: "Koord." },
es: { white: "Juegan blancas", black: "Juegan negras", coords: "Coord." },
it: { white: "Il bianco muove", black: "Il nero muove", coords: "Coord." },
pt: { white: "Brancas jogam", black: "Pretas jogam", coords: "Coord." },
nl: { white: "Wit aan zet", black: "Zwart aan zet", coords: "Koord." },
ru: { white: "Ход белых", black: "Ход чёрных", coords: "Коорд." },
zh: { white: "白方走", black: "黑方走", coords: "坐标" },
ja: { white: "白番", black: "黒番", coords: "座標" },
pl: { white: "Ruch białych", black: "Ruch czarnych", coords: "Koord." },
tr: { white: "Beyazlar oynar", black: "Siyahlar oynar", coords: "Koord." },
en: { white: "White to move", black: "Black to move", coords: "Coords" }
};
const dict = labels[lang] || labels.en;

function applyFenToBoard() {
// 1) Read and normalize FEN (only need first 2 fields: placement + side)
const raw = ('{{FEN}}' || '').trim();
Expand All @@ -718,15 +700,40 @@ <h1 class="clean-pill">{{Themes}}</h1>
// 2) Determine side to move (strict on first char, case-insensitive)
const side = sideRaw.toLowerCase().startsWith('w') ? 'w' : 'b';

// 3) Orient the piece-placement for HTMLTTChess
// 3) Localized labels — kept inside the function so const declarations stay
// function-scoped and never conflict when both card faces share the same
// JS context (Anki reuses the WebView; module-level const would throw
// "already declared" on the second template script).
const lang = ((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage || 'en').slice(0, 2).toLowerCase();
const labels = {
fr: { white: "Trait aux blancs", black: "Trait aux noirs", coords: "Coord." },
de: { white: "Weiß am Zug", black: "Schwarz am Zug", coords: "Koord." },
es: { white: "Juegan blancas", black: "Juegan negras", coords: "Coord." },
it: { white: "Il bianco muove", black: "Il nero muove", coords: "Coord." },
pt: { white: "Brancas jogam", black: "Pretas jogam", coords: "Coord." },
nl: { white: "Wit aan zet", black: "Zwart aan zet", coords: "Koord." },
ru: { white: "Ход белых", black: "Ход чёрных", coords: "Коорд." },
zh: { white: "白方走", black: "黑方走", coords: "坐标" },
ja: { white: "白番", black: "黒番", coords: "座標" },
pl: { white: "Ruch białych", black: "Ruch czarnych", coords: "Koord." },
tr: { white: "Beyazlar oynar", black: "Siyahlar oynar", coords: "Koord." },
en: { white: "White to move", black: "Black to move", coords: "Coords" }
};
const dict = labels[lang] || labels.en;

// 4) Orient the piece-placement for HTMLTTChess
// Pass only the placement (field #1) to <c:chess>; rotate 180° when Black to move.
const oriented = side === 'w' ? placement : rotateFen180(placement);

// 4) Minimal DOM updates (textContent avoids accidental HTML parsing)
// 5) Minimal DOM updates (textContent avoids accidental HTML parsing)
const fig = document.getElementById('fen_fig');
const toMove = document.getElementById('to_move');
if (fig) fig.textContent = oriented;
if (toMove) toMove.textContent = side === 'w' ? dict.white : dict.black;

// 6) coords button label (shared from same dict, avoids a second lang lookup)
const coordsBtn = document.getElementById('coords-toggle');
if (coordsBtn) coordsBtn.textContent = dict.coords;
}

/* ----- Fix font-size bug -------------------------------------------------------- */
Expand Down Expand Up @@ -803,9 +810,8 @@ <h1 class="clean-pill">{{Themes}}</h1>
}

function initCoordsToggle() {
var btn = document.getElementById('coords-toggle');
if (btn) btn.textContent = dict.coords;
setCoordsVisible(localStorage.getItem('ocp_coords') === 'true');
var btn = document.getElementById('coords-toggle');
if (btn) btn.addEventListener('click', function() {
var next = document.documentElement.classList.contains('coords-hidden');
localStorage.setItem('ocp_coords', next);
Expand Down
52 changes: 29 additions & 23 deletions templates/front.html
Original file line number Diff line number Diff line change
Expand Up @@ -680,24 +680,6 @@ <h2 id="to_move" class="clean-pill"></h2>
.join('/');
}

// i18n: detected once at module scope so all functions share lang/dict
const lang = (navigator.language || navigator.userLanguage || 'en').slice(0, 2).toLowerCase();
const labels = {
fr: { white: "Trait aux blancs", black: "Trait aux noirs", moves: "Trouvez la séquence de coups", coords: "Coords" },
de: { white: "Weiß am Zug", black: "Schwarz am Zug", moves: "Finde die Zugfolge", coords: "Koord." },
es: { white: "Juegan blancas", black: "Juegan negras", moves: "Encuentra la secuencia de movimientos", coords: "Coord." },
it: { white: "Il bianco muove", black: "Il nero muove", moves: "Trova la sequenza di mosse", coords: "Coord." },
pt: { white: "Brancas jogam", black: "Pretas jogam", moves: "Encontre a sequência de movimentos", coords: "Coord." },
nl: { white: "Wit aan zet", black: "Zwart aan zet", moves: "Vind de zetvolgorde", coords: "Koord." },
ru: { white: "Ход белых", black: "Ход чёрных", moves: "Найдите последовательность ходов", coords: "Коорд." },
zh: { white: "白方走", black: "黑方走", moves: "找出棋步顺序", coords: "坐标" },
ja: { white: "白番", black: "黒番", moves: "手順を見つける", coords: "座標" },
pl: { white: "Ruch białych", black: "Ruch czarnych", moves: "Znajdź sekwencję ruchów", coords: "Koord." },
tr: { white: "Beyazlar oynar", black: "Siyahlar oynar", moves: "Hamle sırasını bul", coords: "Koord." },
en: { white: "White to move", black: "Black to move", moves: "Find the move sequence", coords: "Coords" }
};
const dict = labels[lang] || labels.en;

function applyFenToBoard() {
// 1) Read and normalize FEN (only need first 2 fields: placement + side)
const raw = ('{{FEN}}' || '').trim();
Expand All @@ -706,19 +688,44 @@ <h2 id="to_move" class="clean-pill"></h2>
// 2) Determine side to move (strict on first char, case-insensitive)
const side = sideRaw.toLowerCase().startsWith('w') ? 'w' : 'b';

// 3) Orient the piece-placement for HTMLTTChess
// 3) Localized labels — kept inside the function so const declarations stay
// function-scoped and never conflict when both card faces share the same
// JS context (Anki reuses the WebView; module-level const would throw
// "already declared" on the second template script).
const lang = ((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage || 'en').slice(0, 2).toLowerCase();
const labels = {
fr: { white: "Trait aux blancs", black: "Trait aux noirs", moves: "Trouvez la séquence de coups", coords: "Coord." },
de: { white: "Weiß am Zug", black: "Schwarz am Zug", moves: "Finde die Zugfolge", coords: "Koord." },
es: { white: "Juegan blancas", black: "Juegan negras", moves: "Encuentra la secuencia de movimientos", coords: "Coord." },
it: { white: "Il bianco muove", black: "Il nero muove", moves: "Trova la sequenza di mosse", coords: "Coord." },
pt: { white: "Brancas jogam", black: "Pretas jogam", moves: "Encontre a sequência de movimentos", coords: "Coord." },
nl: { white: "Wit aan zet", black: "Zwart aan zet", moves: "Vind de zetvolgorde", coords: "Koord." },
ru: { white: "Ход белых", black: "Ход чёрных", moves: "Найдите последовательность ходов", coords: "Коорд." },
zh: { white: "白方走", black: "黑方走", moves: "找出棋步顺序", coords: "坐标" },
ja: { white: "白番", black: "黒番", moves: "手順を見つける", coords: "座標" },
pl: { white: "Ruch białych", black: "Ruch czarnych", moves: "Znajdź sekwencję ruchów", coords: "Koord." },
tr: { white: "Beyazlar oynar", black: "Siyahlar oynar", moves: "Hamle sırasını bul", coords: "Koord." },
en: { white: "White to move", black: "Black to move", moves: "Find the move sequence", coords: "Coords" }
};
const dict = labels[lang] || labels.en;

// 4) Orient the piece-placement for HTMLTTChess
// Pass only the placement (field #1) to <c:chess>; rotate 180° when Black to move.
const oriented = side === 'w' ? placement : rotateFen180(placement);

// 4) Minimal DOM updates (textContent avoids accidental HTML parsing)
// 5) Minimal DOM updates (textContent avoids accidental HTML parsing)
const fig = document.getElementById('fen_fig');
const toMove = document.getElementById('to_move');
if (fig) fig.textContent = oriented;
if (toMove) toMove.textContent = side === 'w' ? dict.white : dict.black;

// 5) display moves string
// 6) display moves string
const Moves = document.getElementById('moves');
if (Moves) Moves.textContent = dict.moves;

// 7) coords button label (shared from same dict, avoids a second lang lookup)
const coordsBtn = document.getElementById('coords-toggle');
if (coordsBtn) coordsBtn.textContent = dict.coords;
}

/* ----- Fix font-size bug -------------------------------------------------------- */
Expand Down Expand Up @@ -795,9 +802,8 @@ <h2 id="to_move" class="clean-pill"></h2>
}

function initCoordsToggle() {
var btn = document.getElementById('coords-toggle');
if (btn) btn.textContent = dict.coords;
setCoordsVisible(localStorage.getItem('ocp_coords') === 'true');
var btn = document.getElementById('coords-toggle');
if (btn) btn.addEventListener('click', function() {
var next = document.documentElement.classList.contains('coords-hidden');
localStorage.setItem('ocp_coords', next);
Expand Down
8 changes: 8 additions & 0 deletions templates/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ table.chess td.rows {
padding: 5px 10px;
}

/* Coords toggle — pinned to top-right corner, outside normal flow */
#coords-toggle {
position: fixed;
top: 8px;
right: 8px;
z-index: 100;
}

/* Coords toggle — active/on state */
.btn.coords-on {
background: var(--sq-dark);
Expand Down
Loading