diff --git a/README.md b/README.md index 299ac91..cef28bd 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Import Kindle `My Clippings.txt` highlights into Zotero as native annotations, d # Install -1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.18`, or `0.6.17-beta` for preview). +1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.19`, or `0.6.18-beta` for preview). 2. In Zotero: `Tools` → `Plugins` → `gear` → `Install Plugin From File…` → pick the `.xpi` → restart Zotero. 3. `Tools` → `Kanzi…` to open the manager. diff --git a/plugin/manager.html b/plugin/manager.html index 84c5115..c031f28 100644 --- a/plugin/manager.html +++ b/plugin/manager.html @@ -103,6 +103,12 @@ startedAt: null, timer: null, lastClippingsPath: null, + integratedPage: 0, + integratedPageSize: 50, + conflictsPage: 0, + conflictsPageSize: 50, + mappingsPage: 0, + mappingsPageSize: 50, initSafe() { try { @@ -623,7 +629,7 @@ return map; }, - refreshIntegrated() { + refreshIntegrated(resetPage = false) { const tbody = document.getElementById('integrated-rows'); const countEl = document.getElementById('integrated-count'); if (!tbody) return; @@ -632,8 +638,83 @@ const all = this.getIntegratedHighlights(); const dateMap = this.buildClippingDateMap(); const filtered = needle ? all.filter(a => `${a.clipping_title} ${a.annotation?.text || ''} ${a.citation_key || ''} ${a.annotation?.pageLabel || ''} ${a.clipping_added_on_iso || ''} ${a.integrated_at || ''}`.toLowerCase().includes(needle)) : all; - const toShow = filtered.slice(0, 400); - if (countEl) countEl.textContent = `${filtered.length} of ${all.length} shown (first 400)`; + if (resetPage) this.integratedPage = 0; + const totalPages = Math.max(1, Math.ceil(filtered.length / this.integratedPageSize)); + if (this.integratedPage >= totalPages) this.integratedPage = totalPages - 1; + const start = this.integratedPage * this.integratedPageSize; + const toShow = filtered.slice(start, start + this.integratedPageSize); + if (countEl) countEl.textContent = `${filtered.length} of ${all.length} — page ${this.integratedPage + 1}/${totalPages} (${this.integratedPageSize} per page)`; + // pagination controls + let pag = document.getElementById('integrated-pagination'); + if (!pag) { + pag = document.createElement('div'); + pag.id = 'integrated-pagination'; + pag.style.display = 'flex'; + pag.style.justifyContent = 'space-between'; + pag.style.alignItems = 'center'; + pag.style.margin = '8px 0'; + pag.style.gap = '8px'; + pag.style.flexWrap = 'wrap'; + tbody.parentElement.parentElement.appendChild(pag); + } + pag.textContent = ''; + const mkBtn = (label, disabled, onClick) => { + const b = document.createElement('button'); + b.textContent = label; + b.disabled = disabled; + b.style.padding = '4px 8px'; + b.style.border = '1px solid var(--line)'; + b.style.background = disabled ? 'var(--panel-soft)' : 'var(--panel)'; + b.style.borderRadius = 'var(--radius)'; + b.style.cursor = disabled ? 'not-allowed' : 'pointer'; + b.style.fontSize = '11px'; + if (!disabled) b.addEventListener('click', onClick); + return b; + }; + const left = document.createElement('div'); + left.style.display = 'flex'; + left.style.gap = '4px'; + left.appendChild(mkBtn('‹ Prev', this.integratedPage === 0, () => { this.integratedPage--; this.refreshIntegrated(); })); + left.appendChild(mkBtn('Next ›', this.integratedPage >= totalPages - 1, () => { this.integratedPage++; this.refreshIntegrated(); })); + const mid = document.createElement('span'); + mid.className = 'muted'; + mid.textContent = `Page ${this.integratedPage + 1} of ${totalPages}`; + left.appendChild(mid); + pag.appendChild(left); + const right = document.createElement('div'); + right.style.display = 'flex'; + right.style.gap = '6px'; + right.style.alignItems = 'center'; + const sel = document.createElement('select'); + sel.style.padding = '4px'; + sel.style.border = '1px solid var(--line)'; + sel.style.borderRadius = 'var(--radius)'; + sel.style.fontSize = '11px'; + for (const n of [25, 50, 100, 200, 500]) { + const opt = document.createElement('option'); + opt.value = n; + opt.textContent = n + ' per page'; + if (n === this.integratedPageSize) opt.selected = true; + sel.appendChild(opt); + } + const optAll = document.createElement('option'); + optAll.value = filtered.length || 500; + optAll.textContent = 'Show all'; + sel.appendChild(optAll); + sel.addEventListener('change', () => { this.integratedPageSize = parseInt(sel.value, 10); this.integratedPage = 0; this.refreshIntegrated(); }); + right.appendChild(sel); + const expand = document.createElement('button'); + expand.textContent = 'Expand 50 →'; + expand.title = 'Show next 50'; + expand.style.padding = '4px 8px'; + expand.style.border = '1px solid var(--line)'; + expand.style.background = 'var(--panel)'; + expand.style.borderRadius = 'var(--radius)'; + expand.style.cursor = 'pointer'; + expand.style.fontSize = '11px'; + expand.addEventListener('click', () => { this.integratedPageSize += 50; this.refreshIntegrated(); }); + right.appendChild(expand); + pag.appendChild(right); if (!toShow.length) { const tr = document.createElement('tr'); const td = document.createElement('td'); @@ -984,7 +1065,7 @@ iSearch.placeholder = 'Filter integrated highlights by title, text, citekey...'; iSearch.style.width = '320px'; iSearch.style.maxWidth = '50%'; - iSearch.addEventListener('input', () => this.refreshIntegrated()); + iSearch.addEventListener('input', () => this.refreshIntegrated(true)); iSearchWrap.appendChild(iSearch); integratedTab.appendChild(iSearchWrap); const iCount = document.createElement('div'); diff --git a/plugin/manifest.json b/plugin/manifest.json index 901cbba..ea8959a 100644 --- a/plugin/manifest.json +++ b/plugin/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Kanzi", - "version": "0.6.18", + "version": "0.6.19", "description": "Kindle annotations to Zotero — My Clippings.txt → native annotations.", "homepage_url": "https://github.com/UtkuBilenDemir/kindle-zotero_importer", "author": "Utku Bilen Demir", diff --git a/src/kindle_zotero_importer/cli.py b/src/kindle_zotero_importer/cli.py index 6f7cd81..6c182ea 100644 --- a/src/kindle_zotero_importer/cli.py +++ b/src/kindle_zotero_importer/cli.py @@ -416,17 +416,19 @@ def main(argv: list[str] | None = None) -> int: if c.id in prev_integrated_ids and c.title in _ov_for_inc: to_process_ids.add(c.id) # Also re-queue highlights whose bracket colour would change the annotation - # (so you can recolour a past highlight by adding [r]/[o] etc. to its note or highlight text) + # (so you can recolour a past highlight by adding [r]/[o] etc. to its note or highlight text, + # and also fix old double-bracket comments like "[r] note" + "note") if colour_map: import re as _re - # Build map of new notes by title for quick lookup - new_notes_by_title: dict[str, list] = {} + # Build map of notes by title for quick lookup (for bracket on note) + notes_by_title: dict[str, list] = {} for n in new_clippings_list: - if n.kind == "note" and n.id not in prev_integrated_ids: - # new note (not yet integrated) — check if it has a bracket colour + if n.kind == "note": m = _re.match(r"^\s*\[([^\]]+)\]\s*", n.text or "") if m and m.group(1).strip().lower() in {k.lower() for k in colour_map.keys()}: - new_notes_by_title.setdefault(n.title, []).append(n) + notes_by_title.setdefault(n.title, []).append(n) + # also check for double-bracket case: note text without bracket but highlight already has [r] in Zotero + # For that, we need to re-queue if existing Zotero comment contains "[r]" for c in new_clippings_list: if c.id not in prev_integrated_ids: continue @@ -439,10 +441,23 @@ def main(argv: list[str] | None = None) -> int: if m and m.group(1).strip().lower() in {k.lower() for k in colour_map.keys()}: has_bracket = True break - # also check if a *new* note for same title would attach to this highlight (by location/page proximity) - # Approximate: any new note with same title is considered for re-queue (conservative, ensures recolours) - if not has_bracket and c.title in new_notes_by_title: + # also check if any note for same title has bracket (new or old) — for already integrated highlights, + # the note that would be attached is in new_clippings_list; check all notes for title + if not has_bracket and c.title in notes_by_title: has_bracket = True + # also check if previous final plan's annotation for this clipping had a bracket comment that is now stripped + # (handles the double "[r] note" + "note" case) + if not has_bracket and prev_final_plan: + for ann in prev_final_plan.get("annotations", []): + if ann.get("clipping_id") == c.id: + prev_comment = ann.get("annotation", {}).get("comment") or "" + # if prev had "[r] note" and new would be "note", they differ + for part in prev_comment.split("\n\n"): + m = _re.match(r"^\s*\[([^\]]+)\]\s*", part.strip()) + if m and m.group(1).strip().lower() in {k.lower() for k in colour_map.keys()}: + has_bracket = True + break + break if has_bracket: to_process_ids.add(c.id) # If colourMap itself changed since last run, re-queue all prev integrated (so Settings change recolours) diff --git a/updates.json b/updates.json index 7fda5f1..7e7e4a2 100644 --- a/updates.json +++ b/updates.json @@ -2,6 +2,15 @@ "addons": { "kindlezoteroimporter@utkubilen.de": { "updates": [ + { + "version": "0.6.19", + "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.19/kindle-zotero-importer.xpi", + "applications": { + "zotero": { + "strict_min_version": "6.999" + } + } + }, { "version": "0.6.18", "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.18/kindle-zotero-importer.xpi",