„Benutzer:Lustiger seth/seth-style.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
fix: 1. used js unicode regexp; 2. used semi-global variable instead of recursive param |
fix: don't try to change pages without discussions |
||
Zeile 9: | Zeile 9: | ||
let post_id = ""; |
let post_id = ""; |
||
function replaceTextNodes(node){ |
function replaceTextNodes(node){ |
||
if(typeof node === "undefined"){ |
|||
return; |
|||
} |
|||
node.childNodes.forEach(function(el){ |
node.childNodes.forEach(function(el){ |
||
if(post_id !== "" && el.nodeType === 3){ // text node |
if(post_id !== "" && el.nodeType === 3){ // text node |
Aktuelle Version vom 7. April 2023, 10:52 Uhr
// apply lower case style and converted umlauts and sz-ligature on comments of lustiger_seth
// (not tested very well.)
function sethsche_schreibung(){
function lc_replacer(match, offset, string){
return match.toLowerCase();
}
let post_id = "";
function replaceTextNodes(node){
if(typeof node === "undefined"){
return;
}
node.childNodes.forEach(function(el){
if(post_id !== "" && el.nodeType === 3){ // text node
el.nodeValue = el.nodeValue
.replace(/(?<!\p{L})\p{Lu}\p{Ll}+(?!\p{L})/gu, lc_replacer)
.replace(/ä/g, "ae")
.replace(/ö/g, "oe")
.replace(/ü/g, "ue")
.replace(/ß/g, "ss");
}else{ // recurse
if(el.nodeType === 1){
if(post_id === "" && el.id.startsWith("c-Lustiger_seth")){
post_id = el.id;
}else if(typeof(el.dataset.mwThreadId) !== "!undefined" && el.dataset.mwThreadId === post_id){
post_id = "";
}
}
replaceTextNodes(el);
}
});
}
replaceTextNodes(document.getElementById("mw-content-text")
.getElementsByClassName("mw-parser-output")[0]);
}
sethsche_schreibung();