-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
208 lines (184 loc) · 5.4 KB
/
popup.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
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
//get info for searching and editting skills
let jobScannerSwitch,userSkills,floatingDivToggle;
chrome.storage.sync.get(
['jobScannerSwitch','userSkills','floatingDivToggle'],
(result) => {
jobScannerSwitch = result.jobScannerSwitch || false;
floatingDivToggle = result.floatingDivToggle;
userSkills = result.userSkills || [];
let onoff = document.getElementById('onoff');
if(jobScannerSwitch){
onoff.innerText = 'Turn Off';
onoff.setAttribute('style','background-color:red;')
}
else{
onoff.innerText = 'Turn On';
onoff.setAttribute('style','background-color:#00ffcc;')
}
let toggle = document.getElementById('toggleFloatingDiv');
if(floatingDivToggle){
toggle.innerText = 'Hide Floating Element';
toggle.setAttribute('style','background-color:red;');
}
else{
toggle.innerText = 'Show Floating Element';
toggle.setAttribute('style','background-color:#00ffcc;');
}
setSkillsHTML();
document.getElementsByTagName('input')[0].focus();
}
);
const originalForm = document.getElementsByTagName('form')[0].innerHTML;
// lists the skills and delete buttons in popup
const setSkillsHTML = ()=>{
const form = document.getElementsByTagName('form')[0];
// add UI for each skill
let skillList = "";
for(let i = 0;i < userSkills.length;i++){
skillList += "<div id='skill'>" +
userSkills[i] +
"<button type='button' id='button"+i+"'>X</button>" +
"</div>"
}
form.innerHTML = skillList + originalForm;
// add button functionality to X's
for(let i = 0;i < userSkills.length;i++){
let el = document.getElementById('button'+i);
el.onclick = element=>{
deleteSkill(i);
};
}
}
// delete skill from userskill list
const deleteSkill = i=>{
userSkills.splice(i,1);
chrome.storage.sync.set(
{"userSkills":userSkills},
()=>{
setSkillsHTML();
document.getElementsByTagName('input')[0].focus();
chrome.tabs.query(
{active: true, currentWindow: true},
tabs =>chrome.tabs.sendMessage(
tabs[0].id,
{command: "findAllSkills"}
)
);
}
);
}
// set functionality of floating div toggle
let toggle = document.getElementById('toggleFloatingDiv');
toggle.onclick = function(element){
floatingDivToggle = !floatingDivToggle;
let toggle = document.getElementById('toggleFloatingDiv');
if(floatingDivToggle){
toggle.innerText = 'Hide Floating Element';
toggle.setAttribute('style','background-color:red;');
}
else{
toggle.innerText = 'Show Floating Element';
toggle.setAttribute('style','background-color:#00ffcc;');
}
chrome.storage.sync.set(
{'floatingDivToggle':floatingDivToggle},
()=>{
document.getElementsByTagName('input')[0].focus();
chrome.tabs.query(
{active: true, currentWindow: true},
tabs => {
chrome.tabs.sendMessage(
tabs[0].id,
{command: "findAllSkills"}
);
}
);
}
);
}
// set function of onoff switch
let onoff = document.getElementById('onoff');
onoff.onclick = function(element){
jobScannerSwitch = !jobScannerSwitch;
if(jobScannerSwitch){
onoff.innerText = 'Turn Off';
onoff.setAttribute('style','background-color:red;')
}
else{
onoff.innerText = 'Turn On';
onoff.setAttribute('style','background-color:#00ffcc;')
}
chrome.storage.sync.set(
{'jobScannerSwitch': jobScannerSwitch},
()=>{
document.getElementsByTagName('input')[0].focus();
chrome.tabs.query(
{active: true, currentWindow: true},
tabs => {
chrome.tabs.sendMessage(
tabs[0].id,
{command: "findAllSkills"}
);
}
);
}
);
};
const updateScore=(score)=>{
console.log('update score');
let scoreDiv = document.getElementById('scoreDiv');
if(score !== null)
scoreDiv.innerText = `Score: ${score}%`;
else
scoreDiv.innerText = null;
}
// set form functionality
let form = document.getElementsByTagName('form')[0];
form.oninput = (e)=>{
let textinput = document.getElementsByTagName('input')[0];
textinput.setAttribute('style', `width:${textinput.value.length * 16}px;`);
}
form.onsubmit = (element)=>{
// saves input to local storage
let input = document.getElementsByTagName('input')[0].value.trim();
if(input.length > 0 && userSkills.indexOf(input.toLowerCase())<0){
userSkills.push(input);
chrome.storage.sync.set(
{'userSkills':userSkills},
()=>{
jobScannerSwitch = true;
chrome.storage.sync.set(
{'jobScannerSwitch': true},
()=>{
// send message to active tab to start search
chrome.tabs.query(
{active: true, currentWindow: true},
tabs =>chrome.tabs.sendMessage(
tabs[0].id,
{command: "findAllSkills"}
)
);
setSkillsHTML();
document.getElementsByTagName('input')[0].focus();
}
);
}
);
}
};
document.body.onclick = e=>{
document.getElementsByTagName('input')[0].focus();
}
chrome.runtime.onMessage.addListener(
function(request,sender,sendResponse){
console.log(request.score);
updateScore(request.score);
}
)
chrome.tabs.query(
{active: true, currentWindow: true},
tabs =>chrome.tabs.sendMessage(
tabs[0].id,
{command: "findAllSkills"}
)
);