Utilisateur:Binabik/Japon.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./* Japanisation, grâce à l'aide de [[User:EDUCA33E]] et [[USER:GôTô]] */
var tabAction = "p-cactions";
function addJapanButton()
{
// condition à améliorer
var toolbar = document.getElementById("toolbar");
if (!toolbar) return;
var l = document.getElementById(tabAction);
t = l.innerHTML;
ind = t.toLowerCase().indexOf("</ul>");
before = t.substring(0,ind);
after = t.substring(ind);
pitem = "<li><a href='javascript:hepburn();' accesskey=\">\">"+
"<div id='japan' style='display:inline;'>" +
"Hepburn" +
"</div></a></li>";
l.innerHTML = before + pitem + after ;
}
function hepburn() {
var txt = document.editform.wpTextbox1;
txt.focus();
if ( window.getSelection )
{
// mozilla
if( txt.selectionStart || txt.selectionStart == '0')
{
var text = txt.value.substring(txt.selectionStart, txt.selectionEnd);
var s2 = txt.value;
text = text.replace(new RegExp("aa", "g"), "ā").replace(new RegExp("Aa", "g"), "Ā");
// La norme Hepburn réserve la conversion suivante aux noms non-sino-japonais.
//text = text.replace(new RegExp("ii", "g"), "ī").replace(new RegExp("Ii", "g"), "Ī");
text = text.replace(new RegExp("ee", "g"), "ē").replace(new RegExp("Ee", "g"), "Ē");
text = text.replace(new RegExp("uu", "g"), "ū").replace(new RegExp("Uu", "g"), "Ū");
text = text.replace(new RegExp("oo", "g"), "ō").replace(new RegExp("Oo", "g"), "Ō");
text = text.replace(new RegExp("ou", "g"), "ō").replace(new RegExp("Ou", "g"), "Ō");
text = text.replace(new RegExp("â", "g"), "ā").replace(new RegExp("Â", "g"), "Ā");
// La norme Hepburn réserve la conversion suivante aux noms non-sino-japonais.
//text = text.replace(new RegExp("î", "g"), "ī").replace(new RegExp("Î", "g"), "Ī");
text = text.replace(new RegExp("ê", "g"), "ē").replace(new RegExp("Ê", "g"), "Ē");
text = text.replace(new RegExp("û", "g"), "ū").replace(new RegExp("Û", "g"), "Ū");
text = text.replace(new RegExp("ô", "g"), "ō").replace(new RegExp("Ô", "g"), "Ō");
text = text.replace(new RegExp("cch", "g"), "tch");
var savestart = txt.selectionStart;
txt.value = s2.substring(0, txt.selectionStart)
+ text
+ s2.substr(txt.selectionEnd);
txt.selectionStart = savestart + text.length;
txt.selectionEnd = savestart + text.length;
}
}
else if( document.getSelection )
{
// Safari/Konqueror
var text = document.getSelection( ).replace(new RegExp("aa", "g"), "ā");
//Manque la suite...
}
else
{
// internet explorer
var range = document.selection.createRange();
var text = range.text;
text = text.replace(new RegExp("aa", "g"), "ā").replace(new RegExp("Aa", "g"), "Ā");
// La norme Hepburn réserve la conversion suivante aux noms non-sino-japonais.
//text = text.replace(new RegExp("ii", "g"), "ī").replace(new RegExp("Ii", "g"), "Ī");
text = text.replace(new RegExp("ee", "g"), "ē").replace(new RegExp("Ee", "g"), "Ē");
text = text.replace(new RegExp("uu", "g"), "ū").replace(new RegExp("Uu", "g"), "Ū");
text = text.replace(new RegExp("oo", "g"), "ō").replace(new RegExp("Oo", "g"), "Ō");
text = text.replace(new RegExp("ou", "g"), "ō").replace(new RegExp("Ou", "g"), "Ō");
text = text.replace(new RegExp("â", "g"), "ā").replace(new RegExp("Â", "g"), "Ā");
// La norme Hepburn réserve la conversion suivante aux noms non-sino-japonais.
//text = text.replace(new RegExp("î", "g"), "ī").replace(new RegExp("Î", "g"), "Ī");
text = text.replace(new RegExp("ê", "g"), "ē").replace(new RegExp("Ê", "g"), "Ē");
text = text.replace(new RegExp("û", "g"), "ū").replace(new RegExp("Û", "g"), "Ū");
text = text.replace(new RegExp("ô", "g"), "ō").replace(new RegExp("Ô", "g"), "Ō");
text = text.replace(new RegExp("cch", "g"), "tch");
range.text = text;
}
}
function customSpecialChars()
{
var elmtP = document.getElementById("editpage-copywarn")
if (elmtP == undefined)
return // Pas en édition
//elmtP = elmtP.getElementsByTagName("table")[0]
var str = "Caractères spéciaux: "
str += "<a href=\"javascript:insertTags('Ā','', '')\" accesskey=\",\">Ā</a> "
str += "<a href=\"javascript:insertTags('ā','', '')\" accesskey=\"a\">ā</a> "
str += "<a href=\"javascript:insertTags('Ē','', '')\" accesskey=\";\">Ē</a> "
str += "<a href=\"javascript:insertTags('ē','', '')\" accesskey=\"f\">ē</a> "
str += "<a href=\"javascript:insertTags('Ī','', '')\" accesskey=\":\">Ī</a> "
str += "<a href=\"javascript:insertTags('ī','', '')\" accesskey=\"i\">ī</a> "
str += "<a href=\"javascript:insertTags('Ō','', '')\" accesskey=\"!\">Ō</a> "
str += "<a href=\"javascript:insertTags('ō','', '')\" accesskey=\"o\">ō</a> "
str += "<a href=\"javascript:insertTags('Ū','', '')\" accesskey=\"ù\">Ū</a> "
str += "<a href=\"javascript:insertTags('ū','', '')\" accesskey=\"v\">ū</a> "
elmtP.innerHTML = "<br/ ><center>" + str + "</center><br />" + elmtP.innerHTML
}
// Quick-replacer pour rectifier les mots sans diacritique triviaux sur les pages japonaises
var tabAction = "p-cactions";
function addAutoMacronButton()
{
// condition à améliorer
var toolbar = document.getElementById("toolbar");
if (!toolbar) return;
var l = document.getElementById(tabAction);
t = l.innerHTML;
ind = t.toLowerCase().indexOf("</ul>");
before = t.substring(0,ind);
after = t.substring(ind);
pitem = "<li><a href='javascript:macron();' accesskey=\"²\">"+
"<div id='macron' style='display:inline;'>" +
"Macron" +
"</div></a></li>";
l.innerHTML = before + pitem + after ;
}
function macron() {
var txt = document.editform.wpTextbox1;
txt.focus();
if ( window.getSelection )
{
// mozilla
if( txt.selectionStart || txt.selectionStart == '0')
{
var text = txt.value.substring(txt.selectionStart, txt.selectionEnd);
var s2 = txt.value;
text = text.replace(new RegExp("Tokyo", "g"), "Tōkyō");
text = text.replace(new RegExp("Kobe", "g"), "Kōbe");
text = text.replace(new RegExp("Keiō", "g"), "Keiō");
text = text.replace(new RegExp("Saikyo", "g"), "Saikyō");
text = text.replace(new RegExp("Chuo", "g"), "Chūō");
text = text.replace(new RegExp("Toei Oedo", "g"), "Toei Ōedo");
text = text.replace(new RegExp("Odakyu", "g"), "Odakyū");
text = text.replace(new RegExp("Hanzomon", "g"), "Hanzōmon");
text = text.replace(new RegExp("Tokyu", "g"), "Tōkyū");
text = text.replace(new RegExp("Koto", "g"), "Kōtō");
text = text.replace(new RegExp("Keiyo", "g"), "Keiyō");
text = text.replace(new RegExp("Shonan", "g"), "Shōnan");
var savestart = txt.selectionStart;
txt.value = s2.substring(0, txt.selectionStart)
+ text
+ s2.substr(txt.selectionEnd);
txt.selectionStart = savestart + text.length;
txt.selectionEnd = savestart + text.length;
}
}
}
$(addAutoMacronButton);
$(addJapanButton);
$(customSpecialChars);