/*
Copyright (c) 2019 Ali Mousavi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
KhayyamJS changes the UI of the presented course list in the student portal
of Khayyam university of Mashhad. It might also work in some other universities
that might use the same portal.
Author: Ali Mousavi (ali.mousavi@gmail.com)
Github: https://github.com/tuxitop/khayyamJS
*/
// ==UserScript==
// @name khayyamJS
// @namespace http://alimsvi.ir/
// @description changes the UI of the presented course list in the student portal of Khayyam university of Mashhad.
// @include https://pooya.khayyam.ac.ir/educ/stu_portal/PresentedCoursesForm.php
// @version 0.6
// @author Ali Mousavi
// @require https://code.jquery.com/jquery-1.10.2.js
// @require https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js
// @grant none
// ==/UserScript==
// define page class.
var Page = function() {
/* Main page class */
// Public methods.
this.infoObj = {
courses: [],
fields: [],
bldgs: []
};
this.courses = this.infoObj.courses;
this.fields = this.infoObj.fields;
this.bldgs = this.infoObj.bldgs;
this.filters = {
field: 'all',
gender: 'all',
bldg: 'all',
weight: 'all',
days: [0, 1, 2, 3, 4, 5],
hours: [0, 1, 2, 3, 4]
};
};
Page.prototype.updateInfo = function(doc) {
var mkInfo = function(doc) {
/* creates and returns an object with different arrays to use
in filters, etc. */
var coursesArray = [];
var fieldsArray = [];
var fieldIDsArray = [];
var bldgArray = [];
// loop through each table row.
$('table:eq(1) tr', $(doc)).each(function(i, row) {
// find each column in the row and add it to courseColArray.
var courseColArray = [];
var columns = $(this).find('td');
columns.each(function() {
courseColArray.push($(this).html());
});
// this if is because the header line doesn't have any "td"s
if (courseColArray.length) {
var course = new Course(i, courseColArray);
coursesArray.push(course);
// add fields if it's not added before
var field = course.degree + ' ' + course.field;
if (fieldsArray.indexOf(field) === -1) {
fieldsArray.push(field);
}
var fieldID = course.fieldID;
if (fieldIDsArray.indexOf(fieldID) === -1) {
fieldIDsArray.push(fieldID);
}
// Add bldgs the same way as fields
if (bldgArray.indexOf(course.bldg) === -1) {
bldgArray.push(course.bldg);
}
}
});
return {
courses: coursesArray,
fields: fieldsArray,
fieldIDs: fieldIDsArray,
bldgs: bldgArray
};
};
this.infoObj = mkInfo(doc);
this.courses = this.infoObj.courses;
this.fields = this.infoObj.fields;
this.fieldIDs = this.infoObj.fieldIDs;
this.bldgs = this.infoObj.bldgs;
this.updateFilters();
};
Page.prototype.updateFilters = function() {
this.filters = {
field: 'all',
gender: 'all',
bldg: 'all',
weight: 'all',
days: [0, 1, 2, 3, 4, 5],
hours: [0, 1, 2, 3, 4]
};
// Loop to create options for field select.
var fieldOptions = '';
this.fieldIDs.map(function(current) {
fieldOptions += '';
});
// Loop to create options for building select.
var bldgOptions = '';
this.bldgs.map(function(current) {
bldgOptions += '';
});
$('#field-select')
.children()
.remove();
$('#field-select').append('');
$('#field-select').append(fieldOptions);
$('#bldg-select')
.children()
.remove();
$('#bldg-select').append('');
$('#bldg-select').append(bldgOptions);
};
Page.prototype.updateGroups = function(faculty) {
$.ajax({
method: 'GET',
url: 'EduGrpSelect.php',
// url: './updateGroupsResponse.html'
data: { FacCode: faculty, SelName: '"EduGrp"' }
}).done(function(data) {
var grpReg = /option value="(\d+)">(.+?)همه گروههای آموزشی'];
var matchArray = [];
while ((matchArray = grpReg.exec(data)) != null) {
optionsArray.push(
''
);
}
$('#group-select').html(optionsArray.join(''));
});
};
// create a prototype (this way I can have private methods)
Page.prototype.mkBody = function() {
// makes the page ready and creates the body of the page.
$('center')
.prevAll('script')
.remove();
$('center, style, link').remove();
// add necessary styleseets.
$('head').append(
'' +
'' +
'' +
'' +
''
);
//navbar
$('body').append(
''
);
$('.navbar-nav').data('size', 'big');
$(window).scroll(function() {
if ($(document).scrollTop()) {
if ($('.navbar-nav').data('size') === 'big') {
$('.navbar-nav li a, .navbar-brand').animate({
padding: '3px 15px 0 15px',
height: '30px'
});
$('.navbar-nav').data('size', 'small');
}
} else if ($('.navbar-nav').data('size') === 'small') {
$('.navbar-nav li a, .navbar-brand').animate({
padding: '15px 15px 10px 15px',
height: '50px'
});
$('.navbar-nav').data('size', 'big');
}
});
$('#about-link').click(function(event) {
event.preventDefault();
$('#about-container').slideToggle();
$('#about-link').toggleClass('clicked');
});
// the jumbotron
$('body').append(
'