commit 5c55b6f921e6e217cf04682ac6aa297c3da6d9ff Author: Gaspard Jankowiak Date: Wed Oct 2 14:46:43 2024 +0200 import diff --git a/directory.css b/directory.css new file mode 100644 index 0000000..097f5f1 --- /dev/null +++ b/directory.css @@ -0,0 +1,19 @@ +#_kfrombi_columns_slider{display: inline-block; vertical-align: middle;} + +#_kfrombi_trombi { display: grid; grid-row-gap: 2em; font-size: 1.2em; text-align: center; } + +._kfrombi_trombi_3 { grid-template-columns: repeat(3, 1fr); } +._kfrombi_trombi_4 { grid-template-columns: repeat(4, 1fr); } +._kfrombi_trombi_5 { grid-template-columns: repeat(5, 1fr); } +._kfrombi_trombi_6 { grid-template-columns: repeat(6, 1fr); } +._kfrombi_trombi_7 { grid-template-columns: repeat(7, 1fr); } +._kfrombi_trombi_8 { grid-template-columns: repeat(8, 1fr); } + +.hidden { display: none; } +._kfrombi_trombi_img { + filter: grayscale(100%) contrast(150%); +} + +@media print { + .headerHeading, #idPageNavi {display: none;} +} diff --git a/directory.js b/directory.js new file mode 100644 index 0000000..2cc6cd4 --- /dev/null +++ b/directory.js @@ -0,0 +1,111 @@ +const C = document.createElement; +// const G = document.getElementById; + +const ordNrRegex = /.*pOrgNr=([0-9]+).*/gm; +const personalIDRegex = /.*pStPersonNr=([0-9]+).*/gm; + +function appendLink() { + if (document.getElementById("_kfrombi_row")) return; + + var row_header = document.createElement("th"); + row_header.textContent = "Trombi"; + + var link = document.createElement("a"); + link.textContent = "Toggle"; + link.href="#"; + link.addEventListener("click", toggleTrombi); + + var slider = document.createElement("input"); + slider.id = "_kfrombi_columns_slider"; + slider.type = "range"; + slider.value = 5; + slider.min = 3; + slider.max = 8; + + var column_nr = document.createElement("span"); + column_nr.id = "_kfrombi_column_nr"; + column_nr.textContent = slider.value; + var column_label = document.createElement("span"); + column_label.textContent = " columns"; + + slider.addEventListener("input", (event) => { + column_nr.textContent = slider.value; + const trombi = document.getElementById("_kfrombi_trombi"); + trombi.classList.remove( "_kfrombi_trombi_3", "_kfrombi_trombi_4", "_kfrombi_trombi_5", "_kfrombi_trombi_6", "_kfrombi_trombi_7", "_kfrombi_trombi_8" ); + trombi.classList.add(`_kfrombi_trombi_${slider.value}`); + }) + + var row_links = document.createElement("td"); + row_links.append(link, slider, column_nr, column_label); + + var tr = document.createElement("tr"); + tr.classList.add("coNavdocument.getElementByIdroup"); + tr.append(row_header, row_links); + tr.id = "_kfrombi_row"; + + const nav = document.getElementById("idPageNavi"); + nav.tBodies[0].append(tr); +} + +function extractIDs(url) { + return { + org: url.replace(ordNrRegex, "$1"), + perso: url.replace(personalIDRegex, "$1"), + } +} + +function generateCard(student, col) { + const url = `https://online.uni-graz.at/kfu_online/pl/ui/$ctx/wbstudkart.wbShowImage?pOrgNr=${student.ids.org}&pStPersonNr=${student.ids.perso}&pType=U` + + const d = document.createElement("div"); + d.style.gridColumn = "auto"; + + const img = document.createElement("img"); + img.classList.add("_kfrombi_trombi_img"); + img.src = url; + + const name_div = document.createElement("div"); + name_div.textContent = `${student.firstname} ${student.lastname}`; + + d.append(img, name_div); + return d; +} + +function toggleTrombi() { + const trombi = document.getElementById("_kfrombi_trombi"); + const form = document.getElementById("idTNListe"); + trombi.classList.toggle("hidden"); + form.classList.toggle("hidden"); +} + +function generateTrombi() { + var trombi = document.getElementById("_kfrombi_trombi"); + if (trombi) { trombi.remove(); } + const slider = document.getElementById("_kfrombi_columns_slider"); + trombi = document.createElement("div"); + trombi.id = "_kfrombi_trombi"; + trombi.classList.add("hidden"); + trombi.classList.add(`_kfrombi_trombi_${slider.value}`); + const form = document.getElementById("idTNListe"); + + const table_body = document.getElementById("idTNVWTable").tBodies[0]; + + const student_list = []; + for (let row of table_body.children) { + student_list.push({ + lastname: row.children[1].textContent, + firstname: row.children[2].textContent, + ids: extractIDs(row.children[1].children[1].href) + }) + }; + + student_list.forEach((student, idx) => { + trombi.append(generateCard(student, 1 + idx % 5)); + }); + + form.after(trombi); +} + +appendLink(); +generateTrombi(); + diff --git a/icons/icon-48.png b/icons/icon-48.png new file mode 100644 index 0000000..af43028 Binary files /dev/null and b/icons/icon-48.png differ diff --git a/icons/icon.svg b/icons/icon.svg new file mode 100644 index 0000000..bb2a3ab --- /dev/null +++ b/icons/icon.svg @@ -0,0 +1,119 @@ + + + + + + + + + + KFRombi + + + + + + + diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..5298b1f --- /dev/null +++ b/manifest.json @@ -0,0 +1,26 @@ +{ + "manifest_version": 2, + "name": "KFRombi", + "version": "0.1", + + "browser_specific_settings": { + "gecko": { + "id": "kfrombi@math.janko.fr" + } + }, + + "description": "Generates a directory of students with photos from online.uni-graz.at", + + "icons": { + "48": "icons/icon-48.png" + }, + + "content_scripts": [ + { + "matches": ["https://online.uni-graz.at/kfu_online/pl/ui/$ctx/wblvgrp.anmeldungen*"], + "js": ["directory.js"], + "css": ["directory.css"] + } + ] + +}