mirror of
https://github.com/panatgithub/AnkiHeadingSync.git
synced 2026-07-22 17:10:28 +00:00
中文: 补充 cardsInfo 读取与 deck 校验流程,让 marker 驱动的旧卡和本地状态漂移场景也能自愈迁移牌组;同时对标题末尾的 #标签 回跳做最小归一化,提升从 Anki 返回 Obsidian 标题定位的兼容性,并提交用于排查的查询脚本。 English: Add cardsInfo-backed deck verification so marker-backed existing notes and deck drift can self-heal during sync. Also normalize trailing heading tags in Obsidian backlinks to improve heading jump compatibility from Anki, and include the helper query scripts used for investigation.
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const http = require('http');
|
|
|
|
const invoke = (action, params = {}) => new Promise((resolve, reject) => {
|
|
const body = JSON.stringify({ action, version: 6, params });
|
|
const req = http.request('http://127.0.0.1:8765', { method: 'POST' }, res => {
|
|
let d = '';
|
|
res.on('data', c => d += c);
|
|
res.on('end', () => {
|
|
try {
|
|
const r = JSON.parse(d);
|
|
if (r.error) reject(new Error(r.error));
|
|
else resolve(r.result);
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
});
|
|
req.on('error', reject);
|
|
req.write(body);
|
|
req.end();
|
|
});
|
|
|
|
(async () => {
|
|
try {
|
|
const noteIds = [1755676734055, 1776577443442];
|
|
const notesInfo = await invoke('notesInfo', { notes: noteIds });
|
|
|
|
for (let i = 0; i < noteIds.length; i++) {
|
|
const noteId = noteIds[i];
|
|
const info = notesInfo[i];
|
|
|
|
console.log(`--- Note ID: ${noteId} ---`);
|
|
if (!info || Object.keys(info).length === 0) {
|
|
console.log('Exists: No');
|
|
continue;
|
|
}
|
|
|
|
console.log('Exists: Yes');
|
|
console.log('Model Name:', info.modelName);
|
|
|
|
const cards = await invoke('cardsInfo', { cards: info.cards });
|
|
if (cards && cards.length > 0) {
|
|
console.log('Deck Name:', cards[0].deckName);
|
|
console.log('Card IDs:', info.cards.join(', '));
|
|
}
|
|
|
|
const front = info.fields.Front?.value || info.fields['正面']?.value || 'N/A';
|
|
const back = info.fields.Back?.value || info.fields['背面']?.value || 'N/A';
|
|
|
|
console.log('Front (First 200 chars):', front.substring(0, 200));
|
|
console.log('Back (First 200 chars):', back.substring(0, 200));
|
|
console.log('\n');
|
|
}
|
|
} catch (e) {
|
|
console.error('Error:', e.message);
|
|
}
|
|
})();
|