User:Func/wpfunc/curps.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
// User:Func/wpfunc/curps.js // function Curps() { var charDiv = document.getElementById( 'editpage-specialchars' ); if ( ! charDiv ) return; // Items are: // - 1-item lists: containing literal HTML // - strings of characters: // * whitespace is ignored, each char-link is output followed by 1 space // * each character can be // - the character itself, "IJ" // - an html numeric entity, "IJ" // - a JavaScript Unicode literal, "\u0132" // * shorthand: [nb] and [br] will insert and <br> for formatting // * a sequence like 'A+Z' will link as javascript:insertTags('A','Z',''), // - as in '«+»' // // All character information below is based on the charts at [[User:Curps/Sandbox2]] // var charData = [ [ '<tt><a href="/wiki/Spanish language" target="somewindow">es</a>:</tt> ' ], 'Á á É é Í í Ó ó Ú ú [nb] Ü ü [nb] Ñ ñ [nb] ¡ ¿ [nb] ª º [br]', [ '<tt><a href="/wiki/Portuguese language" target="somewindow">pt</a>:</tt> ' ], 'Á á É é Í í Ó ó Ú ú [nb]  â Ê ê Ô ô [nb] Ü ü [nb] Ç ç [nb] à ã Õ õ [br]', [ '<tt><a href="/wiki/French language" target="somewindow">fr</a>:</tt> ' ], 'É é [nb] À à È è Ù ù [nb]  â Ê ê Î î Ô ô Û û [nb]', 'Ä ä Ë ë Ï ï Ö ö Ü ü [nb] Ç ç [nb] Œ œ [nb] «+» [br]', [ '<tt><a href="/wiki/Dutch language" target="somewindow">nl</a>:</tt> ' ], 'IJ ij [br]', [ '<tt><a href="/wiki/German language" target="somewindow">de</a>:</tt> ' ], 'Ä ä Ö ö Ü ü [nb] ß [br]', [ '<tt><a href="/wiki/Italian language" target="somewindow">it</a>:</tt> ' ], 'É é [nb] À à È è Ò ò Ù ù [br]', [ '<tt><a href="/wiki/Danish language" target="somewindow">da</a>:</tt> ' ], 'Æ æ Ø ø Å å [br]', [ '<tt><a href="/wiki/Norwegian language" target="somewindow">no</a>:</tt> ' ], 'Æ æ Ø ø Å å [br]', [ '<tt><a href="/wiki/Swedish language" target="somewindow">sv</a>:</tt> ' ], 'Å å Ä ä Ö ö Ü ü [br]', [ '<tt><a href="/wiki/Finnish language" target="somewindow">fi</a>:</tt> ' ], 'Å å Ä ä Ö ö Ü ü Š š Ž ž [br]', [ '<tt><a href="/wiki/Icelandic language" target="somewindow">is</a>:</tt> ' ], '\u00d0 \u00f0 \u00de \u00fe [br]', // Unicode literals: Ð ð Þ þ [ '<tt><a href="/wiki/Polish language" target="somewindow">pl</a>:</tt> ' ], 'Ą ą Ć ć Ę ę Ł ł Ń ń', 'Ó ó Ś ś Ź ź Ż ż [br]', [ '<tt><a href="/wiki/Czech language" target="somewindow">cs</a>:</tt> ' ], 'Á á Č č Ď ď É é Ě ě Í í Ň ň', 'Ó ó Ř ř Š š Ť ť Ú ú Ů ů', '\u00dd \u00fd Ž ž [br]', // Unicode literals: Ý ý [ '<tt><a href="/wiki/Slovak language" target="somewindow">sk</a>:</tt> ' ], 'Á á Ä ä Č č Ď ď É é Í í Ĺ ĺ Ľ', 'ľ Ň ň Ó ó Ô ô Ŕ ŕ Š š Ť ť', 'Ú ú \u00dd \u00fd Ž ž [br]', // Unicode literals: Ý ý [ '<tt><a href="/wiki/Hungarian language" target="somewindow">hu</a>:</tt> ' ], 'Á á É é Í í Ó ó Ú ú [nb] Ö ö Ü ü [nb] Ő ő Ű ű [br]', [ '<tt><a href="/wiki/Slovenian language" target="somewindow">sl</a>:</tt> ' ], 'Č č Š š Ž ž [br]', [ '<tt><a href="/wiki/Croatian language" target="somewindow">hr</a>:</tt> ' ], 'Č č Ć ć Đ đ Š š Ž ž [nb]', 'DŽ Dž dž LJ Lj lj NJ Nj nj [br]', [ '<tt><a href="/wiki/Albanian language" target="somewindow">sq</a>:</tt> ' ], 'Ç ç Ë ë [br]', [ '<tt><a href="/wiki/Turkish language" target="somewindow">tr</a>:</tt> ' ], 'Ç ç Ğ ğ İ ı Ö ö Ş ş Ü ü [br]', [ '<tt><a href="/wiki/Romanian language" target="somewindow">ro</a>:</tt> ' ], 'Ă ă  â Î î Ş ş Ţ ţ [br]', [ '<tt><a href="/wiki/Lithuanian language" target="somewindow">lt</a>:</tt> ' ], 'Ą ą Č č Ę ę Ė ė Į į', '\u0160 \u0161 Ų ų Ū ū \u017d \u017e [br]', // Unicode literals: Š š Ž ž [ '<tt><a href="/wiki/Latvian language" target="somewindow">lv</a>:</tt> ' ], 'Ā ā Č č Ē ē Ģ ģ Ī', 'ī Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ', '\u0160 \u0161 Ū ū \u017d \u017e [br]', // Unicode literals: Š š Ž ž [ '<tt><a href="/wiki/Estonian language" target="somewindow">et</a>:</tt> ' ], '\u0160 \u0161 \u017d \u017e Õ õ Ä ä Ö ö Ü ü [br]', // Unicode literals: Š š Ž ž [ '<tt><a href="/wiki/Maltese language" target="somewindow">ml</a>:</tt> ' ], 'Ċ ċ Ġ ġ Ħ ħ Ż ż [br]', [ '<tt><a href="/wiki/Hanyu pinyin" target="somewindow">zh</a>:</tt> ' ], 'Ā ā Ē ē Ī ī Ō ō Ū ū [nb]', 'Á á É é Í í Ó ó Ú ú [nb]', 'Ǎ ǎ Ě ě Ǐ ǐ Ǒ ǒ Ǔ ǔ [nb]', 'À à È è Ì ì Ò ò Ù ù [nb]', 'ǖ ǘ ǚ ǜ [br]', [ '<tt><a href="/wiki/Catalan language" target="somewindow">ca</a>:</tt> ' ], 'À à Ç ç È è É é Í í Ï ï Ŀ ŀ Ò ò Ó ó Ú ú Ü ü [br]', [ '<tt><a href="/wiki/Esperanto language" target="somewindow">eo</a>:</tt> ' ], 'Ĉ ĉ Ĝ ĝ Ĥ ĥ Ĵ ĵ Ŝ ŝ Ŭ ŭ [br]', [ '<tt><a href="/wiki/Welsh language" target="somewindow">cy</a>:</tt> ' ], 'Ŵ ŵ Ŷ ŷ', ]; var newDiv = document.createElement( 'div' ); newDiv.className = 'plainlinks'; newDiv.style.marginTop = '15px'; newDiv.style.borderWidth = '1px'; newDiv.style.borderStyle = 'solid'; newDiv.style.borderColor = '#aaaaaa'; newDiv.style.padding = '2px'; newDiv.style.fontSize = 'x-small'; newDiv.innerHTML = ''; // it's undefined otherwise, causes problems later charDiv.parentNode.insertBefore( newDiv, charDiv ); // before the existing insertion-links // charDiv.parentNode.insertBefore( newDiv, charDiv.nextSibling ); // after the existing insertion-links // charDiv.parentNode.replaceChild( newDiv, charDiv ); // replace the existing insertion-links var i, j, v, a, c, c2, link; for ( i = 0; i < charData.length; i++ ) { v = charData[ i ]; // array or string if ( v.constructor == Array ) newDiv.innerHTML += v[ 0 ]; // Is this going to work ??? !!! else if ( v.constructor == String ) // sanity check { a = v.split( / +/ ); // break at spaces for ( j = 0; j < a.length; j++ ) { if ( ! ( c = a[ j ] ) ) continue; // sanity check c2 = c.split( /\+/ ); // as in "«+»" for javascript:insertTags('«','»','') if ( c2.length > 1 ) { c = c2[ 0 ]; c2 = c2[ 1 ]; } else c2 = ''; if ( c == '[nb]' ) { newDiv.innerHTML += ' '; continue } else if ( c == '[br]' ) { newDiv.innerHTML += '<br>'; continue } if ( c .indexOf( '&#' ) == 0 ) c = String.fromCharCode( Number( c .substring( 2, c .length - 1 ) ) ); if ( c2.indexOf( '&#' ) == 0 ) c2 = String.fromCharCode( Number( c2.substring( 2, c2.length - 1 ) ) ); link = document.createElement( 'a' ); link.appendChild( document.createTextNode( c + c2 ) ); link.href = "javascript:insertTags('" + c + "','" + c2 + "','')"; newDiv.appendChild( link ); newDiv.appendChild( document.createTextNode( ' ' ) ); } } } } if ( window.addEventListener ) window.addEventListener( 'load', Curps, false ); else if ( window.attachEvent ) window.attachEvent( 'onload', Curps );