Tutorials > A File Manager tool > Files
PLUGIN.JS (3/4)
for (const b of books) (groups.get(key(b.name)) || groups.set(key(b.name), []).get(key(b.name))).push(b);
duplicates = [];
const dupRows = [];
for (const list of groups.values()) {
if (list.length < 2) continue;
list.sort((a, b) => b.size - a.size); // keep the biggest copy
for (const extra of list.slice(1)) duplicates.push(extra.path);
dupRows.push(`
${esc(list[0].path)} (kept)
` +
list.slice(1).map((b) => esc(b.path)).join('
') + '');
}
const total = books.reduce((s, b) => s + b.size, 0);
$('[data-report]').innerHTML = `
${books.length} books, ${fmt(total)} total.
${[...byDir].sort((a, b) => b[1].size - a[1].size).map(([d, v]) =>
`| ${esc(d)} | ${v.n} |
${fmt(v.size)} |
`).join('')}
${duplicates.length} probable duplicates
`;
$('[data-act=move]').disabled = duplicates.length === 0;
}
$('[data-act=scan]').onclick = async () => {
$('[data-act=scan]').disabled = true;
try {
const books = await scan($('[data-root]').value.trim() || '/');
report(books);
$('[data-status]').textContent = 'Done.';
} catch (e) {
Next: 06 plugin.js (4/4)