-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper_scraper.html
More file actions
541 lines (480 loc) · 22.3 KB
/
Copy pathpaper_scraper.html
File metadata and controls
541 lines (480 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>arXivScooper — Paper Scraper</title>
<link rel="stylesheet" href="src/styles/scraper.css">
</head>
<body>
<div class="layout">
<!-- Sidebar: saved queries -->
<div class="sidebar">
<div>
<h2>Paper Scraper</h2>
<a href="paper_database.html" style="font-size:12px; color:var(--accent); text-decoration:none;">← Back to database</a>
</div>
<div class="sidebar-section">
<h3>Saved Queries</h3>
<div id="saved-queries-list"></div>
<button class="add-query-btn" data-action="openAddQueryModal">+ Add query</button>
</div>
<div class="sidebar-section">
<h3>Quick Actions</h3>
<button class="add-query-btn" data-action="runAllSavedQueries" id="run-all-btn">Run all saved queries</button>
</div>
<div class="sidebar-stats" id="sidebar-stats">
<div>Inbox: <span id="stat-inbox">0</span> papers</div>
<div>In database: <span id="stat-db">0</span> papers</div>
<div>Last fetch: <span id="stat-last">never</span></div>
<div style="margin-top:8px;padding-top:8px;border-top:1px solid var(--border)">
arXiv: <span id="conn-status" style="font-weight:600">testing...</span>
<a href="#" id="conn-retest" data-action="runConnectionTest" style="color:var(--accent);font-size:10px;margin-left:4px;display:none">retest</a>
</div>
<div id="conn-details" style="display:none;margin-top:4px;font-size:10px;color:var(--text3);line-height:1.6"></div>
</div>
</div>
<!-- Main content -->
<div class="main">
<div class="header">
<div class="header-left">
<h1>Paper Scraper</h1>
<p>Fetch new papers from arXiv and Physical Review, review before adding to database</p>
<a href="paper_database.html">← Back to database</a>
</div>
<div class="header-right">
<button class="btn btn-sm btn-outline" data-action="clearInbox" title="Clear all dismissed/added items">Clear inbox</button>
</div>
</div>
<!-- Tabs -->
<div class="tabs">
<button class="tab active" data-action="switchScraperTab" data-tab="search" id="tab-search">Search</button>
<button class="tab" data-action="switchScraperTab" data-tab="inbox" id="tab-inbox">Inbox <span class="badge" id="inbox-badge" style="display:none">0</span></button>
<button class="tab" data-action="switchScraperTab" data-tab="quick" id="tab-quick">Quick Search</button>
<button class="tab" data-action="switchScraperTab" data-tab="doi" id="tab-doi">DOI Lookup</button>
<button class="tab" data-action="switchScraperTab" data-tab="patents" id="tab-patents">Patents</button>
</div>
<!-- ── Search Tab ── -->
<div id="panel-search">
<div class="search-panel">
<div class="search-row">
<input type="text" id="search-input" placeholder="Search papers (e.g., tantalum transmon surface loss)..." autofocus>
<button class="btn btn-save-query btn-outline btn-sm" data-action="saveCurrentSearch" title="Save this query">★</button>
<button class="btn" id="search-btn" data-action="doSearch">Search</button>
</div>
<div class="filter-bar">
<div class="source-toggles" id="source-toggles"></div>
<div class="separator"></div>
<div class="filter-group">
<label>Sort:</label>
<select id="sort-order">
<option value="date-desc">Newest first</option>
<option value="date-asc">Oldest first</option>
<option value="relevance">Relevance (arXiv)</option>
<option value="updated">Recently updated</option>
<option value="author">Author A→Z</option>
</select>
</div>
<div class="separator"></div>
<div class="filter-group">
<label>Year:</label>
<input type="number" id="year-from" placeholder="From" min="1990" max="2099">
<span style="color:var(--text3)">–</span>
<input type="number" id="year-to" placeholder="To" min="1990" max="2099">
<button class="btn btn-sm btn-outline" data-action="clearDateFilter" style="font-size:11px;padding:3px 8px">Clear</button>
</div>
</div>
<div class="presets" id="presets-bar"></div>
</div>
<div class="status" id="search-status"></div>
<!-- Batch action bar -->
<div class="batch-bar" id="batch-bar">
<span class="batch-info"><span id="batch-count">0</span> selected</span>
<div class="batch-actions">
<button class="btn btn-sm btn-green" data-action="stageSelected">Add to inbox</button>
<button class="btn btn-sm btn-outline" data-action="clearSelection">Clear</button>
</div>
</div>
<div class="card-list" id="search-results"></div>
</div>
<!-- ── Inbox Tab ── -->
<div id="panel-inbox" style="display:none">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<div style="font-size:13px; color:var(--text2);">
Review papers before adding to your database. You can add notes and edit tags.
</div>
<div style="display:flex; gap:6px;">
<button class="btn btn-sm btn-green" data-action="approveAll">Approve all</button>
</div>
</div>
<div class="card-list" id="inbox-list"></div>
</div>
<!-- ── Quick Search Tab ── -->
<div id="panel-quick" style="display:none">
<div class="search-panel">
<div class="search-row">
<input type="text" id="quick-search-input" placeholder="Search arXiv (e.g., superconducting qubit tantalum surface loss)..." autofocus>
<button class="btn" id="quick-search-btn" data-action="quickDoSearch">Search</button>
</div>
<div class="filter-bar">
<div class="filter-group">
<label>Sort:</label>
<select id="quick-sort-order">
<option value="date-desc">Newest first</option>
<option value="date-asc">Oldest first</option>
<option value="relevance">Relevance (arXiv)</option>
<option value="updated">Recently updated</option>
<option value="author">Author A→Z</option>
</select>
</div>
</div>
<div class="presets" id="quick-presets-bar"></div>
</div>
<div class="status" id="quick-status"></div>
<div id="quick-results-actions" style="display:none" class="quick-results-actions">
<button data-action="quickSelectAll">Select all</button>
<button data-action="quickSelectNone">Clear selection</button>
<span id="quick-selection-count">0 selected</span>
<button class="primary" data-action="quickExportSelected">Export selected for Claude</button>
</div>
<div id="quick-results"></div>
<div id="quick-export-area"></div>
</div>
<!-- ── DOI Lookup Tab ── -->
<div id="panel-doi" style="display:none">
<div class="search-panel">
<div style="font-size:13px; color:var(--text2); margin-bottom:12px;">
Paste a DOI, APS URL, or doi.org link to look up a specific paper.
</div>
<div class="search-row">
<input type="text" id="doi-input" placeholder="e.g., 10.1103/9xbq-t64b or https://journals.aps.org/prb/abstract/10.1103/..." data-action="doDoiLookupOnEnter">
<button class="btn" id="doi-btn" data-action="doDoiLookup">Lookup</button>
</div>
</div>
<div class="status" id="doi-status"></div>
<div id="doi-result"></div>
</div>
<!-- ── Patents Tab ── -->
<div id="panel-patents" style="display:none">
<div class="search-panel">
<div style="font-size:13px; color:var(--text2); margin-bottom:12px;">
Fetch a patent by number or Google Patents URL and add it to your library.
Google is keyless and works immediately; PatentsView keyword search needs an API key.
</div>
<div class="search-row">
<input type="text" id="patent-input" placeholder="e.g., US10374134B2 or https://patents.google.com/patent/US10374134B2" data-action="addPatentOnEnter">
<div class="filter-group">
<label>Source:</label>
<select id="patent-source">
<option value="google">Google (keyless)</option>
<option value="patentsview">PatentsView (needs key)</option>
</select>
</div>
<button class="btn" id="patent-add-btn" data-action="addPatent">Fetch & Add</button>
</div>
</div>
<div class="status" id="patent-status"></div>
<!-- Keyword search (PatentsView; dormant until a key is stored) -->
<details class="search-panel" style="margin-top:12px">
<summary style="cursor:pointer; font-size:13px; color:var(--text2)">Keyword search (PatentsView)</summary>
<div class="search-row" style="margin-top:10px">
<input type="text" id="patent-search-input" placeholder="e.g., tunable coupler transmon readout" data-action="searchPatentsOnEnter">
<button class="btn btn-outline" id="patent-search-btn" data-action="searchPatents">Search</button>
</div>
<div class="status" id="patent-search-status"></div>
<div class="card-list" id="patent-search-results"></div>
</details>
<!-- Stored patents (browse) -->
<div style="display:flex; justify-content:space-between; align-items:center; margin:16px 0 8px;">
<div style="font-size:13px; color:var(--text2);">Stored patents</div>
<div style="display:flex; gap:6px; align-items:center;">
<input type="text" id="patent-filter" placeholder="Filter..." style="font-size:12px; padding:3px 8px; width:160px;">
<button class="btn btn-sm btn-outline" data-action="refreshPatents">Refresh</button>
</div>
</div>
<div class="card-list" id="patent-list"></div>
</div>
</div>
</div>
<!-- Add Query Modal -->
<div class="modal-overlay" id="query-modal">
<div class="modal">
<h3>Save Search Query</h3>
<label>Search terms</label>
<input type="text" id="modal-query" placeholder="e.g., tantalum transmon qubit">
<label>Source</label>
<select id="modal-source"></select>
<div class="modal-actions">
<button class="btn btn-sm btn-outline" data-action="closeScraperModal">Cancel</button>
<button class="btn btn-sm" data-action="confirmSaveQuery">Save</button>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/sql-wasm.js" integrity="sha384-KsfptB549CXfbfsdxZmPo2PlmgCyJ+RNqHTQE1Gj45t3p4DaA1QbZYVyqlni4pOO" crossorigin="anonymous"></script>
<script src="scraper_config.js"></script>
<script src="db_utils.js"></script>
<!-- Modular scraper UI entry (plan #9). Loads deferred (type=module) after
the legacy globals + the inline boot block, mirroring the database-side
setup. Migrated modules get window-shimmed here for the still-inline
callers in the boot block + dynamic template strings. -->
<script type="module" src="src/ui/scraper/main.js"></script>
<script>
// ═══════════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════════
const CFG = SCRAPER_CONFIG; // shorthand
// Cross-module state. All `var` (not `let`) so each binding is the same
// slot as globalThis.<name> — modules in src/ui/scraper/ read+write
// these without re-introducing the boot-block dependency. See
// src/ui/scraper/state.js for the documented manifest.
var searchResults = []; // current search results
var selectedIdxs = new Set();
var inbox = []; // staged papers awaiting review
var savedQueries = []; // persisted queries
var existingIds = new Set(); // paper IDs already in the DB
var quickResults = [];
var quickSelected = new Set();
var activeSources = {};
// Named so the search-config-bridge can call us back via its onReady
// callback once user_config overrides land on SCRAPER_CONFIG. Without
// the rebuild, a user override that sets `enabled: false` on a source
// is silently ignored on the initial page load (B3 follow-up).
function rebuildActiveSources() {
activeSources = {};
for (const [key, src] of Object.entries(CFG.sources)) {
activeSources[key] = !!src.enabled;
}
globalThis.activeSources = activeSources;
}
rebuildActiveSources();
// `var` (not `let`) so globalThis.{dbReady,lastFetchTime} are the same
// bindings — scraper/tabs.js reads them cross-module.
var dbReady = false;
var lastFetchTime = null;
// Auto-tag using config dictionary
function autoTag(title, abstract) {
const text = (title + ' ' + abstract).toLowerCase();
const tags = [];
for (const [tag, keywords] of Object.entries(CFG.tags)) {
for (const kw of keywords) {
if (text.includes(kw.toLowerCase())) { tags.push(tag); break; }
}
}
return tags;
}
// ═══════════════════════════════════════════════════════════
// INIT — build UI from config, then load database
// ═══════════════════════════════════════════════════════════
// Inject dynamic CSS for source colors. Named function so the
// search-config-bridge can re-fire after merged user_config arrives —
// otherwise a user-added source has no badge styling on first load.
function injectSourceStyles() {
// Replace prior injection if we re-run (new sources added by user_config).
let style = document.getElementById('scq-source-styles');
if (!style) {
style = document.createElement('style');
style.id = 'scq-source-styles';
document.head.appendChild(style);
}
let css = '';
for (const [key, src] of Object.entries(CFG.sources)) {
const c = src.color;
const r = parseInt(c.slice(1,3),16), g = parseInt(c.slice(3,5),16), b = parseInt(c.slice(5,7),16);
css += `.saved-query .source-badge.${key} { background: rgba(${r},${g},${b},0.15); color: ${c}; }\n`;
css += `.source-toggle.active.${key} { border-color: ${c}; color: ${c}; background: rgba(${r},${g},${b},0.08); }\n`;
css += `.card-source.${key} { background: rgba(${r},${g},${b},0.15); color: ${c}; }\n`;
}
// Fallback style for DOI lookup papers that don't match a known source
css += `.card-source.crossref { background: rgba(142,142,160,0.15); color: #8e8ea0; }\n`;
style.textContent = css;
}
injectSourceStyles();
// Populate source toggles for Search tab. Named + idempotent for the
// same reason as injectSourceStyles: a user-added source needs to grow
// a toggle button after the bridge resolves.
function initSourceToggles() {
const container = document.getElementById('source-toggles');
if (!container) return;
container.innerHTML = '';
for (const [key, src] of Object.entries(CFG.sources)) {
const btn = document.createElement('button');
btn.className = `source-toggle ${activeSources[key] ? 'active' : ''} ${key}`;
btn.id = `src-${key}`;
btn.textContent = src.label;
btn.onclick = () => {
activeSources[key] = !activeSources[key];
btn.classList.toggle('active');
};
container.appendChild(btn);
}
}
initSourceToggles();
// Populate preset buttons for Search tab. Same idempotent pattern.
function initPresetsSearch() {
const container = document.getElementById('presets-bar');
if (!container) return;
container.innerHTML = '';
CFG.presets.forEach(p => {
const btn = document.createElement('button');
btn.className = 'preset-btn';
btn.textContent = p.label;
btn.title = p.query;
btn.onclick = () => {
document.getElementById('search-input').value = p.query;
doSearch();
};
container.appendChild(btn);
});
}
initPresetsSearch();
// Populate preset buttons for Quick Search tab
(function initPresetsQuick() {
const container = document.getElementById('quick-presets-bar');
const quickPresets = {
'SCQ materials': 'superconducting qubit material',
'Ta resonators': 'tantalum superconducting resonator',
'Transmon coherence': 'transmon qubit coherence',
'JJ fabrication': 'Josephson junction fabrication',
'TLS loss': 'two-level system loss microwave',
'Surface oxides': 'surface oxide superconducting'
};
for (const [label, query] of Object.entries(quickPresets)) {
const btn = document.createElement('button');
btn.className = 'preset-btn';
btn.textContent = label;
btn.onclick = () => quickSetQuery(query);
container.appendChild(btn);
}
})();
// Populate source selector in modal
(function initSourceSelect() {
const select = document.getElementById('modal-source');
for (const [key, src] of Object.entries(CFG.sources)) {
const opt = document.createElement('option');
opt.value = key;
opt.textContent = src.label;
select.appendChild(opt);
}
})();
// Load state from localStorage and initialize database
function init() {
loadSavedQueries();
renderSavedQueries();
loadInbox();
updateInboxBadge();
// Initialize database
initDatabase();
}
async function initDatabase() {
try {
await SCQ.init();
// user_config/search-sources.json overrides are applied by
// bootstrapSearchConfig() in src/ui/scraper/main.js — no DB-settings
// override path remains (was retired with the legacy settings modal).
dbReady = true;
const papers = SCQ.getAllPapers();
papers.forEach(p => existingIds.add(p.id));
updateStats();
} catch (err) {
console.error('Failed to initialize database:', err);
dbReady = false;
}
}
document.addEventListener('DOMContentLoaded', init);
// arXiv fetch helpers + connection test extracted to:
// src/ui/scraper/cors-fetch.js (CORS_PROXIES, isLocalhost,
// toLocalProxy, corsFetch)
// src/ui/scraper/connection-test.js (runConnectionTest)
// Both shimmed onto globalThis at module-import time. The arrow wrapper
// below defers the runConnectionTest lookup until setTimeout fires, by
// which point modules have evaluated.
setTimeout(() => globalThis.runConnectionTest?.(), 500);
// SEARCH TAB + sort + crossref + render-results extracted to
// src/ui/scraper/search-tab.js (12 functions shimmed onto globalThis)
// RENDERING-Inbox + actions extracted to
// src/ui/scraper/inbox-render.js (6 functions shimmed onto globalThis)
// QUICK SEARCH TAB extracted to src/ui/scraper/quick-search.js
// (10 functions + 4 keydown-Enter listeners shimmed onto globalThis)
// ═══════════════════════════════════════════════════════════
// DB INTEGRATION
// ═══════════════════════════════════════════════════════════
function addPaperToDB(paper) {
const dateAdded = new Date().toISOString().slice(0, 10);
// Generate citations using config formatters
const citeBib = CFG.formatBibTeX(paper);
const citeTxt = CFG.formatPlainText(paper);
const authorList = paper.authors || '';
const shortAuth = paper.shortAuthors || 'Unknown';
const year = paper.year || new Date().getFullYear();
// Determine entry type from source
const srcCfg = CFG.sources[paper.source] || {};
const entryType = (srcCfg.type === 'arxiv-jr' || srcCfg.type === 'crossref') ? 'published' : 'preprint';
SCQ.addPaper({
id: paper.id,
title: paper.title,
authors: authorList,
shortAuthors: shortAuth,
year: year,
journal: paper.journal || '',
doi: paper.doi || '',
arxiv_id: paper.source === 'arxiv' ? paper.id : '',
url: paper.url || '',
group_name: '',
dateAdded: dateAdded,
tags: paper.tags || [],
summary: paper.summary ? paper.summary.substring(0, 500) : '',
keyResults: [],
citeBib: citeBib,
citeTxt: citeTxt,
pdf_path: paper.source === 'arxiv' ? `pdfs/${paper.id}.pdf` : '',
entry_type: entryType,
volume: paper.volume || '',
pages: paper.pages || ''
});
// Add note if present
if (paper.note && paper.note.trim()) {
SCQ.setNote(paper.id, paper.note.trim());
}
existingIds.add(paper.id);
}
// SAVED QUERIES extracted to src/ui/scraper/saved-queries.js
// (10 functions shimmed onto globalThis)
// TABS & UI: extracted to src/ui/scraper/tabs.js
// (switchTab / updateInboxBadge / updateStats imported via scraper/main.js,
// shimmed onto globalThis)
// PERSISTENCE — Inbox: extracted to src/ui/scraper/inbox-persistence.js
// (saveInbox / loadInbox imported via scraper/main.js, shimmed onto window)
// ═══════════════════════════════════════════════════════════
// HELPERS
// ═══════════════════════════════════════════════════════════
function esc(str) {
if (!str) return '';
const d = document.createElement('div');
d.textContent = str;
return d.innerHTML;
}
// Close modal on overlay click
document.getElementById('query-modal').addEventListener('click', function(e) {
if (e.target === this) closeModal();
});
// Keyboard shortcut: Escape closes modal
document.addEventListener('keydown', e => {
if (e.key === 'Escape') closeModal();
if (e.key === '/' && !e.ctrlKey && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {
e.preventDefault();
document.getElementById('search-input').focus();
}
});
function clearDateFilter() {
document.getElementById('year-from').value = '';
document.getElementById('year-to').value = '';
}
function showStatusError(el, summary, details) {
el.className = 'status error';
const id = 'err-' + Date.now();
el.innerHTML = `${esc(summary)} <a href="#" data-action="toggleErrorDetails" data-target="${id}" style="color:var(--accent);font-size:11px;margin-left:6px">show details</a>
<div class="status-error-details" id="${id}">${esc(details || '')}</div>`;
}
</script>
</body>
</html>