-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcors-proxy.html
More file actions
63 lines (62 loc) · 2.35 KB
/
Copy pathcors-proxy.html
File metadata and controls
63 lines (62 loc) · 2.35 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
<!DOCTYPE html>
<html>
<head>
<title>Brightscope – CORS Proxy Fix</title>
<style>
body { font-family: monospace; max-width: 800px; margin: 2rem auto; padding: 20px; }
input, button { padding: 10px; font-size: 1rem; }
.result { border-bottom: 1px solid #ccc; margin: 1rem 0; }
</style>
</head>
<body>
<h1>🔍 Brightscope (CORS Proxy Version)</h1>
<p>This uses AllOrigins proxy – works on GitHub Pages.</p>
<input type="text" id="query" placeholder="e.g., quantum machine learning" style="width: 70%;">
<button onclick="search()">Search</button>
<div id="results"></div>
<script>
async function search() {
const q = document.getElementById('query').value.trim();
if (!q) return;
document.getElementById('results').innerHTML = 'Loading...';
// Use AllOrigins proxy to fetch arXiv
const proxy = 'https://api.allorigins.win/raw?url=';
const arxivUrl = `https://export.arxiv.org/api/query?search_query=all:${encodeURIComponent(q)}&max_results=10`;
try {
const resp = await fetch(proxy + encodeURIComponent(arxivUrl));
const text = await resp.text();
const parser = new DOMParser();
const xml = parser.parseFromString(text, 'text/xml');
const entries = xml.querySelectorAll('entry');
if (entries.length === 0) {
document.getElementById('results').innerHTML = 'No results.';
return;
}
let html = '';
for (let entry of entries) {
const title = entry.querySelector('title')?.textContent || 'No title';
const link = entry.querySelector('id')?.textContent || '#';
const summary = entry.querySelector('summary')?.textContent?.slice(0, 300) || '';
html += `
<div class="result">
<strong><a href="${link}" target="_blank">${escapeHtml(title)}</a></strong><br>
<small>${escapeHtml(summary)}...</small>
</div>
`;
}
document.getElementById('results').innerHTML = html;
} catch(e) {
document.getElementById('results').innerHTML = 'Error: ' + e.message;
}
}
function escapeHtml(str) {
return str.replace(/[&<>]/g, function(m) {
if (m === '&') return '&';
if (m === '<') return '<';
if (m === '>') return '>';
return m;
});
}
</script>
</body>
</html>