docent_grades_downloader

Descarga notas en formato CSV

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         docent_grades_downloader
// @namespace    http://www.schooleando.es/
// @version      0.1
// @description  Descarga notas en formato CSV
// @author       Ruben Cancho
// @match        https://docent.edu.gva.es/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let checkExist = setInterval(function() {
        if (document.getElementsByClassName("imc-avaluacio").length) {
          let button = addButton("Descargar");
          document.getElementsByClassName("imc-avaluacio")[0].appendChild(button);
          clearInterval(checkExist);
        }
    }, 100);

    function addButton(text, onclick, cssObj) {
        cssObj = cssObj || {
            position: "fixed",
            top: "15%",
            right: "4%",
            "z-index": 3,
            fontWeight: "600",
            fontSize: "14px",
            backgroundColor: "#00cccc",
            color: "white",
            border: "none",
            padding: "10px 20px"
        };
        let button = document.createElement("button"),
            btnStyle = button.style;
        button.innerHTML = text;
        button.onclick = download_csv;

        return button;
    }

    function download_csv() {

        var csv = 'Nombre,Nota\n';
        var data = get_students();
        var materia = document.querySelector(".imc-av-materia").textContent;
        var curs = document.querySelector("li.imc-grup-nom").innerText
        curs = curs.substr(0, curs.indexOf(','));

        data.forEach(function(row) {
            csv += row.join(',');
            csv += "\n";
        });

        console.log(csv);
        var hiddenElement = document.createElement('a');
        hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
        hiddenElement.target = '_blank';
        hiddenElement.download = curs + materia + '.csv';
        hiddenElement.click();
    }

    function get_students() {
        var students = [];
        var students_dom = document.querySelectorAll("ul.imc-alumnes > li.imc-alumne");
        console.log(students_dom.length);
        for (var i=0, max=students_dom.length; i < max; i++) {
          var name = students_dom[i].querySelector("div.imc-nom > p").textContent.replace(/,/g, " ").toUpperCase();
          var grade = students_dom[i].getAttribute("data-qualificacio");
          console.log(name);
          students.push([name,grade]);
        }

        return students;
    }

})();