Utilizator:Paloi Sciurala/diacritice.js
Notă: După salvare, trebuie să treceți peste cache-ul browser-ului pentru a vedea modificările.
- Mozilla, Google Chrome, Safari, Konqueror: țineți apăsat Shift în timp ce apăsați butonul Reload (sau apăsați Ctrl-Shift-R).
- Internet Explorer: apăsați Ctrl-F5.
- Opera: apăsați F5.
/*
Script made by [[:ro:Utilizator:Strainu]] and [[:ro:Utilizator:Gutza]]. Based on an idea by [[:ro:Utilizator:Alexxed]]
Documents:
Microsoft UA strings: http://msdn.microsoft.com/en-us/library/ms537503.aspx
*/
hookEvent('load', replaceDiacritics);
function goodToBad(node) {
var i;
if (goodToBad.formInputs == undefined) {
goodToBad.formInputs = document.getElementsByTagName('form');
}
// skip the form elements
for (i = 0; i < goodToBad.formInputs.length; i++) {
if(node == goodToBad.formInputs[i])
return;
}
if(node.nodeName == '#text') {
node.nodeValue = node.nodeValue.replace(/ș/g, 'ş');
node.nodeValue = node.nodeValue.replace(/ț/g, 'ţ');
node.nodeValue = node.nodeValue.replace(/Ș/g, 'Ş');
node.nodeValue = node.nodeValue.replace(/Ț/g, 'Ţ');
return;
}
for(i = 0; i < node.childNodes.length; i++)
goodToBad(node.childNodes[i]);
}
function badToGood(node) {
var i;
if (goodToBad.formInputs == undefined) {
goodToBad.formInputs = document.getElementsByTagName('form');
}
// skip the form elements
for (i = 0; i < goodToBad.formInputs.length; i++) {
if(node == goodToBad.formInputs[i])
return;
}
if(node.nodeName == '#text') {
node.nodeValue = node.nodeValue.replace(/ş/g, 'ș');
node.nodeValue = node.nodeValue.replace(/ţ/g, 'ț');
node.nodeValue = node.nodeValue.replace(/Ş/g, 'Ș');
node.nodeValue = node.nodeValue.replace(/Ţ/g, 'Ț')
return;
}
// skip Turkish stuff
if (node.getAttribute != undefined && node.getAttribute('lang')=='tr') {
return;
}
for(i = 0; i < node.childNodes.length; i++)
badToGood(node.childNodes[i]);
}
function replaceDiacritics() {
//var is_ie6m = -1;
//var is_vista = -1;
//ignore history pages and special pages due to performance concerns
if(wgAction == "history" || wgCanonicalNamespace == "Special")
return;
//excluding JS files for practical purposes
if(wgTitle.indexOf(".js") > -1)
return;
var titleOverride=document.getElementById("full_title");
if (titleOverride!=undefined) {
var DOMtitle=document.getElementById("firstHeading");
if (DOMtitle!=undefined) {
DOMtitle.innerHTML=titleOverride.innerHTML;
}
}
var content = document.getElementById("content");
if(content === null)
badToGood(document.body);
else
badToGood(document.body);
// badToGood(content);
}
/*function diacriticeFull()
{
document.body.innerHTML = document.body.innerHTML.replace(/ş/g, 'ș');
document.body.innerHTML = document.body.innerHTML.replace(/ţ/g, 'ț');
document.body.innerHTML = document.body.innerHTML.replace(/Ş/g, 'Ș');
document.body.innerHTML = document.body.innerHTML.replace(/Ţ/g, 'Ț');
return;
}
hookEvent('load',diacriticeFull);*/