-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjobTabs.js
48 lines (47 loc) · 2.13 KB
/
jobTabs.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
const SCRIPT_ID = "nutabs-script";
const BASE_URL =
"https://northeastern-csm.symplicity.com/students/app/jobs/search";
const addJobLinks = () => {
// only attempt to do anything if it is on the base URL
if (!location.href.startsWith(BASE_URL)) {
return;
}
console.debug("NUTabs Script Triggered");
// remove an instance of a previously inserted NUTabs script if it exists
const prevScript = document.getElementById(SCRIPT_ID);
if (prevScript !== null) {
prevScript.remove();
}
const s = document.createElement("script");
s.type = "text/javascript";
s.id = SCRIPT_ID;
const code = `
(function getJobElements() {
const noJobResults = document.getElementsByClassName("empty-state ng-scope").length !== 0;
const loadingBar = document.getElementById('loading-bar');
const jobElements = document.getElementsByClassName('list-item-body') || [];
/* Wait for job results to appear.
If there are no results for this search result stop waiting. */
if ((jobElements.length === 0 || loadingBar) && !noJobResults) {
setTimeout(getJobElements, 1000);
} else {
/* Replace all job title with an anchor tags and add the job URLs to it */
for (const job of jobElements) {
const jobID = angular.element(job).scope().$ctrl.job.job_id;
const jobURL = "https://northeastern-csm.symplicity.com/students/app/jobs/detail/" + jobID;
job.outerHTML = job.outerHTML.replace(/^<div/, "<a id='nutabs' href='" + jobURL + "'").replace(new RegExp("</div>$"), "</a>");
}
}
})();`;
// add script to page
try {
s.append(document.createTextNode(code));
(document.head || document.documentElement).appendChild(s);
} catch (e) {
console.error(e);
s.text = code;
document.body.appendChild(s);
}
};
// Whenever the background script says a job search was performed execute the job script
chrome.runtime.connect({ name: "nutabs" }).onMessage.addListener(addJobLinks);