MediaWiki:Gadget-Einleitung-bearbeiten.js
Aus Kitakien
(Unterschied zwischen Versionen)
(Etwas beschleunigt, etwas verlangsamt zu Gunsten der Kompatibilität mit anderen Skins wie modern.) |
(das müsste alles auch so gehen, wenn auch etwas langsamer) |
||
Zeile 21: | Zeile 21: | ||
// additional checkup to stop | // additional checkup to stop | ||
- | var test = document | + | var test = document.getElementsByTagName("h2").length + |
- | document | + | document.getElementsByTagName("h3").length + |
- | document | + | document.getElementsByTagName("h4").length; |
// note that there is always siteSub (h3) | // note that there is always siteSub (h3) | ||
var addEditTopLinkNumHeaders = window.addEditTopLinkNumHeaders || 2; | var addEditTopLinkNumHeaders = window.addEditTopLinkNumHeaders || 2; | ||
Zeile 30: | Zeile 30: | ||
// get first header element | // get first header element | ||
- | var fst_h1 = document | + | var fst_h1 = document.getElementsByTagName("h1")[0]; |
// Creating elements | // Creating elements |
Version vom 05:56, 24. Apr. 2008
// ursprünglich: [[:en:User:Pile0nades]] // Erweitert von: Maciej Jaros [[:pl:User:Nux]] // siehe http://pl.wikipedia.org/wiki/MediaWiki:Monobook.js // Korrigiert von: [[Benutzer:TMg]] if (wgIsArticle) addOnloadHook(function() { // somehow it gets run twice on some pages - stop that if (window.addEditTopLinkDone) return; window.addEditTopLinkDone = true; // if there are no edit-section links then stop var spans = document.getElementsByTagName("span"); var i; for (i = 0; i < spans.length; i++) { if (spans[i].className == 'editsection') break; } if (i >= spans.length) return; // additional checkup to stop var test = document.getElementsByTagName("h2").length + document.getElementsByTagName("h3").length + document.getElementsByTagName("h4").length; // note that there is always siteSub (h3) var addEditTopLinkNumHeaders = window.addEditTopLinkNumHeaders || 2; if (test <= addEditTopLinkNumHeaders) return; // get first header element var fst_h1 = document.getElementsByTagName("h1")[0]; // Creating elements // create span var span = document.createElement("SPAN"); span.className = 'editsection'; // create link var link = document.createElement("A"); link.href = document.getElementById("ca-edit").getElementsByTagName("a")[0].href + '§ion=0'; link.title = "Abschnitt bearbeiten: Einleitung"; link.appendChild(document.createTextNode('Bearbeiten')); // append link and stuff to span span.appendChild(document.createTextNode('[')); span.appendChild(link); span.appendChild(document.createTextNode(']')); // Insert span container into the DOM before the h1 fst_h1.insertBefore(document.createTextNode(" "), fst_h1.firstChild); fst_h1.insertBefore(span, fst_h1.firstChild); });