Skip to content

Instantly share code, notes, and snippets.

@harsh183
Last active March 14, 2021 22:16
Show Gist options
  • Save harsh183/4505b4870fb9a003abe5193e0f7b9c71 to your computer and use it in GitHub Desktop.
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.
// ==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;
});
@harsh183
Copy link
Author

harsh183 commented Apr 6, 2020

MIT License

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment