Step 7a: Bulk ID Check moves to a detached popup window

New files:
  bulk-check.html, bulk-check.js, bulk-check.css

Popup gains a 📋 launcher button next to the ⚙ Options gear. Clicking
it sends `open-bulk-check` to background.js and closes the popup;
background.js owns window lifecycle:

  - chrome.storage.session.bulkCheckWindowId stashes the open window id
  - existing id → chrome.windows.update({ focused, drawAttention })
  - missing or stale id → chrome.windows.create({ type:'popup',
    width:640, height:540 }) and stash the new id
  - chrome.windows.onRemoved clears the stale id on close

Last-paste persisted to chrome.storage.local.bulkCheckLastPaste,
debounced 500ms on input, restored on window open. quickMode is read
from settings at run time, matching previous behavior. Ctrl/Cmd+Enter
inside the textarea triggers the check.

Options page no longer carries the Bulk ID Check fieldset: removed
from options.html (Library Review pdesc updated to note the
relocation) and the matching handlers from options.js
(1903 → 1852 lines). No manifest permission changes — own-page
chrome.windows.create needs no extra permission.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
admin
2026-05-22 21:27:12 +02:00
parent e4ee06b19f
commit ad4df28a66
9 changed files with 321 additions and 64 deletions
+2 -2
View File
@@ -137,13 +137,13 @@ Done in rc-jav catalog loading. Catalog CSV/XML paths are normalized from Window
5. **Recent Activity + Search Troubleshooting moved to new Debug Tools pane.** Verified Recent Activity is search-trigger-only by reading `background.js``recordActivity()` is NOT called from `delete-file` handler. No audit-value split needed. New sidebar entry "Debug Tools" under System group; new `pane-debug` houses both fieldsets.
6. **options.js split — Cache & Scans + Duplicate Review paired extraction.** `options.js` 3133 → 2356 lines. New files: `options-cache.js` (161 lines, Cache & Scans block), `options-dupe-review.js` (616 lines, Dup Review + Keep Ranking incl. bottom `loadKeepRanking()` call). Script-tag order in `options.html`: cache → dupe-review → options.js (body bottom). Cross-script binding visibility (vanilla classic scripts share global declarative env): Library Issues code still in options.js reads `_configuredScanRoots` / `_cacheSkippedByRemote` / calls `rememberConfiguredScanRoots` from cache file by bare reference. Calls to `escapeHtml` / `openModal` / `closeModal` / `keepActionViewport` / `clearNativeRepairCard` / `renderNativeMessagingFailure` from extracted files all occur inside event handlers (resolved at call time, after options.js parses). Repo `git init`'d before this step; baseline commit `f8e781f` is the rollback point. Verified by `node --check` on each file and on concatenated script.
6b. **options.js split — Library Issues extraction.** `options.js` 2356 → 1903 lines. New file: `options-library-issues.js` (453 lines) — covers `lastLibraryIssues`, `_libraryIssuesDirty`, `renderLibraryIssues`, `_closeLibraryIssues`, and the bottom IIFE that wraps `_optScanTimer` / `_setOptScanningState` / `_pollOptProgress` for optimization-scan progress polling. Block was fully self-contained (no external callers of its identifiers). Reads `_configuredScanRoots` / `_cacheSkippedByRemote` / calls `rememberConfiguredScanRoots` from `options-cache.js` — same cross-file binding pattern proven in step 6. Script-tag order in `options.html`: cache → dupe-review → library-issues → options.js. `node --check` passes on each file and on concatenation; line count of concat (3133) matches pre-split total exactly.
7a. **Bulk Check standalone window.** New `bulk-check.{html,js,css}` opened as detached `chrome.windows.create({ type: 'popup', width: 640, height: 540 })`. Launcher = 📋 icon button in popup header next to ⚙ Options; click sends `open-bulk-check` message to background and closes the popup. Background owns the lifecycle: `openBulkCheckWindow()` reads `chrome.storage.session.bulkCheckWindowId`; existing id → `chrome.windows.update({ focused, drawAttention })`; failure or no id → create new window + stash id. `chrome.windows.onRemoved` clears the stale id on close. Last-paste persisted to `chrome.storage.local.bulkCheckLastPaste` (debounced 500ms), restored on window open. `quickMode` read from settings on each run (parity with old options behavior). Removed the Bulk ID Check fieldset from `options.html` (Library Review pane description updated to note the relocation) and its handlers from `options.js` (1903 → 1852 lines). No manifest permission changes needed.
(Step 4 in the plan is a paired-extraction sub-task of step 6; folded into step 6 ship.)
**Pending (in execution order):**
- **Step 6c — finish options.js split (optional).** Remaining options.js (1903 lines) still holds: settings load/save, backup/restore, recent activity, search test bench, bulk ID check, adapters, ID normalizers, part detectors, element picker, overlay previews, diagnostics, profiles, paths, and the bottom-entry IIFE. Candidates for extraction: Diagnostics (~250 lines, 13541603 in current options.js), Profiles (~265 lines), Adapters + ID normalizers + Part detectors as a "rules editors" file (~330 lines combined). Diminishing returns past this point — bottom IIFE + load/save core should stay in `options.js` as the entry point.
- **Step 7a — Bulk Check standalone window.** New `bulk-check.html` opened as detached `chrome.windows.create({ type: 'popup', width: 640, height: 540 })` from a "Bulk Check" launcher button in the popup. Single canonical entry path — NOT a Console sidebar tab. Window dedup via `chrome.storage.session`, last-paste persisted via `chrome.storage.local`.
- **Step 6c — finish options.js split (optional).** Remaining options.js (1852 lines) still holds: settings load/save, backup/restore, recent activity, search test bench, adapters, ID normalizers, part detectors, element picker, overlay previews, diagnostics, profiles, paths, and the bottom-entry IIFE. Candidates for extraction: Diagnostics (~250 lines), Profiles (~265 lines), Adapters + ID normalizers + Part detectors as a "rules editors" file (~330 lines combined). Diminishing returns past this point — bottom IIFE + load/save core should stay in `options.js` as the entry point.
- **Step 8 — Shared fixture corpus.** Top-level `D:\DEV\Project\rclone-jav\fixtures\` (neutral location, NOT inside Python or extension repo). JSON cases for query-ID extraction (extension), filename ID extraction (Python), shared normalization.
- **Step 9 — Cache contract design.** CACHE_VERSION already exists (currently 3). Add ID_RULES_VERSION concept: schema bump = force rebuild, rules bump = warn-and-mark-stale.
- **Step 10 — `rc-jav.py` module split** into `rcjav/` package (ids, cache, dupes, catalog, rclone_io, output, cli). Keep `rc-jav.py` as thin entrypoint that imports from `rcjav.cli.main`.
+46
View File
@@ -692,6 +692,11 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
})();
return true;
}
if (msg.type === "open-bulk-check") {
openBulkCheckWindow();
sendResponse({ ok: true });
return false;
}
if (msg.type === "dupe-review") {
(async () => {
try {
@@ -1075,3 +1080,44 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
// On install / startup, build context menu
chrome.runtime.onInstalled.addListener(() => ensureContextMenu());
chrome.runtime.onStartup.addListener(() => ensureContextMenu());
// ---------- Bulk Check standalone window ----------
const BULK_CHECK_WIN_KEY = "bulkCheckWindowId";
async function openBulkCheckWindow() {
const session = chrome.storage.session;
try {
const stored = session ? await session.get(BULK_CHECK_WIN_KEY) : {};
const existingId = stored?.[BULK_CHECK_WIN_KEY];
if (existingId) {
try {
await chrome.windows.update(existingId, { focused: true, drawAttention: true });
return;
} catch {
if (session) await session.remove(BULK_CHECK_WIN_KEY);
}
}
const win = await chrome.windows.create({
url: chrome.runtime.getURL("bulk-check.html"),
type: "popup",
width: 640,
height: 540,
});
if (session && win?.id != null) {
await session.set({ [BULK_CHECK_WIN_KEY]: win.id });
}
} catch (e) {
console.warn("openBulkCheckWindow failed:", e);
}
}
chrome.windows.onRemoved.addListener(async (windowId) => {
const session = chrome.storage.session;
if (!session) return;
try {
const stored = await session.get(BULK_CHECK_WIN_KEY);
if (stored?.[BULK_CHECK_WIN_KEY] === windowId) {
await session.remove(BULK_CHECK_WIN_KEY);
}
} catch { /* ignore */ }
});
+102
View File
@@ -0,0 +1,102 @@
body {
font-family: -apple-system, Segoe UI, sans-serif;
font-size: 13px;
margin: 0;
padding: 12px;
background: #1a1a1a;
color: #ddd;
}
#header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
#header strong { font-size: 15px; }
#mode-pill {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.4px;
background: #1a2a3a;
color: #6ec1ff;
padding: 2px 8px;
border-radius: 3px;
border: 1px solid #2a4a6a;
}
#mode-pill[data-mode="CACHE"] {
background: #1a3a1a;
color: #afa;
border-color: #2a5a2a;
}
.help {
font-size: 12px;
color: #aaa;
line-height: 1.4;
margin-bottom: 8px;
}
.help code {
background: #0d0d0d;
padding: 1px 4px;
border-radius: 2px;
font-family: Consolas, monospace;
color: #ddd;
}
.dim { color: #777; }
textarea#bulk-id-input {
width: 100%;
height: 140px;
resize: vertical;
background: #0d0d0d;
color: #ddd;
border: 1px solid #444;
border-radius: 3px;
padding: 6px 8px;
font-size: 12px;
font-family: Consolas, monospace;
box-sizing: border-box;
}
textarea#bulk-id-input:focus { outline: none; border-color: #6ec1ff; }
.button-row {
display: flex;
align-items: center;
gap: 6px;
margin: 8px 0;
}
button {
background: #333;
color: #ddd;
border: 1px solid #555;
border-radius: 3px;
padding: 4px 10px;
cursor: pointer;
font-size: 12px;
}
button:hover { background: #444; }
button:disabled { opacity: 0.5; cursor: default; }
button.running { background: #3a1a1a; border-color: #722; color: #faa; }
#count-pill {
margin-left: auto;
font-size: 11px;
}
.mono-output {
background: #0d0d0d;
border: 1px solid #333;
border-radius: 3px;
padding: 8px 10px;
font-family: Consolas, monospace;
font-size: 12px;
line-height: 1.5;
max-height: 260px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-word;
}
.mono-output:empty { display: none; }
+32
View File
@@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bulk ID Check — rclone-jav</title>
<link rel="stylesheet" href="bulk-check.css">
</head>
<body>
<div id="header">
<strong>Bulk ID Check</strong>
<span id="mode-pill" title="Current search mode"></span>
</div>
<div class="help">
Paste IDs separated by lines, commas, or spaces. Uses the current LIVE/CACHE mode and active library profile.
<br><span class="dim">Examples: <code>BLK-474</code>, <code>FC2-4865786</code>, <code>PRTD-[027-030]</code></span>
</div>
<textarea id="bulk-id-input" spellcheck="false" autocomplete="off"
placeholder="BLK-474&#10;FC2-4865786&#10;PRTD-[027-030]"></textarea>
<div class="button-row">
<button id="bulk-id-run" type="button">Check IDs</button>
<button id="bulk-id-clear" type="button">Clear</button>
<span id="count-pill" class="dim"></span>
</div>
<div id="bulk-id-results" class="mono-output"></div>
<script src="bulk-check.js"></script>
</body>
</html>
+133
View File
@@ -0,0 +1,133 @@
// Standalone Bulk ID Check window.
// Launched via chrome.windows.create from popup; background.js owns
// the windowId lifecycle (chrome.storage.session.bulkCheckWindowId).
const LAST_PASTE_KEY = "bulkCheckLastPaste";
const SAVE_DEBOUNCE_MS = 500;
function escapeHtml(s) {
return String(s ?? "").replace(/[&<>"']/g, (c) =>
({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
}
function readBulkIds() {
return [...new Set(document.getElementById("bulk-id-input").value
.split(/[\s,]+/)
.map((x) => x.trim())
.filter(Boolean))];
}
function updateCountPill() {
const ids = readBulkIds();
const pill = document.getElementById("count-pill");
pill.textContent = ids.length ? `${ids.length} unique ID${ids.length === 1 ? "" : "s"}` : "";
}
function renderBulkResults(r) {
const out = document.getElementById("bulk-id-results");
if (!r || !r.ok) {
out.innerHTML = `<span style="color:#faa;">error:</span> ${escapeHtml(r?.error || "no response")}`;
return;
}
const rows = [
`<div><span style="color:#777;">Mode:</span> ${escapeHtml(r.search_mode || "?")} · <span style="color:#777;">Queries:</span> ${escapeHtml(r.query_count || 0)} · <span style="color:#777;">Hits:</span> ${escapeHtml(r.hits || 0)} · <span style="color:#777;">Host:</span> ${escapeHtml(r.timings?.host_rcjav_ms ?? "?")}ms</div>`,
];
for (const q of r.queries || []) {
const hit = q.hits > 0;
const sample = (q.structured || []).slice(0, 3).map((h) => h.full_path || h.path || h.jav_id).join(" | ");
rows.push(`<div style="margin-top:7px;">
<span style="color:${hit ? "#afa" : "#ffa"};font-weight:600;">${hit ? "HIT" : "MISS"}</span>
<span>${escapeHtml(q.query || "?")}</span> · ${escapeHtml(q.hits || 0)} hit(s)
${sample ? `<div style="color:#777;margin-left:12px;">${escapeHtml(sample)}</div>` : `<div style="color:#777;margin-left:12px;">${escapeHtml(q.no_match_title || "No library hit")}</div>`}
</div>`);
}
out.innerHTML = rows.join("");
}
async function refreshModePill() {
const pill = document.getElementById("mode-pill");
try {
const settings = await chrome.runtime.sendMessage({ type: "get-settings" });
const mode = settings?.quickMode !== false ? "LIVE" : "CACHE";
pill.textContent = mode;
pill.dataset.mode = mode;
} catch {
pill.textContent = "?";
}
}
let _saveTimer = null;
function schedulePersist() {
if (_saveTimer) clearTimeout(_saveTimer);
_saveTimer = setTimeout(async () => {
_saveTimer = null;
const value = document.getElementById("bulk-id-input").value;
try {
await chrome.storage.local.set({ [LAST_PASTE_KEY]: value });
} catch { /* ignore */ }
}, SAVE_DEBOUNCE_MS);
}
async function restoreLastPaste() {
try {
const stored = await chrome.storage.local.get(LAST_PASTE_KEY);
const value = stored?.[LAST_PASTE_KEY];
if (typeof value === "string" && value) {
document.getElementById("bulk-id-input").value = value;
updateCountPill();
}
} catch { /* ignore */ }
}
document.getElementById("bulk-id-input").addEventListener("input", () => {
updateCountPill();
schedulePersist();
});
document.getElementById("bulk-id-clear").addEventListener("click", () => {
document.getElementById("bulk-id-input").value = "";
document.getElementById("bulk-id-results").innerHTML = "";
updateCountPill();
schedulePersist();
});
document.getElementById("bulk-id-run").addEventListener("click", async () => {
const runBtn = document.getElementById("bulk-id-run");
const out = document.getElementById("bulk-id-results");
const queries = readBulkIds();
if (!queries.length) {
out.innerHTML = `<span style="color:#ffa;">paste at least one ID</span>`;
return;
}
runBtn.disabled = true;
runBtn.classList.add("running");
out.textContent = `checking ${queries.length} ID(s)...`;
try {
const settings = await chrome.runtime.sendMessage({ type: "get-settings" });
const quick = settings?.quickMode !== false;
const r = await chrome.runtime.sendMessage({
type: "bulk-query",
queries,
quick,
});
renderBulkResults(r);
} catch (err) {
out.innerHTML = `<span style="color:#faa;">error:</span> ${escapeHtml(err?.message || String(err))}`;
} finally {
runBtn.disabled = false;
runBtn.classList.remove("running");
}
});
// Ctrl/Cmd+Enter inside textarea = run
document.getElementById("bulk-id-input").addEventListener("keydown", (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === "Enter") {
e.preventDefault();
document.getElementById("bulk-id-run").click();
}
});
(async () => {
await restoreLastPaste();
await refreshModePill();
})();
+1 -11
View File
@@ -410,7 +410,7 @@
<div class="pane" id="pane-maintenance">
<div class="pane-head">
<h1>Library Review</h1>
<div class="pdesc">Review duplicate groups, check IDs in bulk, and fix non-canonical filenames in your library.</div>
<div class="pdesc">Review duplicate groups and fix non-canonical filenames in your library. (Bulk ID Check now opens in its own window from the popup.)</div>
</div>
<div class="fieldset">
@@ -478,16 +478,6 @@
<div id="library-issues-results" class="mono-output"></div>
</div>
<div class="fieldset">
<div class="ftitle">Bulk ID check</div>
<div class="help">Paste IDs separated by lines, commas, or spaces. Uses the current LIVE/CACHE mode and active library profile.</div>
<textarea id="bulk-id-input" placeholder="BLK-474&#10;FC2-4865786&#10;PRTD-[027-030]"></textarea>
<div class="button-row" style="margin-top:8px;">
<button id="bulk-id-run" type="button">Check IDs</button>
<button id="bulk-id-clear" type="button">Clear</button>
</div>
<div id="bulk-id-results" class="mono-output"></div>
</div>
</div>
<!-- SETUP -->
-51
View File
@@ -674,57 +674,6 @@ document.getElementById("search-bench-clear").addEventListener("click", () => {
document.getElementById("search-bench-results").innerHTML = "";
});
// ---------- bulk ID check ----------
function readBulkIds() {
return [...new Set(document.getElementById("bulk-id-input").value
.split(/[\s,]+/)
.map((x) => x.trim())
.filter(Boolean))];
}
function renderBulkResults(r) {
const out = document.getElementById("bulk-id-results");
if (!r || !r.ok) {
out.innerHTML = `<span style="color:#faa;">error:</span> ${escapeHtml(r?.error || "no response")}`;
return;
}
const rows = [
`<div><span style="color:#777;">Mode:</span> ${escapeHtml(r.search_mode || "?")} · <span style="color:#777;">Queries:</span> ${escapeHtml(r.query_count || 0)} · <span style="color:#777;">Hits:</span> ${escapeHtml(r.hits || 0)} · <span style="color:#777;">Host:</span> ${escapeHtml(r.timings?.host_rcjav_ms ?? "?")}ms</div>`,
];
for (const q of r.queries || []) {
const hit = q.hits > 0;
const sample = (q.structured || []).slice(0, 3).map((h) => h.full_path || h.path || h.jav_id).join(" | ");
rows.push(`<div style="margin-top:7px;">
<span style="color:${hit ? "#afa" : "#ffa"};font-weight:600;">${hit ? "HIT" : "MISS"}</span>
<span>${escapeHtml(q.query || "?")}</span> · ${escapeHtml(q.hits || 0)} hit(s)
${sample ? `<div style="color:#777;margin-left:12px;">${escapeHtml(sample)}</div>` : `<div style="color:#777;margin-left:12px;">${escapeHtml(q.no_match_title || "No library hit")}</div>`}
</div>`);
}
out.innerHTML = rows.join("");
}
document.getElementById("bulk-id-run").addEventListener("click", async () => {
const out = document.getElementById("bulk-id-results");
const queries = readBulkIds();
if (!queries.length) {
out.innerHTML = `<span style="color:#ffa;">paste at least one ID</span>`;
return;
}
out.textContent = `checking ${queries.length} ID(s)...`;
const r = await chrome.runtime.sendMessage({
type: "bulk-query",
queries,
quick: document.getElementById("quickMode").checked,
});
renderBulkResults(r);
});
document.getElementById("bulk-id-clear").addEventListener("click", () => {
document.getElementById("bulk-id-input").value = "";
document.getElementById("bulk-id-results").innerHTML = "";
});
// ---------- adapters ----------
function renderAdapters(list) {
+1
View File
@@ -14,6 +14,7 @@
<button id="mode-cache" type="button" data-mode="cache" title="CACHE: use cache.json">CACHE</button>
</div>
<button id="pause-scan" type="button" title="Pause scanning"></button>
<button id="open-bulk" title="Bulk ID Check">📋</button>
<button id="open-options" title="Options"></button>
</div>
</div>
+4
View File
@@ -560,6 +560,10 @@ document.getElementById("recheck").addEventListener("click", async () => {
else runCheck(true);
});
document.getElementById("open-options").addEventListener("click", () => chrome.runtime.openOptionsPage());
document.getElementById("open-bulk").addEventListener("click", () => {
chrome.runtime.sendMessage({ type: "open-bulk-check" });
window.close();
});
$modeLive.addEventListener("click", () => setSearchMode("live"));
$modeCache.addEventListener("click", () => setSearchMode("cache"));
$pauseScan.addEventListener("click", () => setScanPaused(!(settings && settings.scanPaused)));