„Benutzer:Lustiger seth/section jumpers.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
K debugging: fixed check |
feat: extended to h3 elements |
||
Zeile 1: | Zeile 1: | ||
/* |
/* |
||
task: add up/down arrows at the end of each major section title (h2 |
task: add up/down arrows at the end of each major section title (h2, h3) |
||
in order to jump to previous or next section respectively |
in order to jump to previous or next section respectively |
||
tested in firefox only |
tested in firefox only |
||
*/ |
*/ |
||
$(function (){ |
$(function (){ |
||
const |
const h_elems = document.getElementById("mw-content-text").querySelectorAll("h2, h3"); |
||
const arr = Array.from( |
const arr = Array.from(h_elems); |
||
for(let i = 1; i < arr.length; ++i){ |
for(let i = 1; i < arr.length; ++i){ |
||
arr[i].style.display = "flex"; |
arr[i].style.display = "flex"; |
Version vom 20. Februar 2022, 10:52 Uhr
/*
task: add up/down arrows at the end of each major section title (h2, h3)
in order to jump to previous or next section respectively
tested in firefox only
*/
$(function (){
const h_elems = document.getElementById("mw-content-text").querySelectorAll("h2, h3");
const arr = Array.from(h_elems);
for(let i = 1; i < arr.length; ++i){
arr[i].style.display = "flex";
arr[i].style.flexFlow = "row wrap";
arr[i].getElementsByClassName("mw-headline")[0].style.width = "74%";
if(arr[i].getElementsByClassName("mw-editsection").length > 0){
arr[i].getElementsByClassName("mw-editsection")[0].style.width = "20%";
}
let append_nav = '<span style="text-align:right; width:3%">';
if(i - 1 > 0){
append_nav += ' <a href="#' + arr[i - 1].childNodes[0].id + '">↑</a>';
}
if(i + 1 < arr.length){
append_nav += ' <a href="#' + arr[i + 1].childNodes[0].id + '">↓</a>';
}
arr[i].innerHTML += append_nav + "</span>";
}
});