-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
150 lines (118 loc) · 4.33 KB
/
script.js
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
const STATUS = {
IN_PROGRESS: 'inProgress',
GHOSTED: 'ghosted',
REJECTED: 'rejected',
INTERVIEW: 'interview',
OFFERS: 'offers'
};
document.addEventListener('DOMContentLoaded', () => {
loadApplications();
initializeTabNavigation();
initializeApplicationForm();
});
async function loadApplications() {
const applications = await getStoredApplications();
checkForGhostedApplications(applications);
displayApplicationsByStatus(applications);
}
async function getStoredApplications() {
return new Promise((resolve) => {
chrome.storage.local.get(['applications'], (result) => {
resolve(result.applications || []);
});
});
}
function saveApplications(applications) {
return new Promise((resolve) => {
chrome.storage.local.set({ applications }, resolve);
});
}
function checkForGhostedApplications(applications) {
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
applications.forEach(app => {
if (app.status === STATUS.IN_PROGRESS) {
const applicationDate = new Date(app.dateAdded);
if (applicationDate < thirtyDaysAgo) {
app.status = STATUS.GHOSTED;
}
}
});
saveApplications(applications);
}
function initializeTabNavigation() {
const tabs = document.querySelectorAll('.tab-btn');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
const tabPanes = document.querySelectorAll('.tab-pane');
tabPanes.forEach(pane => pane.classList.remove('active'));
document.getElementById(tab.dataset.tab).classList.add('active');
});
});
}
function initializeApplicationForm() {
const form = document.getElementById('applicationForm');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const companyName = document.getElementById('companyName').value;
const jobLink = document.getElementById('jobLink').value;
const newApplication = {
id: Date.now(),
companyName,
jobLink,
status: STATUS.GHOSTED,
dateAdded: new Date().toISOString()
};
const applications = await getStoredApplications();
applications.push(newApplication);
await saveApplications(applications);
form.reset();
loadApplications();
});
}
function displayApplicationsByStatus(applications) {
Object.values(STATUS).forEach(status => {
const container = document.querySelector(`#${status} .applications-list`);
container.innerHTML = '';
const filteredApps = applications.filter(app => app.status === status);
filteredApps.forEach(app => {
container.appendChild(createApplicationCard(app));
});
});
}
function createApplicationCard(application) {
const card = document.createElement('div');
card.className = 'application-card';
const dateBadge = document.createElement('span');
dateBadge.className = 'date-badge';
dateBadge.textContent = new Date(application.dateAdded).toLocaleDateString();
const title = document.createElement('h3');
title.textContent = application.companyName;
const link = document.createElement('a');
link.href = application.jobLink;
link.textContent = 'View Job Posting';
link.target = '_blank';
const statusSelect = document.createElement('select');
statusSelect.className = 'status-select';
Object.entries(STATUS).forEach(([key, value]) => {
const option = document.createElement('option');
option.value = value;
option.textContent = key.replace('_', ' ').toLowerCase();
option.selected = value === application.status;
statusSelect.appendChild(option);
});
statusSelect.addEventListener('change', async () => {
const applications = await getStoredApplications();
const index = applications.findIndex(app => app.id === application.id);
applications[index].status = statusSelect.value;
await saveApplications(applications);
loadApplications();
});
card.appendChild(dateBadge);
card.appendChild(title);
card.appendChild(link);
card.appendChild(statusSelect);
return card;
}