File size: 3,676 Bytes
4d5c005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8fa2bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d5c005
e8fa2bc
 
 
 
 
 
 
4d5c005
 
 
e8fa2bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d5c005
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
document.addEventListener('DOMContentLoaded', function() {
    const lightMode = document.getElementById('lightMode');
    const darkMode = document.getElementById('darkMode');
    const body = document.body;

    // Set initial theme based on system preference
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        body.classList.add('dark-mode');
        darkMode.style.display = 'none';
        lightMode.style.display = 'block';
    } else {
        body.classList.remove('dark-mode');
        darkMode.style.display = 'block';
        lightMode.style.display = 'none';
    }

    // Toggle theme functions
    lightMode.addEventListener('click', () => {
        body.classList.remove('dark-mode');
        darkMode.style.display = 'block';
        lightMode.style.display = 'none';
        localStorage.setItem('theme', 'light');
    });
    
    darkMode.addEventListener('click', () => {
        body.classList.add('dark-mode');
        darkMode.style.display = 'none';
        lightMode.style.display = 'block';
        localStorage.setItem('theme', 'dark');
    });

    // Check for saved theme preference
    const savedTheme = localStorage.getItem('theme');
    if (savedTheme) {
        if (savedTheme === 'dark') {
            body.classList.add('dark-mode');
            darkMode.style.display = 'none';
            lightMode.style.display = 'block';
        } else {
            body.classList.remove('dark-mode');
            darkMode.style.display = 'block';
            lightMode.style.display = 'none';
        }
    }
}); 
function createPaperCard(paper) {
    // Create the card element
    const cardElement = document.createElement('div');
    cardElement.className = 'paper-card';
    
    // Set the inner HTML with the paper details
    cardElement.innerHTML = `
        <h2 class="paper-title">${escapeHtml(paper.title)}</h2>
        <div class="paper-authors">
            ${paper.authors.split(', ').map(author => 
                `<span class="author-name">${escapeHtml(author)}</span>`
            ).join('')}
        </div>
        <div class="paper-abstract">
            ${escapeHtml(paper.abstract)}
        </div>
        <div class="paper-meta">
            <div class="meta-info">
                <span class="meta-item">
                    <span class="meta-icon">📅</span>
                    ${paper.published}
                </span>
                <span class="meta-item">
                    <span class="meta-icon">🏷️</span>
                    ${paper.category || 'N/A'}
                </span>
            </div>
            <div class="paper-actions">
                <button class="action-button analyze-btn">
                    <span>🔍</span> Analyze with AI
                </button>
                <button class="action-button download-btn">
                    <span>📥</span> Download PDF
                </button>
            </div>
        </div>
    `;
    
    // Add event listeners directly to the buttons
    const analyzeButton = cardElement.querySelector('.analyze-btn');
    analyzeButton.addEventListener('click', () => {
        analyzeWithAI(paper.pdf_link);
    });
    
    const downloadButton = cardElement.querySelector('.download-btn');
    downloadButton.addEventListener('click', () => {
        downloadPaper(paper.pdf_link, paper.title);
    });
    
    return cardElement;
}

// Make sure the escapeHtml function is available
function escapeHtml(unsafe) {
    return unsafe
        .replace(/&/g, "&amp;")
        .replace(/</g, "&lt;")
        .replace(/>/g, "&gt;")
        .replace(/"/g, "&quot;")
        .replace(/'/g, "&#039;");
}