03 plugin.js (1/4)

  CrossPoint.registerPlugin((container, api) => {
    const $ = (s) => container.querySelector(s);
    const BOOK = /\.(epub|xtc|txt|md|pdf)$/i;
    // Never scan plugin folders (their README.md files are not books) or our own output.
    const SKIP_DIRS = ['/plugins', '/Duplicates', '/System Volume Information'];
    const fmt = (b) => b > 1048576 ? (b / 1048576).toFixed(1) + ' MB' : Math.ceil(b / 1024) + ' KB';
    const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
    const form = (o) => new URLSearchParams(o);
  
    container.innerHTML = `
      <h2>Library Doctor</h2>
      <div class="setting-row">
        <div class="setting-name">Scan folder</div>
        <div class="setting-control"><input type="text" data-root value="/"></div>
      </div>
      <p><button class="btn-small btn-add" data-act="scan">Scan</button>
         <button class="btn-small" data-act="move" disabled>Move duplicates to /Duplicates</button></p>
      <p data-status style="color:var(--muted-color)"></p>
      <div data-report></div>`;
  
    let duplicates = [];   // paths to move
  
    // One request at a time: the reader's web server is single-threaded.
    async function listDir(path) {
      const r = await fetch('/api/files?path=' + encodeURIComponent(path));
      if (!r.ok) throw new Error(`list ${path}: HTTP ${r.status}`);
      return r.json();
    }
  
    async function scan(root) {
      const books = [];
‹ PreviousReader file (.txt)Next ›