Skip to content

Commit

Permalink
Add feature to show time table of courses
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAkhondali committed Oct 5, 2017
1 parent 63fa9f1 commit 7fa3689
Show file tree
Hide file tree
Showing 17 changed files with 610 additions and 63 deletions.
47 changes: 47 additions & 0 deletions web-extension/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
let BrowserNameSpace;
if(typeof browser !== 'undefined' )
BrowserNameSpace = browser ;
else if(typeof chrome !== 'undefined' )
BrowserNameSpace = chrome;


function saveSections(sections,callback){
"use strict";
let store = {};
store["sections"] = sections;
BrowserNameSpace.storage.local.set(store,function () {
callback();//saving finished, notifiy caller
});
}

function getSections(callback) {
return BrowserNameSpace.storage.local.get("sections",(data)=>{
"use strict";
callback(data);//Getting finished, pass data to caller
});
}

function showTimeTable() {
let windowConfig = {
focused: true,
type: 'popup',
state:'maximized'
};

BrowserNameSpace.windows.create(windowConfig,(window)=>{
"use strict";
let wid = window.id;
let tabConfig ={
windowId:wid,
url:"timetable/index.html"
}

BrowserNameSpace.tabs.create(tabConfig, (tab)=>{
//We are inside the time table tab, Lets push sections
//So what? He'll handle it himself
});

});

}


// Nothing here...
// just a comment for firefox manifest
Expand Down
3 changes: 2 additions & 1 deletion web-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"<all_urls>",
"webRequest",
"webRequestBlocking",
"tabs"
"tabs",
"storage"
],
"version": "0.2"
}
4 changes: 4 additions & 0 deletions web-extension/popup/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ body,html {
}


#generate_schulde{
width: 100%;
margin-top: 80px;
}
Binary file modified web-extension/popup/fonts/Vazir.eot
Binary file not shown.
Binary file modified web-extension/popup/fonts/Vazir.ttf
Binary file not shown.
Binary file modified web-extension/popup/fonts/Vazir.woff
Binary file not shown.
Binary file added web-extension/popup/fonts/Vazir.woff2
Binary file not shown.
76 changes: 19 additions & 57 deletions web-extension/popup/js/final.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,27 @@ $(document).ready(function () {


$("#generate_schulde").on('click',function () {
//Before telling what i'm doing here, i would like to say FUCK YOU SAMA
//FUCK YOUR CREATORS
//FUCK YOUR DESIGNERS
//FUCK ANY UNIVERSITY WHICH PAYED YOU FOR THIS SHIT
//Ok let's go on, it's 3:47am now and i've just started writing this shit
//There is no fucking id attribute or any fucking class to find which table are they using
//To show data of schedule, So i should to it dirty too ...
BrowserNameSpace.tabs.executeScript(null,
{
allFrames:true,
file: "/popup/js/jquery-2.2.4.min.js"
}, function(){
BrowserNameSpace.tabs.executeScript(null,
{
allFrames:true,
file:"/scripts/findthemall.js"
}, function(res){
//res is an array, mostly null. Cause it executed script on all pages
//We'll only select items which are not null
res = res.filter((i)=>i!= null)[0];
let BG = BrowserNameSpace.extension.getBackgroundPage();
BG.saveSections(res,()=>{
"use strict";
BG.showTimeTable();
});


let section_data = [];

//First, I'll find 9th td of any table, the only table which has it is the schedule
//So now let's go to grandparent to get main table
let sch_table = $("table td:nth-child(9)").parent().parent();

//Select all rows and set it to tr, I know the variable "tr" is redundant here
//But i love it so much <3 My codes = My rules . It's non of your fucking businesses.
let tr = sch_table.children();

//Skip first and second rows, Cause they are shit
for (let i=2;i<tr.length;i++){
//Shows there is only one fucking row, so it's the time of class
if (tr[i].firstChild.children.length == 1){
let section_data = tr[i].firstChild.children[0].innerText.trim().split("\n");
let className = tr[i-1].children[1].firstChild.innerText;

let classData = {
name: className,
};

let sections = [];

for(section in section_data){
let section_info = section.split("،");

const
class_date = section_info[0],
place = section_info[1],
teacher = section_info[2];

const posOfDay = class_date.indexOf(':');
const nameOfDay = class_date.substr(0,posOfDay);

const fromTo = class_date.substring(pposOfDay+2,class_date.length-2).split(" تا ");
const classPlace = place.substring(place.indexOf("(")+1,place.length-2).trim();
const teacherName = teacher.substring(teacher.indexOf("(")+1,teacher.length-2).trim().replace("_"," ");
sections.append({
day: nameOfDay.trim(),
from: fromTo[0].trim(),
to: fromTo[1].trim(),
place: classPlace,
teacher: teacherName
});
}
classData["sections"] = sections;
section_data.append(classData);
}
}//End for loop

});
});


Expand Down
3 changes: 1 addition & 2 deletions web-extension/popup/js/popup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
var BrowserNameSpace;
let BrowserNameSpace;
if(typeof browser !== 'undefined' )
BrowserNameSpace = browser ;
else if(typeof chrome !== 'undefined' )
Expand Down Expand Up @@ -31,7 +31,6 @@ function fillOptions(percent,bypass_filter,send) {
allFrames:true,
file: "/scripts/fillthemall.js"},
function(){
//Inserted ...
});
});
}
4 changes: 2 additions & 2 deletions web-extension/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<h1 id="header_name">GSama</h1>

<ul id="tabs-swipe-demo" class="tabs">
<li class="tab col s6"><a class="active" href="#vote">ارزشیابی</a></li>
<li class="tab col s6"><a href="#weekschelude">برنامه هفتگی</a></li>
<li class="tab col s6"><a href="#vote">ارزشیابی</a></li>
<li class="tab col s6"><a class="active" href="#weekschelude">برنامه هفتگی</a></li>
</ul>

<div id="vote" class="budget-wrap" style="width: 400px;padding-top: 15px;">
Expand Down
1 change: 0 additions & 1 deletion web-extension/scripts/fillthemall.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions web-extension/scripts/findthemall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
if (typeof $($("table td:nth-child(9)")[0]).parent().parent()[0] !== "undefined"){

// let BrowserNameSpace;
// if(typeof browser !== 'undefined' )
// BrowserNameSpace = browser ;
// else if(typeof chrome !== 'undefined' )
// BrowserNameSpace = chrome;


//Before telling what i'm doing here, i would like to say FUCK YOU SAMA
//FUCK YOUR CREATORS
//FUCK YOUR DESIGNERS
//FUCK ANY UNIVERSITY WHICH PAYED YOU FOR THIS SHIT
//Ok let's go on, it's 3:47am now and i've just started writing this shit
//There is no fucking id attribute or any fucking class to find which table are they using
//To show data of schedule, So i should to it dirty too ...


let all_section_data = [];

//First, I'll find 9th td of any table, the only table which has it is the schedule
//So now let's go to grandparent to get main table
let sch_table = $($("table td:nth-child(9)")[0]).parent().parent();

//Select all rows and set it to tr, I know the variable "tr" is redundant here
//But i love it so much <3 My codes = My rules . It's non of your fucking businesses.
let tr = sch_table.children();


//Skip first and second rows, Cause they are shit
for (let i=2;i<tr.length;i++){
//Shows there is only one fucking row, so it's the time of class
if (tr[i].children.length == 1 && tr[i].innerText != ""){
let section_data = tr[i].firstChild.children[0].innerText.trim().split("\n");
let className = tr[i-1].children[1].firstChild.innerText;
let sections = [];
let classData = {
name: className,
};

for(let section of section_data){
let section_info = section.split("،");

const
class_date = section_info[0],
place = section_info[1],
teacher = section_info[2];

const posOfDay = class_date.indexOf(':');
const nameOfDay = class_date.substr(0,posOfDay);

const fromTo = class_date.substring(posOfDay+2,class_date.length-2).split(" تا ");
const classPlace = place.substring(place.indexOf("(")+1,place.length-2).trim();
const teacherName = teacher.substring(teacher.indexOf("(")+1,teacher.length-2).trim().replace("_"," ");
sections.push({
name: className,
day: nameOfDay.trim(),
start: fromTo[0].trim(),
end: fromTo[1].trim(),
place: classPlace,
teacher: teacherName
});
}
classData["sections"] = sections;
all_section_data.push(classData);
}
}//End for loop


all_section_data
}
Loading

0 comments on commit 7fa3689

Please sign in to comment.