Skip to content

Commit

Permalink
Showing an error message on invalid URLs. Solves LambdaIITH#5
Browse files Browse the repository at this point in the history
  • Loading branch information
shraiysh committed Sep 2, 2020
1 parent ef30359 commit 749b570
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/gpa/activateGPA.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ add_checkboxes = function(){
}

show_total_gpa = function(){

if (document.location.href !== "https://aims.iith.ac.in/aims/courseReg/myCrsHistoryPage") {
return null;
}

var courses = [];
$('#gpa_button').val('Calculating');
$('#gpa_bar').remove();
Expand Down
6 changes: 5 additions & 1 deletion src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@
</head>
<body>
<div class="heading"><p>aims helper<p></div>
<p class="status" style="display: none">You are not on the AIMS Page. </p> <!-- Replace with JS checker later. -->
<p class="status" id="error-message" style="display: none;">You are probably not on the appropriate AIMS page. Goto <a
href="https://aims.iith.ac.in/aims/courseReg/studentRegForm/44">Course Registration</a> for timetable and <a
href="https://aims.iith.ac.in/aims/courseReg/myCrsHistoryPage">View my courses</a> for GPA.
If you think this is a mistake, please reach us at <a href="mailto:[email protected]"> [email protected]</a>
</p>
<div class="gpa-container">
<span class="gpa-text"> GPA </span><span class="gpa-text">=</span> <span class="gpa-text gpa-value"></span>
</div>
Expand Down
38 changes: 32 additions & 6 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@

var whichButton = 0 ; // 0 : no button has been clicked

// Show the error message div
function showError() {
document.getElementById("error-message").style.display = "block";
document.getElementsByClassName("button-container")[0].style.display = "none";
document.getElementById("loading-image").style.display = "none";
}


chrome.runtime.onMessage.addListener((request, sender) => {
if (request.action == "activateTimetable" && request.status == true)
{
onWindowLoad();
}
if (request.action == "activateTimetable" && request.status == true) {
onWindowLoad();
}
else {
showError();
}
});
chrome.runtime.onMessage.addListener(function(request, sender) {
if (request.action == "getSource") {
Expand Down Expand Up @@ -38,19 +49,29 @@ function onWindowLoad() {
function showLoading() {
document.getElementById("loading-image").style.display = "block";
document.getElementsByClassName("button-container")[0].style.display="none";
document.getElementById("error-message").style.display = "none"; // adding to avoid any risks!
}

function removeLoading() {
document.getElementById("loading-image").style.display = "none";
document.getElementsByClassName("button-container")[0].style.display = "block";
document.getElementById("error-message").style.display = "none"; // adding to avoid any risks!
}

function injectTimetable() {
showLoading();
chrome.tabs.executeScript(null, {
file: "/src/timetable/activateTimetable.js"
}, function() {
if (chrome.runtime.lastError) console.log(chrome.runtime.lastError.message);
}, function () {
if (chrome.runtime.lastError) {
switch (chrome.runtime.lastError.message) {
case "Cannot access a chrome:// URL":
showError();
break;
default:
console.log(chrome.runtime.lastError.message);
}
}
});
}

Expand All @@ -68,6 +89,11 @@ function injectGPA() {
}
chrome.runtime.onMessage.addListener(function(request, sender){
if(request.action == "parsedGPA"){

if (!request.data) {
return showError();
}

removeLoading();
var gpa_value = request.data.gpa;
document.getElementsByClassName("gpa-container")[0].style.display = "flex";
Expand Down
5 changes: 5 additions & 0 deletions src/timetable/activateTimetable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function activate() {

if (!(document.location.href === "https://aims.iith.ac.in/aims/courseReg/studentRegForm/44")) {
return false
}

var timeTabIcons = document.getElementsByClassName("time_tab_icon");
for (var i = 0 ; i < timeTabIcons.length ; i++)
{
Expand Down

0 comments on commit 749b570

Please sign in to comment.