Browse Source

stuff

master
Baltazár Radics 7 months ago
parent
commit
07b1944eaf
Signed by: baltazar GPG Key ID: 9440F591E4397C3E
  1. 65
      11.IB.json
  2. 33
      index.html
  3. 123
      index.js
  4. 8
      list.html
  5. 7
      list.js

65
11.IB.json

@ -32,11 +32,11 @@
}, {
"start": 5,
"len": 1,
"name": "inf"
"name": "ang"
}, {
"start": 5,
"len": 1,
"name": "bio"
"name": "ANG"
}, {
"start": 6,
"len": 1,
@ -66,11 +66,11 @@
}, {
"start": 4,
"len": 1,
"name": "ang"
"name": "inf"
}, {
"start": 4,
"len": 1,
"name": "ANG"
"name": "bio"
}, {
"start": 5,
"len": 1,
@ -235,79 +235,98 @@
"classes": {
"MAT": {
"pretty": "Maths HL",
"gc": "MjA5ODI0NDY5NDcy"
"gc": "MjA5ODI0NDY5NDcy",
"color": "#c26401"
},
"mat": {
"pretty": "Maths SL",
"gc": "MjA5OTYyOTUyNDIx"
"gc": "MjA5OTYyOTUyNDIx",
"color": ""
},
"fra": {
"pretty": "Francia",
"gc": "idk"
"gc": "idk",
"color": ""
},
"ném": {
"pretty": "Német",
"gc": "MjEwMzQzODEyMzE0"
"gc": "MjEwMzQzODEyMzE0",
"color": ""
},
"oro": {
"pretty": "Orosz",
"gc": "MjM3NzY4MDAyOTUz"
"gc": "MjM3NzY4MDAyOTUz",
"color": ""
},
"spa": {
"pretty": "Spanyol",
"gc": "idk"
"gc": "MjA5NzM0NzE3NjMx",
"color": ""
},
"mag": {
"pretty": "Magyar",
"gc": "MTcyNjUzNjM0NzE3"
"gc": "MTcyNjUzNjM0NzE3",
"color": "#202124"
},
"inf": {
"pretty": "CompSci",
"gc": "MjA5ODk1Mjg1Njg1"
"gc": "MjA5ODk1Mjg1Njg1",
"color": "#1967d2"
},
"bio": {
"pretty": "Biology",
"gc": "MjA5ODM3MjU2OTIx"
"gc": "MjA5ODM3MjU2OTIx",
"color": ""
},
"fiz": {
"pretty": "Physics",
"gc": "MjA5ODg1MzQ0MTcw"
"gc": "MjA5ODg1MzQ0MTcw",
"color": "#174ea6"
},
"tör": {
"pretty": "History",
"gc": "MjEwMzEzODM5Mzgy"
"gc": "MjEwMzEzODM5Mzgy",
"color": "#c26401"
},
"köz": {
"pretty": "Economics",
"gc": "MTcyNjYwNDY1NDk1"
"gc": "MTcyNjYwNDY1NDk1",
"color": "#007b83"
},
"pszi": {
"pretty": "Psychology",
"gc": "idk"
"gc": "MjExNTEyNDIxODE0",
"color": ""
},
"ang": {
"pretty": "English B",
"gc": "MjEwMDgyNDU2ODMz"
"gc": "MjEwMDgyNDU2ODMz",
"color": "#1967d2"
},
"ANG": {
"pretty": "English A",
"gc": "MjA5ODEyOTA5NTQx"
"gc": "MjA5ODEyOTA5NTQx",
"color": "#5f6368"
},
"tok": {
"pretty": "TOK",
"gc": "MjA5ODQ3ODc0ODQx"
"gc": "MjA5ODQ3ODc0ODQx",
"color": "#1967d2"
},
"ofo": {
"pretty": "Ofő",
"gc": "MzQ2NTY2MzQ0NTla"
"gc": "MzQ2NTY2MzQ0NTla",
"color": "#1967d2"
},
"kém": {
"pretty": "Kémia",
"gc": "MjA4OTMxNzQ3OTc5"
"gc": "MjA4OTMxNzQ3OTc5",
"color": ""
},
"KÉM": {
"pretty": "Kémia fakt",
"gc": "MjA2MzQ4MTMyMTM2"
"gc": "MjA2MzQ4MTMyMTM2",
"color": ""
}
}
}

33
index.html

@ -5,6 +5,10 @@
<title>Timetable</title>
<script src='index.js'></script>
<style>
html {
background-color: black;
color: white;
}
body {
font-size: large;
}
@ -39,6 +43,29 @@ a {
color: inherit;
display: block;
}
#bot {
display: inline-block;
text-align: right;
margin: 10px;
}
#bot>label {
display: block;
}
#bot>label>div {
display: inline-block;
position: relative;
}
#bot>label>div>a {
display: inline-block;
padding: 5px;
width: 150px;
text-align: center;
}
#progressbar {
position: absolute;
height: 100%;
z-index: -1;
}
</style>
</head><body>
@ -62,4 +89,10 @@ a {
</tbody>
</table>
<div id='bot'>
<label>Current lesson: <div><a id='cur'></a></div></label>
<label>Time left: <div><div id='progressbar'></div><a id='left'></a></div></label>
<label>Next lesson: <div><a id='next'></a></div></label>
</div>
</body></html>

123
index.js

@ -1,6 +1,6 @@
'use strict';
const days = [
const wdays = [
'Mon',
'Tue',
'Wed',
@ -8,57 +8,120 @@ const days = [
'Fri',
];
function mins(m) {
return 60000*m;
}
const day = 86400000;
// poor man's date
function pmd(h, m) {
return mins(60*h + m);
}
function cur_pmd() {
const now = new Date();
return (now.getTime() - mins(now.getTimezoneOffset())) % day + now.getDay() * day;
}
const starttimes = [
new Date(0, 0, 0, 7, 20),
new Date(0, 0, 0, 8, 0),
new Date(0, 0, 0, 8, 50),
new Date(0, 0, 0, 10, 0),
new Date(0, 0, 0, 10, 50),
new Date(0, 0, 0, 11, 40),
new Date(0, 0, 0, 13, 10),
new Date(0, 0, 0, 14, 0),
new Date(0, 0, 0, 14, 50),
pmd( 7,20),
pmd( 8, 0),
pmd( 8,50),
pmd(10, 0),
pmd(10,50),
pmd(11,40),
pmd(13,10),
pmd(14, 0),
pmd(14,50),
];
const formatter = new Intl.DateTimeFormat('default', { timeStyle: 'short', hour12: false });
let timetable = [];
let classes;
let guser;
function cur_lesson(time) {
let count = timetable.length;
let i = 0;
while (count > 0) {
const step = Math.floor(count / 2);
if (timetable[i + step].start <= time) {
i += step + 1;
count -= step + 1;
} else {
count = step;
}
}
return (i + timetable.length - 1) % timetable.length;
}
function update_times() {
const time = cur_pmd();
const c = cur_lesson(time);
const n = c + 1 % timetable.length;
const formatter = new Intl.DateTimeFormat('default', { timeStyle: 'medium', hourCycle: 'h23', timeZone: 'UTC' });
if (time < timetable[c].end) {
cur.innerText = classes[timetable[c].name].pretty;
cur.href = `https://classroom.google.com/u/${guser}/c/${classes[timetable[c].name].gc}`
cur.style['background-color'] = classes[timetable[c].name].color;
left.innerText = formatter.format(timetable[c].end - time);
progressbar.style.width = 100*(timetable[c].end - time)/(timetable[c].end - timetable[c].start) + '%';
progressbar.style['background-color'] = classes[timetable[c].name].color;
progressbar.style.right = 0;
} else {
cur.innerText = '-';
cur.href = null;
cur.style['background-color'] = null;
left.innerText = formatter.format(timetable[n].start - time);
progressbar.style.width = 100*(1 - (timetable[n].start - time)/(timetable[n].start - timetable[c].end)) + '%';
progressbar.style['background-color'] = classes[timetable[n].name].color;
progressbar.style.right = null;
}
next.innerText = classes[timetable[n].name].pretty;
next.href = `https://classroom.google.com/u/${guser}/c/${classes[timetable[n].name].gc}`
next.style['background-color'] = classes[timetable[n].name].color;
function addMinutes(date, minutes) {
let d = new Date(date);
d.setMinutes(d.getMinutes() + minutes);
return d;
setTimeout(update_times, 1000);
}
window.onload = async function() {
const formatter = new Intl.DateTimeFormat('default', { timeStyle: 'short', hourCycle: 'h23', timeZone: 'UTC' });
const params = new URLSearchParams(window.location.search);
const cls = params.get('class');
const filter = params.get('filter').split(',');
const guser = params.get('authuser') ?? '1';
guser = params.get('authuser') ?? '1';
const usecolor = +(params.get('color') ?? '0');
const thing = await (await fetch(cls+'.json')).json();
const table = thing.table;
const classes = thing.classes;
classes = thing.classes;
for (let i = 0; i < table.length; ++i) {
let row = document.createElement('tr');
let row = tbody.appendChild(document.createElement('tr'));
let num = 0;
let wd = document.createElement('td');
wd.innerText = days[i];
row.appendChild(wd);
row.appendChild(document.createElement('td')).innerText = wdays[i];
for (let lesson of table[i]) {
if (lesson.start < num)
continue;
if (!filter.includes(lesson.name))
continue;
if (lesson.start > num) {
let space = document.createElement('td');
space.colSpan = lesson.start - num;
row.appendChild(space);
}
let cell = document.createElement('td');
if (lesson.start > num)
row.appendChild(document.createElement('td')).colSpan = lesson.start - num;
let cell = row.appendChild(document.createElement('td'));
cell.colSpan = lesson.len;
cell.innerHTML = `<a href='https://classroom.google.com/u/${guser}/c/${classes[lesson.name].gc}'><div class='lesson'>${classes[lesson.name].pretty}</div><span class='startt'>${formatter.format(starttimes[lesson.start])}</span><span class='endt'>${formatter.format(addMinutes(starttimes[lesson.start], lesson.len*40))}</span></a>`;
if (usecolor && classes[lesson.name].color)
cell.style['background-color'] = classes[lesson.name].color;
const start = starttimes[lesson.start] + (i + 1) * day;
const end = start + mins(40*lesson.len);
cell.innerHTML = `<a href='https://classroom.google.com/u/${guser}/c/${classes[lesson.name].gc}'><div class='lesson'>${classes[lesson.name].pretty}</div><span class='startt'>${formatter.format(start)}</span><span class='endt'>${formatter.format(end)}</span></a>`;
cell.className = 'tile';
row.appendChild(cell);
timetable.push({
name: lesson.name,
cell: cell,
start: start,
end: end,
});
num = lesson.start + lesson.len;
}
tbody.appendChild(row);
}
update_times();
}

8
list.html

@ -8,6 +8,9 @@
body {
font-size: large;
}
td:nth-child(2), td:nth-child(4) {
font-family: monospace, monospace;
}
</style>
</head><body>
@ -19,13 +22,14 @@ body {
<th>Abbrev</th>
<th>Class name</th>
<th>Classroom id</th>
<th>Color</th>
</tr>
</thead>
<tbody id='tbody'>
</tbody>
</table>
<label>Google user num:</label><input type='text' value='1' id='authuser'>
<br>
<label>Google user num:<input type='text' value='1' id='authuser'></label><br>
<label>Use colors:<input type='checkbox' id='color'></label><br>
<a id='urlbox'></a>
</body></html>

7
list.js

@ -10,6 +10,7 @@ window.onload = async function() {
let url = 'https://balti.desnull.hu/timetable/index.html';
url += '?class='+cls;
url += '&authuser='+authuser.value;
url += '&color='+ +color.checked;
url += '&filter=';
let first = true;
for (let abbrev in classes) {
@ -52,9 +53,15 @@ window.onload = async function() {
croomc.innerText = classes[abbrev].gc;
row.appendChild(croomc);
let colorc = document.createElement('td');
colorc.innerText = classes[abbrev].color;
colorc.style.color = classes[abbrev].color;
row.appendChild(colorc);
tbody.appendChild(row);
}
authuser.onchange = genurl;
color.onchange = genurl;
genurl();
}
Loading…
Cancel
Save