Skip to content

Commit

Permalink
Create extension
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjhanna committed Jul 9, 2016
0 parents commit e4417b4
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
![Chrome extension in action](showcase.gif?raw=true "SGA extension in action")

Use this extension when deciding subjects for next semester.

Don't waste your time looking up every subject by its code to find out its schedules.

## Installation
1. Clone the repo
2. [Load extension](https://developer.chrome.com/extensions/getstarted#unpacked)

## Usage
1. Go to SGA
2. Click on Legajo > Datos del Alumno > Analítico de notas
3. Refresh page and watch the shortcuts appear

27 changes: 27 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let subjectCode = null
let nextStep = null;

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
switch(request.type) {
case 'storeSubjectCode':
subjectCode = request.subjectCode
nextStep = 'searchSubject'
sendResponse({})
break
case 'hasSearchedPage':
nextStep = 'clickResults'
sendResponse({})
break
case 'hasFoundSubjectPage':
nextStep = 'showSchedules'
sendResponse({})
break
case 'requestAction':
sendResponse({ nextStep: nextStep, subjectCode: subjectCode })
break
case 'stop':
subjectCode = null
nextStep = null
break
}
});
75 changes: 75 additions & 0 deletions contentscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const send = (request, callback = (response => {})) => (
chrome.extension.sendMessage(request, callback)
)

const getLink = (text) => (
Array.from(document.querySelectorAll('a')).filter(a => a.innerText === text)[0]
)

const createShortcutLinks = () => {
Array.from(document.querySelectorAll('.subjectBackground')).forEach(e => {
const cell = e.querySelector('td')
const subjectCode = cell.querySelector('span.bold').innerText.match(/[0-9]{2}\.[0-9]{2}/)[0]
const link = document.createElement('a')
Array.from(cell.childNodes).forEach(child => link.appendChild(child))
link.href = '#'
link.addEventListener("click", () => openSearchPage(subjectCode), false);

cell.innerHTML = null
cell.appendChild(link)
})
}

const openSearchPage = (subjectCode) => {
send({ type: 'storeSubjectCode', subjectCode: subjectCode })
window.location = getLink('Cursos').href
}

const semesterFilterValue = () => {
const month = (new Date()).getMonth() + 1
if (month > 5 && month < 11) {
return 1 // You are looking for second semester info
} else {
return 0 // You are looking for first semester info
}
}

const searchSubject = (subjectCode) => {
// Subject code filter
document.querySelector('.filters-tr .filter-td input').value = subjectCode

// Semester filter
Array.from(document.querySelectorAll('.filters-tr .filter-td select')).filter(s => {
const options = Array.from(s.querySelectorAll('option')).map(o => o.innerText)
return options.includes('Primer Cuat.', 'Segundo Cuat.')
})[0].value = semesterFilterValue()

document.querySelector('a[title=Filtrar]').click()
send({ type: 'hasSearchedPage' })
}

const clickResults = (subjectCode) => {
send({ type: 'hasFoundSubjectPage' })
document.querySelector('tr img[title="Ver Detalles"]').click()
}

const showSchedules = () => {
send({ type: 'stop' })
getLink('Comisiones').click()
}

send({ type: 'requestAction' }, (response) => {
switch (response.nextStep) {
case 'searchSubject':
searchSubject(response.subjectCode)
break;
case 'clickResults':
clickResults(response.subjectCode)
break;
case 'showSchedules':
showSchedules()
break
}
})

createShortcutLinks()
Binary file added icon_19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon_38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const searchPage = Array.from(document.querySelectorAll('a')).filter(a => a.innerText === 'Cursos')[0]

// Every link

Array.from(document.querySelectorAll('.subjectBackground')).forEach(e => {
const cell = e.querySelector('td');
const subjectCode = cell.querySelector('span.bold').innerText.match(/[0-9]{2}\.[0-9]{2}/)[0];
cell.innerHTML = `<a href=foo'>${cell.innerHTML}</a>`
})
27 changes: 27 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifest_version": 2,
"name": "SGA - Subject Schedule Shortcut",
"description": "This extension create shortcuts to subject schedules",
"version": "1.0.0",
"minimum_chrome_version": "47",
"page_action": {
"default_icon": {
"19": "icon_19.png",
"38": "icon_38.png"
}
},
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [{
"matches": [
"https://sga.itba.edu.ar/*"
],
"js": ["contentscript.js"],
"run_at": "document_idle",
"all_frames": false
}]
}
Binary file added showcase.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e4417b4

Please sign in to comment.