-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_0d.js
196 lines (179 loc) · 6.25 KB
/
content_0d.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
// get base document to revert to when search is undone
let originalHTML = document.body.innerHTML;
let oldSwitch = undefined;
// finds
const findAllSkills = (sendResponse) => {
debugger;
const notChar = (c)=>{
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(c) < 0;
}
let jobScannerSwitch, allSkills, userSkills,floatingDivToggle;
chrome.storage.sync.get(
['jobScannerSwitch','allSkills','userSkills','floatingDivToggle'],
(result) => {
jobScannerSwitch = result.jobScannerSwitch || false;
floatingDivToggle = result.floatingDivToggle;
allSkills = result.allSkills || [];
userSkills = result.userSkills || [];
if(oldSwitch === undefined)
oldswitch = jobScannerSwitch;
if(originalHTML === undefined){
console.log("started");
}
// if(originalHTML === undefined)
// originalHTML = document.body.innerHTML;
//
// if(!oldSwitch)
// originalHTML = document.body.innerHTML;
// if(!jobScannerSwitch){
// oldSwitch = jobScannerSwitch;
// document.body.innerHTML = originalHTML;
// deleteDiv();
// sendScore(null);
// return;
// }
allSkills = allSkills.sort((a,b)=>b.length - a.length);
userSkills = userSkills.sort((a,b)=>b.length - a.length);
let userCounter = {};
let allCounter = {};
// let setter = originalHTML;
// let inCode = false;
// let inQuotes = null;
// let sidx = 0;
//check if code is tag
// while(sidx < setter.length){
// if(inCode && !inQuotes && `\`"'`.indexOf(setter[sidx])>-1)
// inQuotes = setter[sidx];
// else if(inQuotes && setter[sidx] === inQuotes)
// inQuotes = null;
// else if(!inQuotes && setter[sidx]==="<")
// inCode = true;
// else if(!inQuotes && setter[sidx]===">")
// inCode = false;
// search all skills
// scans for keywords by checking strong + 1 char before and after
// let found = false;
// if(!inCode){
// for(let i = 0;i < userSkills.length;i++){
// if(userSkills[i].length < 1)
// continue;
//
// // checks if the keyword is in the beginning of the string
// let substring = setter.substring(sidx, sidx + userSkills[i].length);
// if(substring.toLowerCase() === userSkills[i].toLowerCase() &&
// notChar(setter[sidx - 1]) &&
// notChar(setter[sidx + userSkills[i].length])){
// // increase counter or set counter to 1 for skill
// if(!userCounter[userSkills[i]])
// userCounter[userSkills[i]] = 1;
// else
// userCounter[userSkills[i]] += 1;
//
// if(!allCounter[userSkills[i]])
// allCounter[userSkills[i]] = 1;
// else
// allCounter[userSkills[i]] += 1;
//
// // insert first half of highligh html
// const highlight1=`<span style="background-color:#00ffcc;">`;
// setter = setter.slice(0,sidx)
// + highlight1
// + setter.slice(sidx);
// sidx += highlight1.length + userSkills[i].length;
//
// const highlight2=`</span>`;
// setter = setter.slice(0,sidx)
// + highlight2
// + setter.slice(sidx);
// sidx += highlight2.length - 1;
//
// found = true;
// break;
// }
// }
// highlight for user
// if(!found){
// for(let i = 0;i < allSkills.length;i++){
// // checks if the keyword is in the beginning of the string
// let substring = setter.substring(sidx, sidx + allSkills[i].length);
// if(substring.toLowerCase() === allSkills[i].toLowerCase() &&
// notChar(setter[sidx - 1]) &&
// notChar(setter[sidx + allSkills[i].length])) {
// // increase counter or set counter to 1 for keyword
// if(!allCounter[allSkills[i]])
// allCounter[allSkills[i]] = 1;
// else
// allCounter[allSkills[i]] += 1;
//
// // insert first half of highligh html
// const highlight1="<span style='background-color:#ffaa80;'>";
// setter = setter.slice(0,sidx)
// + highlight1
// + setter.slice(sidx);
// sidx += highlight1.length + allSkills[i].length;
//
// const highlight2="</span>";
// setter = setter.slice(0,sidx)
// + highlight2
// + setter.slice(sidx);
// sidx += highlight2.length - 1;
//
// break;
// }
// }
// }
// }
// sidx++;
}
// document.body.innerHTML = setter;
const score = processScore(userCounter,allCounter);
if(floatingDivToggle)
createUpdateDiv(score);
else
deleteDiv();
sendScore(score);
oldSwitch = jobScannerSwitch;
}
);
};
window.onload = ()=> {
debugger;
chrome.storage.sync.get(
['jobScannerSwitch','allSkills','userSkills'],
(result) => {
jobScannerSwitch = result.jobScannerSwitch || false;
if(jobScannerSwitch)
findAllSkills();
}
)
};
const processScore = (userCounter, allCounter)=>{
let userScores = Object.values(userCounter);
let allScores = Object.values(allCounter);
let userScore = 0;
let allScore = 0;
const log2 = Math.log(2);
userScores.forEach(score=>{
userScore += 1 + Math.log(score)/log2;
});
allScores.forEach(score=>{
allScore += 1 + Math.log(score)/log2;
});
return Math.floor(userScore/allScore * 100 + .5) || 0;
};
chrome.runtime.onMessage.addListener(
(request, sender, sendResponse)=>{
switch(request.command){
case "findAllSkills":
debugger;
findAllSkills();
break;
default:
console.log('invalid request command');
break;
}
}
);
const sendScore = score=>{
chrome.runtime.sendMessage({score: score});
}