„Benutzer:Lustiger seth/section jumpers.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
init; source: a self-written greasemonkey script |
(kein Unterschied)
|
Version vom 13. Februar 2022, 12:22 Uhr
/*
task: add up/down arrows at the end of each major section title (h2)
in order to jump to previous or next section respectively
tested in firefox only
*/
$(function (){
const h2s = document.getElementById("mw-content-text").getElementsByTagName("h2");
const arr = Array.from(h2s);
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%";
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>";
}
});