-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlanguage.js
More file actions
196 lines (174 loc) · 6.22 KB
/
language.js
File metadata and controls
196 lines (174 loc) · 6.22 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
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
async function waiting() {
console.log("Before sleep");
await sleep(7000); // Sleep for 7 seconds
console.log("After sleep [After 7 Seconds]");
return true;
}
async function sleep(ms) {
await new Promise((resolve) => setTimeout(resolve, ms));
}
// Fetches the job description from the DOM after waiting for the page to load
function getJobDesc() {
console.log("Running getJobDesc");
const jobDesc = document.getElementById("job-details");
if(jobDesc) {
console.log("jobDesc found");
var text = [];
jobDesc.childNodes.forEach((node) => {
text.push(node.textContent);
});
return text;
};
}
function flattenText(acquired_text) {
console.log("Running flattenText");
var arrayLength = acquired_text.length;
for (var i = 0; i < arrayLength; i++) {
acquired_text[i] = acquired_text[i].trim();
acquired_text[i] = acquired_text[i].replace(/\s+/g, " ");
acquired_text[i] = acquired_text[i].replace(/\n/g, " ");
acquired_text[i] = acquired_text[i].concat(acquired_text[i]," ");
}
var all_text = acquired_text.join(",");
all_text = all_text.replace(" , , , ,", " ");
all_text = all_text.replace(" ,", "");
all_text = all_text.toLowerCase();
return all_text;
}
// Searches the jobDesc for language keywords and returns a string of found languages
function getLanguageKeywords(fullText){
console.log("Running getLanguageKeywords");
const isGerman = /german\b/i.test(fullText) || /deutsch\b/i.test(fullText) || /deutschkenntnisse\b/i.test(fullText);
const isEnglish = /english\b/i.test(fullText) || /englischkenntnisse\b/i.test(fullText) || /englisch\b/i.test(fullText);
const isFrench = fullText.includes("français") || fullText.includes("french");
const isSpanish = fullText.includes("spanish");
const isItalian = fullText.includes("italian") || fullText.includes("italiano");
const isPortuguese = fullText.includes("portuguese");
const output = []
if (isGerman) {
output.push("German");
}
if (isEnglish) {
output.push("English");
}
if (isFrench) {
output.push("French");
}
if (isSpanish) {
output.push("Spanish");
}
if (isItalian) {
output.push("Italian");
}
if (isPortuguese) {
output.push("Portuguese");
}
output.sort();
const outputString = output.join(", ");
console.log("Language Keywords found: ", outputString);
return outputString;
}
function addLanguageBubble(fullText){
console.log("Running addLanguageBubble");
var parent = document.getElementsByClassName("job-details-fit-level-preferences");
var ref = parent[0];
var kids = ref.children;
var child = kids[0];
var languageLabel = child.cloneNode(true);
var outputLabel = "";
if (fullText === "") {
outputLabel = "No Language Specified";
} else {
const outputStr = "Languages: ";
outputLabel = outputStr.concat(fullText);
}
languageLabel.innerText = outputLabel;
ref.insertBefore(languageLabel,null);
return "bubble";
}
function addLanguageHighlight(fullText){
console.log("Running addLanguageHighlight");
var parent = document.getElementsByClassName("job-details-jobs-unified-top-card__job-insight job-details-jobs-unified-top-card__job-insight--highlight");
var ref = parent[0];
var example_detail = document.getElementsByClassName("job-details-jobs-unified-top-card__job-insight-view-model-secondary");
var languageLabel = example_detail[0].cloneNode(true);
const outputStr = "Languages: ";
const outputLabel = outputStr.concat(fullText);
languageLabel.innerText = outputLabel;
ref.insertBefore(languageLabel,null);
return "highlight";
}
function removeLanguageBubble(){
var parent = document.getElementsByClassName("job-details-fit-level-preferences");
var ref = parent[0];
var kids = ref.children;
var child = kids[kids.length-1];
child.remove();
console.log("attempted to remove bubble.");
return true;
}
function removeLanguageHighlight(){
var example_detail = document.getElementsByClassName("job-details-jobs-unified-top-card__job-insight-view-model-secondary");
var child = example_detail[example_detail.length-1];
child.remove();
console.log("attempted to remove highlight.");
return true;
}
function langLabelTry(fullText) {
try{
var labelType = addLanguageBubble(fullText);
console.log("lanLabelTry", labelType);
return labelType;
}
catch(err){
console.log('error: ', err);
var labelType = addLanguageHighlight(fullText);
return labelType;
}
}
async function jobObserver(currentLabel, retryDelay = 500){
setTimeout(() => {
var selectedJob = document.querySelector('div[aria-current="page"]');
if (!selectedJob) {
console.log("job var not found yet, retrying...");
jobObserver(retryDelay + 100);
return;
}
console.log('currentLabel', currentLabel);
var selectedJobBigElement = selectedJob.parentElement.parentElement;
var jobList = selectedJobBigElement.parentElement;
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === "childList") {
console.log("Child list mutation detected");
try{
removeLanguageBubble();
currentLabel = generalRunner();
}
catch(err){
// removeLanguageHighlight();
currentLabel = generalRunner();
}
};
});
});
observer.observe(jobList, { childList: true, subtree: true });
}, retryDelay)
}
async function generalRunner(){
console.log("Running generalRunner");
jobText = getJobDesc();
flattened = flattenText(jobText);
keywordsStr = getLanguageKeywords(flattened);
labelType = langLabelTry(keywordsStr);
return labelType;
}
async function main() {
waiting()
.then(() => {
generalRunner();
jobObserver(labelType);
return labelType;
})
}
main();