Last active
March 14, 2021 22:16
-
-
Save harsh183/4505b4870fb9a003abe5193e0f7b9c71 to your computer and use it in GitHub Desktop.
UIUC Course Explore Direct Search Modification. Normally the UIUC Course Website search bar doesn't directly let you go to the Course page directly as the search bar only takes the department. This adds the functionality without breaking any existing usage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name UIUC course explorer direct enter course number | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// @author Harsh Deep <harsh183> | |
// @date 2019-05-04 | |
// @for https://courses.illinois.edu/* | |
// This script modifies the search box in a way that directly entering the course | |
// number will go to the page instead of having to go to a subject page and then | |
// picking the course. This won't break existing entering nothing and being able | |
// to go to the course page though. | |
// Usage: | |
// The existing search box is modified so instead of typing | |
// `MATH` | |
// type | |
// `MATH 231` or `MATH231` | |
// schedule/DEFAULT/DEFAULT/MATH/231 | |
function getCourseInfo() { | |
const searchBox = document.getElementById("subjectAutoJump"); | |
const searchText = searchBox.value; | |
if (searchText === null) { | |
return; | |
} | |
const regexNumbers = /[0-9]+/ | |
const courseInfo = { | |
name: extractCourseName(searchText, regexNumbers), | |
number: extractCourseNumber(searchText, regexNumbers) | |
} | |
return courseInfo; | |
} | |
function extractCourseName(searchText, regexNumbers) { | |
return searchText.split(regexNumbers)[0].toUpperCase().trim(); | |
} | |
function extractCourseNumber(searchText, regexNumbers) { | |
const possibleCourseNumbers = searchText.match(regexNumbers); | |
if (possibleCourseNumbers === null) { | |
return; | |
} | |
return possibleCourseNumbers[0].trim(); | |
} | |
const search_form = document.getElementById("subjectAutoJump-form"); | |
search_form.addEventListener("submit", function(e) { | |
const courseInfo = getCourseInfo(); | |
if (courseInfo === null || courseInfo.number == null) { | |
return; | |
} | |
e.preventDefault(); | |
const newUrl = `https://courses.illinois.edu/schedule/DEFAULT/DEFAULT/${courseInfo.name}/${courseInfo.number}`; | |
window.location.href = newUrl; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using Greasemonkey to run this but it doesn't really depend on it.