User:Strainu/dia.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:Strainu/dia. |
- Report page listing warnings and errors.
function all_commas(str)
{
str=str.replace(/ţ/g,"ț");
str=str.replace(/Ţ/g,"Ț");
str=str.replace(/ş/g,"ș");
str=str.replace(/Ş/g,"Ș");
return str;
}
save_new_diacritics = function()
{
var wgPageName = mw.config.get('wgPageName');
var upload_form=document.getElementById('mw-upload-form');
if (wgPageName=="Special:Upload" && upload_form) {
upload_form.onsubmit=function(){
var ta=document.getElementById('wpUploadDescription');
var title=document.getElementById('wpDestFile');
if (!ta || !title) {
return true;
}
var newvalue = ta.value;
var newtitle = title.value;
var turkish_regexp = /(<(span) lang=[^<>]*>(.|\r|\n)*?<\/\2>)|(<(gallery)(.*?)>(.|\r|\n)*?<\/\5>)/gi;
var turkish_phrases = newvalue.match(turkish_regexp);
newvalue=all_commas(newvalue);
var mixed_phrases = newvalue.match(turkish_regexp);
if(mixed_phrases != null && turkish_phrases != null) {
for(var i = 0; i < turkish_phrases.length; i++) {
newvalue = newvalue.replace(mixed_phrases[i], turkish_phrases[i]);
}
}
//restore the value to the editbox
ta.value = newvalue;
if(ta.value.search("{{titlu corect") > -1){//we found the template, do not replace the title
return true;
}
title.value = all_commas(newtitle);
return true;
}
}
}
addOnloadHook(save_new_diacritics);