Added github contributors to options page

This commit is contained in:
sghsri
2020-08-23 23:11:01 -05:00
parent b2d46c186e
commit 908241fd67
6 changed files with 362 additions and 232 deletions

81
css/options.css Normal file
View File

@@ -0,0 +1,81 @@
.version {
padding: 0px 5px 5px 0px;
text-align: right;
}
.creator-tag {
margin: 10px 5px 5px 0px;
text-align: center;
}
.options-card {
width: 400px;
margin-left: auto;
margin-right: auto;
height: auto;
padding-bottom: 5px;
}
#version-container {
margin-left: auto;
margin-right: auto;
width: 400px;
}
.options-header {
padding: 16px 16px 0px 16px;
font-size: 20px;
}
#contributors_container {
text-align: center;
margin-top: 30;
padding: 5px 20px 20px 20px;
width: auto;
margin-right: 20%;
margin-left: 20%;
margin-top: 20px;
}
#contributor-list {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.contributor-card {
cursor: pointer;
padding: 5px;
max-width: 1200px;
margin: 0 auto;
text-align: center;
display: grid;
grid-gap: 1rem;
}
.contributor-card img {
width: 200px;
height: 200px;
}
.contributor-name {
font-weight: bold;
margin: 0;
}
.contributor-username {
margin: 0 0 5px 0;
font-style: italic;
}
.contributor-title {
margin-bottom: 0;
font-size: 15px;
}
.open-source-tag {
padding: 10px;
font-size: 16px;
}

View File

@@ -37,12 +37,12 @@ Template.Main = class {
</div>
</div>
</div>
</div>`
</div>`;
}
static extension_button() {
return `<td data-th="Plus"><input type="image" class="distButton" id="distButton" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`
}
return `<td data-th="Plus"><input type="image" class="distButton" id="distButton" width="20" height="20" src='${chrome.extension.getURL("images/disticon.png")}'/></td>`;
}
};
Template.Catalog = class {
static loading() {
return `<div style="text-align:center">
@@ -52,9 +52,9 @@ Template.Catalog = class {
<h1 id="retrylabel"style="color: #F44336;display:none;">Failed to Load Courses</h1>
<br>
<button class=material-button id="retry" style="background: #F44336;display:none;">Retry</button>
</div>`
}
</div>`;
}
};
Template.UTPlanner = class {
static modal() {
return `<div class=modal id=myModal>
@@ -83,25 +83,19 @@ Template.UTPlanner = class {
</div>
</div>
</div>
</div>`
}
</div>`;
}
};
Template.Calendar = class {
static line(line) {
let {
days,
start_time,
end_time,
location_link,
location_full
} = line;
let { days, start_time, end_time, location_link, location_full } = line;
return `<p class='time' style='font-size:large;'>
<span style='display:inline-block;'>${days}:</span>
<span style='margin-left:10px;display:inline-block;text-align:center;'>${start_time} to ${end_time}</span>
<span style='float:right;display:inline-block;text-align:right;width: 25%;'>
<a target='_blank' style='color:#3c87a3;text-decoration:none;'href='${location_link}'>${location_full}</a>
</span>
</p>`
</p>`;
}
static modal() {
return `<div id="myModal" class="modal">
@@ -121,9 +115,9 @@ Template.Calendar = class {
<button id="remove" class="matbut" style="font-size:medium;margin:10px;background: #FF0000;">Remove</button>
</div>
</div>
</div>`
}
</div>`;
}
};
Template.Popup = class {
static list_item(i, list_tile_color, unique, department, number, profname, list_sub_color, line) {
return `<li id='${i}' class='course_list_item'>
@@ -150,26 +144,20 @@ Template.Popup = class {
}
static conflict_message(conflict_message) {
return `<p id='conflict' class='conflict_message'>${conflict_message}</>`
return `<p id='conflict' class='conflict_message'>${conflict_message}</>`;
}
static line(line) {
let {
days,
start_time,
end_time,
location_link,
location_full
} = line;
let { days, start_time, end_time, location_link, location_full } = line;
return `<span class='time_line_days'>${days}:</span>
<span class='time_line_hours'>${start_time} to ${end_time}</span>
<span class='time_line_location'>
<a target='_blank' class= 'time_line_location_link' href='${location_link}'>${location_full}</a>
</span>
<br>`
}
<br>`;
}
};
Template.Import = class {
static import_button() {
return `<button class='material-button' id='import' style='margin:15px 0px;'>${Text.button_text_default}</button><br>`;
@@ -180,10 +168,9 @@ Template.Import = class {
}
static store_waitlist_message() {
return `<h1 id="nextlabel"style="color: #FF9800;display:none;"></h1>`
}
return `<h1 id="nextlabel"style="color: #FF9800;display:none;"></h1>`;
}
};
Template.Options = class {
static options_row(key, enabled) {
@@ -196,7 +183,14 @@ Template.Options = class {
<button id="${key}" value=${enabled} class="material-button" style="display:inline-block;font-size:medium; float:right; background:${button_color}">
${button_text}
</button>
<br>`
<br>`;
}
static contributor_card(username, name, image_url, profile_url) {
return `<div class='card contributor-card' id="${username}" data-url="${profile_url}">
<img class='contributor-image' src="${image_url}"></img>
${name ? `<p class='contributor-name'>${name}</p>` : ""}
<p class='contributor-username'>${username}</p>
</div>`;
}
}
};

View File

@@ -4,10 +4,10 @@ var departments = [];
var should_open = false;
const default_options = {
"loadAll": true,
"courseConflictHighlight": true,
"storeWaitlist": true,
}
loadAll: true,
courseConflictHighlight: true,
storeWaitlist: true,
};
onStartup();
@@ -72,7 +72,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
xhr.onload = () => {
console.log(xhr.responseUrl);
response(xhr.responseText);
}
};
xhr.onerror = () => response(xhr.statusText);
if (method == "POST") {
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -87,13 +87,16 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
setDefaultOptions();
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
if (!data.savedCourses) {
chrome.storage.sync.set({
savedCourses: new Array()
}, function () {
console.log('initial course list');
});
chrome.storage.sync.set(
{
savedCourses: new Array(),
},
function () {
console.log("initial course list");
}
);
}
});
} else if (details.reason == "update") {
@@ -102,11 +105,10 @@ chrome.runtime.onInstalled.addListener(function (details) {
}
});
chrome.storage.onChanged.addListener(function (changes) {
for (key in changes) {
console.log(changes);
if (key === 'savedCourses') {
if (key === "savedCourses") {
updateBadge(false, changes.savedCourses.newValue);
}
}
@@ -114,72 +116,80 @@ chrome.storage.onChanged.addListener(function (changes) {
function onStartup() {
updateBadge(true);
loadDataBase()
loadDataBase();
getCurrentSemesters();
getCurrentDepartments();
}
function getOptionsValue(key, sendResponse) {
chrome.storage.sync.get('options', function (data) {
chrome.storage.sync.get("options", function (data) {
if (!data.options) {
setDefaultOptions();
} else {
sendResponse({
'value': data.options[key]
value: data.options[key],
});
}
});
}
function setOptionsValue(key, value, sendResponse) {
chrome.storage.sync.get('options', function (data) {
chrome.storage.sync.get("options", function (data) {
let new_options = data.options;
if (!data.options) {
setDefaultOptions();
new_options = default_options;
}
new_options[key] = value;
chrome.storage.sync.set({
options: new_options
}, function () {
chrome.storage.sync.set(
{
options: new_options,
},
function () {
console.log(key);
console.log(new_options);
sendResponse({
'value': new_options[key]
});
value: new_options[key],
});
}
);
});
}
function setDefaultOptions() {
chrome.storage.sync.get('options', function (data) {
chrome.storage.sync.get("options", function (data) {
if (!data.options) {
chrome.storage.sync.set({
options: default_options
}, function () {
console.log('default options:');
chrome.storage.sync.set(
{
options: default_options,
},
function () {
console.log("default options:");
console.log(default_options);
});
}
);
}
});
}
function getCurrentSemesters() {
$.get('https://registrar.utexas.edu/schedules', function (response) {
$.get("https://registrar.utexas.edu/schedules", function (response) {
if (response) {
htmlToNode(response).find('.callout2>ul>li>a').each(function (i) {
htmlToNode(response)
.find(".callout2>ul>li>a")
.each(function (i) {
if (i < Popup.num_semesters) {
let sem_name = $(this).text().trim();
if (sem_name != "Course Schedule Archive") {
// $("#semesters").append(`<option>${sem_name}</option>`);
current_semesters[sem_name] = "code";
$.get($(this).attr('href'), function (response) {
$.get($(this).attr("href"), function (response) {
if (response) {
let response_node = htmlToNode(response);
let name = response_node.find(".page-title").text().substring(17).trim();
response_node.find('.gobutton>a').each(function () {
let link = $(this).attr('href');
var sem_num = link.substring(link.lastIndexOf('/') + 1).trim();
response_node.find(".gobutton>a").each(function () {
let link = $(this).attr("href");
var sem_num = link.substring(link.lastIndexOf("/") + 1).trim();
if (current_semesters[name] != sem_num) {
current_semesters[name] = sem_num;
}
@@ -193,12 +203,13 @@ function getCurrentSemesters(){
});
}
function getCurrentDepartments() {
$.get('https://catalog.utexas.edu/undergraduate/appendix-b/', function(response){
if(response){;
$.get("https://catalog.utexas.edu/undergraduate/appendix-b/", function (response) {
if (response) {
departments = [];
htmlToNode(response).find('.column1').each(function(i){
htmlToNode(response)
.find(".column1")
.each(function (i) {
if (i > 1) {
let abv = $(this).text();
departments.push(abv);
@@ -212,53 +223,51 @@ function updateBadge(first, new_changes) {
if (new_changes) {
updateBadgeText(first, new_changes);
} else {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
let courses = data.savedCourses;
updateBadgeText(first, courses);
});
}
}
function updateBadgeText(first, courses) {
let badge_text = courses.length > 0 ? `${courses.length}` : "";
let flash_time = !first ? 200 : 0;
chrome.browserAction.setBadgeText({
text: badge_text
text: badge_text,
});
if (!first) {
chrome.browserAction.setBadgeBackgroundColor({
color: Colors.badge_flash
color: Colors.badge_flash,
});
}
setTimeout(function () {
chrome.browserAction.setBadgeBackgroundColor({
color: Colors.badge_default
color: Colors.badge_default,
});
}, flash_time);
}
/* Find all the conflicts in the courses and send them out/ if there is even a conflict*/
function checkConflicts(sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var conflicts = [];
var courses = data.savedCourses;
for (let i = 0; i < courses.length; i++) {
for (let j = i + 1; j < courses.length; j++) {
let course_a = courses[i];
let course_b = courses[j];
if (isConflict(course_a.datetimearr, course_b.datetimearr))
conflicts.push([course_a, course_b]);
if (isConflict(course_a.datetimearr, course_b.datetimearr)) conflicts.push([course_a, course_b]);
}
}
if (conflicts.length == 0) {
sendResponse({
isConflict: false
isConflict: false,
});
} else {
sendResponse({
isConflict: true,
between: conflicts
between: conflicts,
});
}
});
@@ -266,7 +275,7 @@ function checkConflicts(sendResponse) {
/* Find if the course at unique and with currdatearr is contained in the saved courses and if it conflicts with any other courses*/
function isSingleConflict(currdatearr, unique, sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var courses = data.savedCourses;
var conflict_list = [];
var conflict = false;
@@ -284,14 +293,11 @@ function isSingleConflict(currdatearr, unique, sendResponse) {
sendResponse({
isConflict: conflict,
alreadyContains: contains,
conflictList: conflict_list
conflictList: conflict_list,
});
});
}
/* Check if conflict between two date-time-arrs*/
function isConflict(adtarr, bdtarr) {
for (var i = 0; i < adtarr.length; i++) {
@@ -312,25 +318,25 @@ function isConflict(adtarr, bdtarr) {
/* Add the requested course to the storage*/
function add(request, sender, sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var courses = data.savedCourses;
if (!contains(courses, request.course.unique)) {
courses.push(request.course)
courses.push(request.course);
console.log(courses);
chrome.storage.sync.set({
savedCourses: courses
savedCourses: courses,
});
}
sendResponse({
done: "Added: (" + request.course.unique + ") " + request.course.coursename,
label: "Remove Course -",
value: "remove"
value: "remove",
});
});
}
/* Find and Remove the requested course from the storage*/
function remove(request, sender, sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var courses = data.savedCourses;
console.log(courses);
var index = 0;
@@ -339,22 +345,22 @@ function remove(request, sender, sendResponse) {
}
courses.splice(index, 1);
chrome.storage.sync.set({
savedCourses: courses
savedCourses: courses,
});
sendResponse({
done: "Removed: (" + request.course.unique + ") " + request.course.coursename,
label: "Add Course +",
value: "add"
value: "add",
});
});
}
/* Find if the unique is already contained within the storage*/
function alreadyContains(unique, sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var courses = data.savedCourses;
sendResponse({
alreadyContains: contains(courses, unique)
alreadyContains: contains(courses, unique),
});
});
}
@@ -371,14 +377,14 @@ function contains(courses, unique) {
}
function isSameCourse(course, unique) {
return course.unique == unique
return course.unique == unique;
}
function updateTabs() {
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command: "updateCourseList"
command: "updateCourseList",
});
}
});
@@ -388,9 +394,8 @@ const UPDATE_INTERVAL = 1000 * 60 * 16;
setInterval(updateStatus, UPDATE_INTERVAL);
// updateStatus();
function updateStatus(sendResponse) {
chrome.storage.sync.get('savedCourses', function (data) {
chrome.storage.sync.get("savedCourses", function (data) {
var courses = data.savedCourses;
var no_change = true;
for (let i = 0; i < courses.length; i++) {
@@ -403,37 +408,34 @@ function updateStatus(sendResponse) {
success: function (result) {
if (result) {
console.log(result);
var object = $('<div/>').html(result).contents();
var object = $("<div/>").html(result).contents();
let new_status = object.find('[data-th="Status"]').text();
let register_link = object.find('td[data-th="Add"] a');
if (register_link)
register_link = register_link.attr('href');
var haschanged = (new_status == old_status && register_link == old_link);
if (!haschanged)
console.log(c.unique + ' updated from ' + old_status + " to " + new_status + " and " + old_link + " to " + register_link);
if (register_link) register_link = register_link.attr("href");
var haschanged = new_status == old_status && register_link == old_link;
if (!haschanged) console.log(c.unique + " updated from " + old_status + " to " + new_status + " and " + old_link + " to " + register_link);
no_change &= haschanged;
c.registerlink = register_link;
c.status = new_status;
}
}
},
});
} catch (e) {
console.log(e);
console.log('Not logged into UT Coursebook. Could not update class statuses.');
console.log("Not logged into UT Coursebook. Could not update class statuses.");
}
}
if (!no_change) {
chrome.storage.sync.set({
savedCourses: courses
savedCourses: courses,
});
console.log('updated status');
console.log("updated status");
}
});
}
function executeQuery(query, sendResponse) {
console.log(grades)
console.log(grades);
var res = grades.exec(query)[0];
sendResponse({
data: res,
@@ -443,7 +445,7 @@ function executeQuery(query, sendResponse) {
/* Load the database*/
function loadDataBase() {
sql = window.SQL;
loadBinaryFile('grades.db', function (data) {
loadBinaryFile("grades.db", function (data) {
var sqldb = new SQL.Database(data);
grades = sqldb;
});
@@ -460,4 +462,4 @@ function loadBinaryFile(path, success) {
success(arr.join(""));
};
xhr.send();
};
}

View File

@@ -3,25 +3,34 @@ Timing.fade_time = 100;
Timing.calendar_fade_time = 100;
Timing.button_delay = 75;
class Colors {}
Colors.material_colors = ['#4CAF50', '#CDDC39',
'#FFC107', '#2196F3', '#F57C00', '#9C27B0', '#FF5722', '#673AB7',
'#FF5252', '#E91E63', '#009688', '#00BCD4',
'#4E342E', '#424242', '#9E9E9E'
Colors.material_colors = [
"#4CAF50",
"#CDDC39",
"#FFC107",
"#2196F3",
"#F57C00",
"#9C27B0",
"#FF5722",
"#673AB7",
"#FF5252",
"#E91E63",
"#009688",
"#00BCD4",
"#4E342E",
"#424242",
"#9E9E9E",
];
Colors.open = "#4CAF50";
Colors.waitlisted = "#FF9800";
Colors.closed = "#FF5722";
Colors.no_status = "#607D8B";
Colors.open_light = "#C8E6C9";
Colors.waitlisted_light = "#FFE0B2";
Colors.closed_light = "#FFCCBC";
Colors.no_status_light = "#CFD8DC";
Colors.highlight_conflict = "#F44336";
Colors.highlight_default = "#333333";
Colors.highlight_saved = "#4CAF50";
@@ -29,31 +38,50 @@ Colors.highlight_saved = "#4CAF50";
Colors.badge_flash = "#FF5722";
Colors.badge_default = "#bf5700";
class Export {}
Export.png_options = {
foreignObjectRendering: true,
logging: true,
removeContainer: true,
async: true,
}
};
class Popup {}
Popup.num_semesters = 2;
class Text {}
Text.emptyText = function () {
let arr = ["Doesn't Look Like Anything To Me.", "You Can't Fail Classes You're Not In.", "Pro-Tip: Don't Take O-Chem.",
"No Work Happens On PCL 5th Floor.", "Sophomore But Freshman By Credit.", "Pain is temporary, GPA is forever.",
"You've Yee'd Your Last Haw.", "lol everything is already waitlisted.", "At Least You're Not At A&M.",
`It's ${moment().format("h:mm")} and OU Still Sucks.`, 'TeXAs iS BaCK GuYZ', "'Academically Challenged'",
'Does McCombs teach Parseltongue?', 'Lets make Daddy Fenves proud.', 'Feel bad if you say Wampus.', 'No Cruce Enfrente Del Bus.',
'Midterm 1 has been Unmuted', 'Omae Wa Mou Shindeiru...', 'Bevo Bucks are the new Bitcoin', 'Subway Robber > Machete Guy'
]
let arr = [
"Doesn't Look Like Anything To Me.",
"You Can't Fail Classes You're Not In.",
"Pro-Tip: Don't Take O-Chem.",
"Jendy's Fofofo™",
"Fine Dining at Jester City Limits",
"Rec Sports is full and it's only 2pm.",
"Hope Domino is doing well rn &#129402;",
"The year is 2055 and Welch still isn't finished.",
"Wear a Mask.",
"Motivation dropping faster than ur GPA",
"No Work Happens On PCL 5th Floor.",
"Sophomore But Freshman By Credit.",
"Pain is temporary, GPA is forever.",
"You've Yee'd Your Last Haw.",
"lol everything is already waitlisted.",
"At Least You're Not At A&M.",
`It's ${moment().format("h:mm")} and OU Still Sucks.`,
"TeXAs iS BaCK GuYZ",
"'Academically Challenged'",
"Does McCombs teach Parseltongue?",
"Feel bad if you say Wampus.",
"No Cruce Enfrente Del Bus.",
"Midterm 1 has been Unmuted",
"Omae Wa Mou Shindeiru...",
"Bevo Bucks are the new Bitcoin",
];
let index = Math.floor(Math.random() * arr.length);
return arr[index];
}
};
Text.button_text_default = "<span style='font-size:small'>Import to </span><b>UT Reg +<b>";
Text.waitlist_button_text_default = "<span style='font-size:small'>Import Waitlists to </span><b>UT Reg +<b>";
Text.button_success = "Courses Saved!";

View File

@@ -1,32 +1,50 @@
var manifestData = chrome.runtime.getManifest();
$("#version").text(manifestData.version);
chrome.storage.sync.get('options', function(data){
chrome.storage.sync.get("options", function (data) {
if (data.options) {
console.log(data.options);
Object.keys(data.options).forEach(key => {
let enabled = data.options[key];
$('#options_container').append(Template.Options.options_row(key, enabled));
$("#options_container").append(Template.Options.options_row(key, enabled));
});
}
});
$("body").on("click", "button", function () {
let key = $(this).attr('id');
let old_status = $(this).val() === 'true';
let key = $(this).attr("id");
let old_status = $(this).val() === "true";
let new_status = !old_status;
chrome.runtime.sendMessage({
chrome.runtime.sendMessage(
{
command: "setOptionsValue",
key: key,
value: new_status
}, function (response) {
value: new_status,
},
function (response) {
console.log(response.value);
toggle(key, response.value)
toggle(key, response.value);
updateAllTabsCourseList();
});
}
);
});
$.get("https://api.github.com/repos/sghsri/UT-Registration-Plus/stats/contributors", data => {
data = data.sort((a, b) => b.total - a.total);
console.log("data", data);
for (var contributorData of data) {
$.get(`https://api.github.com/users/${contributorData.author.login}`, userData => {
let fullData = { ...contributorData, ...userData };
let { login, avatar_url, html_url, name } = fullData;
$("#contributor-list").append(Template.Options.contributor_card(login, name, avatar_url, html_url));
});
}
});
$("body").on("click", ".contributor-card", function () {
console.log("hello world");
window.open($(this).data("url"), "_blank");
});
function toggle(key, value) {
let button_text = value ? "Turn Off" : "Turn On";

View File

@@ -1,23 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="css/styles.css" />
<link rel="stylesheet" href="css/options.css" />
</head>
<body>
<div class="card" style="width: 400px; margin-left:auto;margin-right: auto; height:auto;" id="header">
<h2 style="padding:16px 16px 0px 16px;font-size: 20px"> <u>Options</u> </h2>
<div id="options_container">
<div id="version-container">
<p class="version">(v<span id="version"></span>)</p>
</div>
<div class="card options-card" id="header">
<h2 class="options-header"><u>Options</u></h2>
<div id="options_container"></div>
<p class="creator-tag"><a href="https://sghsri.github.io">Sriram Hariharan</a> (2018)</p>
</div>
<p style="padding:0px 5px 5px 0px; float: right">(v<span id="version"></span>), Sriram Hariharan, 2018</p>
<div class="card options-card" id="contributors_container">
<h3 class="contributor-title">Amazing people who've contributed to the extension!</h3>
<p class="creator-tag open-source-tag">Code is open source here <a href="https://github.com/sghsri/UT-Registration-Plus">here</a> :)</p>
<div id="contributor-list"></div>
</div>
<script src="js/config.js"></script>
<script src="js/lib/jquery-3.3.1.min.js"></script>
<script src="js/util.js"></script>
<script src="js/Template.js"></script>
<script src="js/options.js"></script>
</body>
</html>