„Benutzer:Lustiger seth/seth-style.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
chore: debugging; currently the reply function is disturbed |
feat: traverse DOM instead of raw innerHTML |
||
Zeile 6: | Zeile 6: | ||
return match.toLowerCase(); |
return match.toLowerCase(); |
||
} |
} |
||
function replacer(match, p1, p2, offset, string, groups){ |
|||
function replaceTextNodes(node, post_id=""){ |
|||
//console.log(p1); |
|||
node.childNodes.forEach(function(el){ |
|||
const split_html = p2.split(/(<[^>]+>)/); |
|||
if(post_id !== "" && el.nodeType === 3){ // text node |
|||
for(var i = split_html.length - 1; i >= 0; --i){ |
|||
el.nodeValue = el.nodeValue |
|||
if(split_html[i][0] != "<"){ |
|||
split_html[i] = split_html[i] |
|||
.replace(/\b[A-ZÄÖÜ][a-zäöüß]+\b/g, lc_replacer) |
.replace(/\b[A-ZÄÖÜ][a-zäöüß]+\b/g, lc_replacer) |
||
.replace(/L(ustiger[_ ]seth)/g, "l$1") |
.replace(/L(ustiger[_ ]seth)/g, "l$1") |
||
Zeile 18: | Zeile 17: | ||
.replace(/ü/g, "ue") |
.replace(/ü/g, "ue") |
||
.replace(/ß/g, "ss"); |
.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, post_id); |
|||
} |
} |
||
} |
}); |
||
result = " id=\"" + p1 + "\"></span>" + split_html.join('') |
|||
+ "<span data-mw-comment-end=\"" + p1 + "\""; |
|||
return result; |
|||
} |
|||
⚫ | |||
⚫ | |||
const old_html = content.innerHTML; |
|||
const new_html = content.innerHTML.replace( |
|||
/ id="(c-Lustiger_seth-[^"]+)"><\/span>((?:.|[\n\r\s])*?)<span data-mw-comment-end="\1"/g, |
|||
replacer); |
|||
if(content.innerHTML != old_html){ |
|||
console.log("nope"); |
|||
}else{ |
|||
content.innerHTML = new_html; |
|||
} |
} |
||
⚫ | |||
⚫ | |||
} |
} |
||
sethsche_schreibung(); |
Version vom 5. April 2023, 23:41 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();
}
function replaceTextNodes(node, post_id=""){
node.childNodes.forEach(function(el){
if(post_id !== "" && el.nodeType === 3){ // text node
el.nodeValue = el.nodeValue
.replace(/\b[A-ZÄÖÜ][a-zäöüß]+\b/g, lc_replacer)
.replace(/L(ustiger[_ ]seth)/g, "l$1")
.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, post_id);
}
});
}
replaceTextNodes(document.getElementById("mw-content-text")
.getElementsByClassName("mw-parser-output")[0]);
}
sethsche_schreibung();