Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalRamesh50 committed Oct 22, 2020
0 parents commit 72b1e34
Show file tree
Hide file tree
Showing 11 changed files with 7,004 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WEB_EXT_API_KEY=
WEB_EXT_API_SECRET=
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
node_modules/
web-ext-artifacts/
.web-extension-id
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# NUTabs

A browser extension which allows students to open job postings in a new tab since NUworks/Symplicity doesn't make this possible currently on the [Job Search Page](https://northeastern-csm.symplicity.com/students/app/jobs/search).

Works by replacing the job title `div` tags with `anchor` tags and linking them to where the job posting link would be.

Previous Behavior:

![Previous Behavior](https://media.giphy.com/media/hGDkI9xANHf7PRc2H1/giphy.gif)

With Extension:

![With Extension](https://media.giphy.com/media/L8TGpHcnrnwc4atwgB/giphy.gif)

Tested On:

- Firefox Browser Developer Edition (82.0b9 [64-bit])
- Google Chome (86.0.4240.80 [Official Build] [x86_64])

If for some reason it doesn't seem to work, try reloading the page. If it still doesn't work you can [create an issue](https://github.com/VishalRamesh50/NUTabs/issues) describing the problem.

## How Do I Add This to My Browser?

### Firefox

1. Download the [latest release](https://github.com/VishalRamesh50/NUTabs/releases/latest) `nutabs-version-an+fx.xpi` file from GitHub releases. If you download this while you're using Firefox it should ask you to add the extension right there. Give it permission to allow GitHub to install the extension, proceed, and you're done! If it didn't ask this, follow the next steps.
2. Open Firefox and type `about:addons` in your address bar.
3. Either drag and drop your `.xpi` file in the browser or click the gear icon for settings in the top right > Install add-on From File... and select the `.xpi` file.
4. Click the Add button when prompted.

### Google Chrome

1. Download the [latest release](https://github.com/VishalRamesh50/NUTabs/releases/latest) `nutabs-version.zip` file from GitHub releases.
2. Open Google Chrome and type `chrome://extensions/` in your address bar.
3. Make sure Developer Mode is toggled on in the top right.
4. Drag and drop the `.zip` file onto the browser and you're done! \
_If you see the warning/error:_ `Unrecognized manifest key: 'browser_specific_settings'` _you can safely ignore this. It will still work._

## How to Test Locally

_These notes are only if you are trying to develop for this extension. Ignore otherwise._

### Firefox

1. Install all dependencies

```sh
npm install
```

2. Run the extension with the right version of firefox.

```sh
npm run start[:nightly|:beta|:dev]
```

This means that if you want to run with the normal Firefox version you can do

```sh
npm run start
```

but if you want to run with a different version, for example, the DeveloperEdition Build you need to use

```sh
npm run start:dev
```

3. That's it! Any changes you make and save to the extension file should be reflected in the browser automatically.

Alternatively you could add it as a [temporary extension](https://extensionworkshop.com/documentation/develop/temporary-installation-in-firefox/) and test it that way.

### Google Chrome

Follow the steps to [add the extension normally](#google-chrome) but use the current working directory instead of the `.zip` file.
8 changes: 8 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Whenever a response from the job API is gotten, assume a job search has been
// performed and tell the content script to add its script to the page.
chrome.runtime.onConnect.addListener((p) => {
chrome.webRequest.onResponseStarted.addListener(() => p.postMessage({}), {
urls: ["https://northeastern-csm.symplicity.com/api/v2/jobs*"],
types: ["xmlhttprequest"],
});
});
Binary file added icons/new-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions jobTabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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;
const orgHTML = job.outerHTML.substring(4, job.outerHTML.length - 6);
const newHTML = "<a id='nutabs' href=" + '"' + jobURL + '"' + orgHTML + "</a>";
job.outerHTML = newHTML;
}
}
})();`;
// 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);
29 changes: 29 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"manifest_version": 2,
"name": "NUTabs",
"version": "0.1.0",
"description": "Adds ability to open job postings from NUworks in a new tab.",
"icons": {
"512": "icons/new-tab.png"
},
"content_scripts": [
{
"matches": [
"https://northeastern-csm.symplicity.com/students/app/jobs/*"
],
"js": ["jobTabs.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"browser_specific_settings": {
"gecko": {
"update_url": "https://raw.githubusercontent.com/VishalRamesh50/NUTabs/master/updates.json"
}
},
"permissions": [
"webRequest",
"https://northeastern-csm.symplicity.com/students/app/jobs/*"
]
}
Loading

0 comments on commit 72b1e34

Please sign in to comment.