Script para ies

Script que agrega funcionalidades al tid

Verze ze dne 30. 10. 2017. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Script para ies
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Script que agrega funcionalidades al tid
// @author       Falaz
// @match        http://tid.ies21.edu.ar/*
// @grant        none
// ==/UserScript==

(function() {
    var tiempoInicial = new Date();
    try{
        var navbar = document.getElementsByClassName("ui-grid-b");
        navbar[0].id = "Hola";
        var a = document.getElementById("Hola");
        a.classList.remove("ui-grid-b");
    }catch (Exception){
        var navbar = document.getElementsByClassName("ui-grid-c");
        navbar[0].id = "Hola";
        var a = document.getElementById("Hola");
        a.removeChild(a.childNodes[3]);

    }

    a.classList.add("ui-grid-c");
    var liBtn = document.createElement("li");
    liBtn.id = "botonchito";
    liBtn.classList.add("ui-block-d");

    var aChild = document.createElement("a");
    var aSpan1 = document.createElement("span");
    var aSpan2 = document.createElement("span");
    var aSpan2icon = document.createElement("span");
    aChild.classList.add("ui-btn");
    aChild.classList.add("ui-btn-inline");
    aChild.classList.add("ui-btn-up-a");

    aSpan1.classList.add("ui-btn-inner");
    aSpan2.classList.add("ui-btn-text");

    aSpan2icon.classList.add("ui-btn-text");
    aSpan2icon.innerText = "\n";

    aChild.id = "achild";
    aChild.href= "javascript:void(0)";
    aChild.onclick= function(){
        tiempoInicial = new Date();
        return false;
    };

    aSpan1.appendChild(aSpan2icon);
    aSpan1.appendChild(aSpan2);
    aChild.appendChild(aSpan1);
    liBtn.appendChild(aChild);
    a.appendChild(liBtn);

    // Calcular tiempo de lectura
    var todosLosP = document.getElementsByTagName("p");
    var texto = "";
    for(i = 0;i<todosLosP.length;i++){texto += (todosLosP[i].innerText);}
    primerBlanco = /^ /;
    ultimoBlanco = / $/;
    variosBlancos = /[ ]+/g;
    texto = texto.replace (variosBlancos," ");
    texto = texto.replace(primerBlanco,"");
    texto = texto.replace(ultimoBlanco,"");
    textoTroceado = texto.split(" ");

    numeroPalabras = textoTroceado.length;

    console.log("Palabras contadas: " + numeroPalabras);
    console.log("El tiempo estimado de lectura, se basa en unas 150 o 100 palabras por minuto");
    console.log("Tiempo inicial: " + tiempoInicial);
    aSpan2.innerText = Math.round(numeroPalabras / 170) + " - "+ Math.round(numeroPalabras/130) + " min aprox\n";
    var b = false;
    var time = setInterval(myTimer, 1000);

    function myTimer() {
        if(b){b=false;}else{b=true;}
        var c = new Date();
        var segundos = (c.getTime() - tiempoInicial.getTime()) /1000;
        var min = Math.floor(segundos / 60);
        segundos = Math.round(segundos % 60);
        if(b){
            aSpan2icon.innerText = min + ":" + segundos+ "\n";
        }else{
            aSpan2icon.innerText = min + " " + segundos + "\n";
        }
    }
        function replaceLinks(){
        var botones = document.getElementsByClassName('ui-btn');
        var linksPrincipal = document.getElementsByClassName('ui-link-inherit');
        for(i=0;i<linksPrincipal.length;i++){
            linksPrincipal[i].setAttribute("target","_parent");
        }
        for(i=0;i<botones.length;i++){
            botones[i].setAttribute("target","_parent");
        }
        console.log("links reemplazados");
    }

     function replaceMedia(){
        var medias = $('.textoc');
        for (var i = 0; i < medias.length; i++) {
            if(medias[i].children){
                if(medias[i].children.length > 0 && medias[i].children[0] !== null){
                    var link;
                    var tipo = 'video';
                    link = medias[i].children[0].href;
                    var div = document.createElement('div');

                    replaceVideo(link, div, medias[i]);

                    div.id = 'media' + [i];
                    medias[i].appendChild(div);

                }
            }
            // $('#media' + [i]).load(link + '#containingBlock');
        }
    }
    function replaceVideo(link,div, medias){
        var xhr = new XMLHttpRequest();
        xhr.withCredentials = true;

        xhr.addEventListener("readystatechange", function () {
          if (this.readyState === 4) {
              //tomar el iframe del response. Para los videos de youtube.
              if(xhr.response.includes('iframe')){
                  //remove link and img from div

                  medias.children[0].remove();
                  var index = xhr.response.indexOf('<iframe');
                  var j = xhr.response.lastIndexOf('iframe>');
                  j+= 7;
                  var iframetext = xhr.response.substring(index,j);
                  var iframeSrc = iframetext.match(/src="([^"]+)"/);
                  var iframe = document.createElement('iframe');
                  iframe.src = iframeSrc[1];
                  iframe.height = 400;
                  iframe.width = 600;
                  div.appendChild(iframe);
                //   div.append("aquí estaba un video");
            }else{
                console.log("hay un elemento que no es un video. Aún no implementé la solución para eso :c");
            }

          }
        });

        xhr.open("GET", link);
        xhr.send('cache-control');
    }
    setTimeout(replaceLinks(),1000);
    setTimeout(replaceMedia(),1000);
})();