jueves, 19 de marzo de 2009

Bloque T1.8 Ejercicio 1

// ==UserScript==
// @name AAP-Nav-Pachus
// @namespace http://geneura.org/projects/greasemonkey
// @description Navegación por las secciones de AAP
// @include http://geneura.ugr.es/~jmerelo/asignaturas/*
// ==/UserScript==

GM_log('Entrando AAP-Nav');
var ejercicios = document.getElementsByTagName('div');
GM_log(ejercicios);
var a_nodes = new Array;
var anchors = new Array;
var contador =0;
for ( var secs = 0; secs < ejercicios.length; secs ++ ) {
if(ejercicios[secs].getAttribute('class')=='ejercicios'){
a_nodes[contador] = ejercicios[secs].firstChild;
anchors[contador] = ejercicios[secs].getAttribute('id');
GM_log('Anchor ' + secs + " " + anchors[contador]);
contador++;
}
}



for ( var secs = 0; secs < ejercicios.length; secs ++ ) {
var span = document.createElement('span');
span.setAttribute('style','background:lightblue');
if ( secs > 0 ) {
var ahref = document.createElement('a');
ahref.setAttribute('href','#'+anchors[secs-1]);
var txt=document.createTextNode('^');
ahref.appendChild(txt);
span.appendChild(ahref);
}
if ( secs < ejercicios.length -1 ) {
span.appendChild(document.createTextNode(' | '));
var ahref = document.createElement('a');
ahref.setAttribute('href','#'+anchors[secs+1]);
var txt=document.createTextNode('v');
ahref.appendChild(txt);
span.appendChild(ahref);
}
a_nodes[secs].parentNode.insertBefore(span,a_nodes[secs]);
}


No hay comentarios:

Publicar un comentario