-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
84 lines (73 loc) · 2.55 KB
/
Copy pathpopup.js
File metadata and controls
84 lines (73 loc) · 2.55 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
// Get current tab information
let currentTab = null;
let isPDF = false;
document.addEventListener('DOMContentLoaded', async () => {
// Get current tab
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
currentTab = tab;
// Check if current page is a PDF
isPDF = tab.url.toLowerCase().endsWith('.pdf') || tab.mimeType === 'application/pdf';
// Update UI based on page type
const pageTypeEl = document.getElementById('pageType');
if (isPDF) {
pageTypeEl.textContent = '📄 PDF detected - will upload this PDF';
} else {
pageTypeEl.textContent = '🌐 Webpage - will convert to PDF';
}
// Auto-fill title from page title
if (tab.title) {
document.getElementById('title').placeholder = tab.title;
}
// Check if settings are configured
const settings = await chrome.storage.sync.get(['paperlessUrl', 'paperlessToken']);
if (!settings.paperlessUrl || !settings.paperlessToken) {
showStatus('Please configure your Paperless-ngx settings first', 'warning');
document.getElementById('saveBtn').disabled = true;
}
// Event listeners
document.getElementById('saveBtn').addEventListener('click', handleSave);
document.getElementById('settingsLink').addEventListener('click', (e) => {
e.preventDefault();
chrome.runtime.openOptionsPage();
});
});
async function handleSave() {
const saveBtn = document.getElementById('saveBtn');
saveBtn.disabled = true;
saveBtn.textContent = 'Saving...';
try {
const title = document.getElementById('title').value || currentTab.title;
const tags = document.getElementById('tags').value
.split(',')
.map(tag => tag.trim())
.filter(tag => tag);
// Send message to background script
const response = await chrome.runtime.sendMessage({
action: 'saveToPaperless',
data: {
tabId: currentTab.id,
url: currentTab.url,
title: title,
tags: tags,
isPDF: isPDF
}
});
if (response.success) {
showStatus('✓ Successfully saved to Paperless-ngx!', 'success');
setTimeout(() => window.close(), 2000);
} else {
showStatus('Error: ' + response.error, 'error');
saveBtn.disabled = false;
saveBtn.textContent = 'Save to Paperless';
}
} catch (error) {
showStatus('Error: ' + error.message, 'error');
saveBtn.disabled = false;
saveBtn.textContent = 'Save to Paperless';
}
}
function showStatus(message, type) {
const statusEl = document.getElementById('status');
statusEl.textContent = message;
statusEl.className = `status ${type}`;
}