User:Nyenyec/nyenyeclib.js
A Wikipédiából, a szabad lexikonból.
Megjegyzés: A beállítások elmentése után frissítened kell a böngésződ gyorsítótárát, hogy a változások érvénybe lépjenek. Mozilla / Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Reload / Frissítés gombra az eszköztáron, vagy használd a Ctrl–F5 billentyűkombinációt (Apple Mac-en Cmd–Shift–R); Internet Explorer: tartsd nyomva a Ctrl-t, és kattints a Reload / Frissítés gombra, vagy nyomj Ctrl–F5-öt; Konqueror: egyszerűen csak kattints a Reload / Frissítés gombra (vagy Ctrl–R vagy F5); Opera felhasználóknak teljesen ki kell üríteniük a gyorsítótárat a Tools→Preferences menüben.
// Generates the box element containing the spec chars. function createSpecCharBox() { var boxDiv = document.createElement("div"); boxDiv.setAttribute('id', 'editMenu'); // boxDiv.setAttribute('id', 'customBar'); // boxDiv.setAttribute('style', 'margin-top:5px;border:1px solid #aaaaaa;padding:3px'); var html = '<a href="http://hu.wikipedia.org/wiki/Wikipédia:Különleges_karakterek"' + ' title="Wikipédia:Különleges karakterek">Különleges karakterek:</a>:' + "<a href=\"javascript:insertTags('„','','')\">„</a> ·" + "<a href=\"javascript:insertTags('”','','')\">“</a> ·" + "<a href=\"javascript:insertTags('–','','')\">– <small>(gondolatjel)</small></a> ·" + "<a href=\"javascript:insertTags('„','”','')\">„”</a> ·" + "<a href=\"javascript:insertTags('»','«','')\">»«</a> ·" + "<a href=\"javascript:insertTags('²','','')\">²</a> " + "<a href=\"javascript:insertTags('³','','')\">³</a> " + "<a href=\"javascript:insertTags('½','','')\">½</a> ·" + "<a href=\"javascript:insertTags('€','','')\">€</a> ·" + "<a href=\"javascript:insertTags('í','','')\">í</a> ·" + "<a href=\"javascript:insertTags('[[',']]','')\">[[]]</a> " + "<a href=\"javascript:insertTags('|','','')\">|</a> " + "<a href=\"javascript:insertTags('{{','}}','')\">{{}}</a> ·" + "<a href=\"javascript:insertTags('{{Külső/Angol}}','','')\"><small>angol link</small></a> ·" + "<a href=\"javascript:insertTags('{{' + 'torles}}','','')\"><small>törlésre javasolt</small></a> ·" + "<a href=\"javascript:insertTags('--\176\176\176\176','','')\"><small>aláírás</small></a> ·" + "<a href=\"javascript:translateInfoboxCountryEnHu()\"><small>ország</small></a> ·" + "<a href=\"javascript:fixLatin1Chars()\"><small>kalapos</small></a> ·" + "<a href=\"javascript:fixHungarianQuotes()\"><small>idézőjel</small></a> ·" + "<a href=\"javascript:fixExternalLinksSectionTitle()\"><small>külső</small></a> ·" + "<a href=\"javascript:translateDatesEnHu()\"><small>dátum</small></a> ·" + "<a href=\"javascript:insertCustomForm(customReplaceForm())\"><small>egyedi</small></a>" "</div>"; return boxDiv; } function replaceRegexp(replaceWhat, replaceWith, modifiers) { if (modifiers == null) { modifiers = ""; } var txtarea = document.editform.wpTextbox1; // IE if(document.selection && !is_gecko) { var theSelection = document.selection.createRange().text; txtarea.focus(); theSelection = theSelection.replace(replaceWhat, replaceWith); document.selection.createRange().text = theSelection; // Mozilla } else if(txtarea.selectionStart || txtarea.selectionStart == '0') { // This is probably more complicated than it needs to be var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; var scrollTop=txtarea.scrollTop; var pattern = new RegExp(replaceWhat, modifiers); var myText = (txtarea.value).replace(pattern, replaceWith); txtarea.value = myText; txtarea.focus(); var cPos=startPos; txtarea.selectionStart=cPos; txtarea.selectionEnd=cPos; txtarea.scrollTop=scrollTop; // All others } else { alert("No support for this browser yet"); return; } // reposition cursor if possible if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate(); } // Replaces Latin 1 chars with properly encoded Hungarian Latin 2 equivalents function fixLatin1Chars() { replaceRegexp("Õ", "\u0150", "g"); replaceRegexp("Û", "Ű", "g"); replaceRegexp("õ", "ő", "g"); replaceRegexp("ő", "ő", "g"); replaceRegexp("ű", "ű", "g"); replaceRegexp("û", "ű", "g"); } // Replaces English style "" quotes with Hungarian „” function fixHungarianQuotes() { replaceRegexp("\"([^\"]*)\"", "„$1”", "mg"); } // Replaces English style "" quotes with Hungarian „” function fixExternalLinksSectionTitle() { replaceRegexp("=\\s*Külső linkek\\s*=", "=Külső hivatkozások=", "mg"); } // Replace all occurences of a user-entered regexp with a user entered replacement function customReplace() { var what = prompt('Cseréld ezt:'); if (what != null) { var withWhat = prompt('Cseréld ezt: "' + what + '", erre:'); if (withWhat != null) { replaceRegexp(what, withWhat, "gm"); } } } // Translate dates from English format to Hungarian // Currently it only handles linkified dates function translateDatesEnHu() { var months = [ ["January", "január"], ["February", "február"], ["March", "március"], ["April", "április"], ["May", "május"], ["June", "június"], ["July", "július"], ["August", "augusztus"], ["September", "szeptember"], ["October", "október"], ["November", "november"], ["December", "december"] ]; for (var i = 0; i < months.length; i++) { var enMonth = months[i][0]; var huMonth = months[i][1]; // alert("Replacing " + enMonths + " with " + huMonth); // Replace "[[November 15]], [[2005]]" with "[[2005]]. [[november 15]]." // $1 = "15", $2 = "2005" replaceRegexp("\\[\\[" + enMonth + " (\\d+)\\]\\],?\\s*\\[\\[(\\d{4})\\]\\]", "[[$2]]. [[" + huMonth + " $1]].", "gm"); } } // Translates an English country infobox to Hungarian function translateInfoboxCountryEnHu() { var dict = [ ["Infobox Country", "Országtáblázat"], ["Infobox_Country", "Országtáblázat"], ["native_name", "teljesnév"], ["image_flag", "zászlókép"], ["image_coat", "címerkép"], ["image_map", "elhelyezkedéskép"], ["national_motto", "mottó"], ["national_anthem", "himnusz"], ["official_languages", "hivatalos_nyelvek"], ["capital", "főváros"], ["capitals_coordinates.*\$", ""], ["government_type", "államforma"], ["leader_titles", "államfő"], ["leader_names", "jelenlegiállamfő"], ["largest_city", "legnagyobbváros"], ["area", "terület"], ["area_rank", "területrangsorban"], ["area_magnitude.*\$", ""], ["percent_water", "víz"], ["population_estimate", "népesség"], ["population_estimate_year", "népesség_dátum"], ["population_estimate_rank", "népességrangsorban"], ["population_census.*\$", ""], ["population_census_year.*\$", ""], ["population_density", "népsűrűség"], ["population_density_rank", "népsűrűségrangsorban"], ["GDP_PPP_year", "GDP_dátum"], ["GDP_PPP", "GDP"], ["GDP_PPP_rank", "GDPrangsorban"], ["GDP_PPP_per_capita", "egyfőrejutóGDP"], ["GDP_PPP_per_capita_rank", "egyfőrejutóGDPrangsorban"], ["sovereignty_type.*\$", ""], ["established_events", "függetlenségesemény"], ["established_dates", "függetlenségdátuma"], ["currency", "pénznem"], ["currency_code", "pénznemrövidítés"], ["time_zone", "időzóna"], ["utc_offset.*\$", ""], ["time_zone_DST", "NYISZ"], ["utc_offset_DST", ""], ["cctld", "tld"], ["calling_code", "hívókód"], ["footnotes", "lábjegyzet"], ["Federal republic", "szövetségi köztársaság"], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["Declared", "kikiáltása"], ["Recognised", "elismerése"], ["English language", "angol nyelv"], ["French language", "francia nyelv"], ["Spanish language", "spanyol nyelv"], ["German language", "német nyelv"], ["million", "millió"] ]; for (var i = 0; i < dict.length; i++) { var pair = dict[i]; replaceRegexp(pair[0], pair[1]); } // In Hungarian, we use for separating digits instead of , replaceRegexp("(\\d+?),(\\d+?)", "$1 $2", "g"); // Decimal separator "." -> "," replaceRegexp("(\\d+?)\\.(\\d+?)", "$1,$2", "g"); // In rankings, get rid of "st", "th", etc. replaceRegexp("(\\d+?)st", "$1", "g"); replaceRegexp("(\\d+?)nd", "$1", "g"); replaceRegexp("(\\d+?)rd", "$1", "g"); replaceRegexp("(\\d+?)th", "$1", "g"); // Get rid of $ prefix in GDP replaceRegexp("\\$(\\d+?)", "$1", "g") // Get rid of whitespace before "=" replaceRegexp("(\\s+)=", " =", "g"); translateDatesEnHu(); } // Replace all occurences of a user-entered regexp with a user entered replacement function customReplaceForm() { var form = 'Cseréld ezt a reguláris kifejezést: <input id="customReplaceThis" type="text" size="40"> ' + 'erre: <input id="customReplaceWith" type="text" size="40"> ' + '<input type="submit" value="Csere" onClick="javascript:performCustomReplace()">'; return form; } function performCustomReplace() { var replaceThis = document.getElementById('customReplaceThis'); var replaceWith = document.getElementById('customReplaceWith'); replaceRegexp(replaceThis.value, replaceWith.value, "gm"); deleteCustomForm(); } function insertCustomForm(customForm) { var customBar = document.getElementById('editMenu'); if (customBar == null) return; var replaceForm = document.createElement('div'); replaceForm.setAttribute('id', 'customForm'); replaceForm.setAttribute('style', 'margin-top:5px;border:1px solid #aaaaaa;padding:3px;text-align:center'); replaceForm.innerHTML = '<img src="http://upload.wikimedia.org/wikipedia/hu/b/bd/Close.png" align="right" ' + 'style="margin:2px" onClick="javascript:deleteCustomForm()">' + customForm; var oldForm = document.getElementById('customForm'); if (oldForm != null) { customBar.parentNode.replaceChild(replaceForm, oldForm); } else { customBar.parentNode.insertBefore(replaceForm, customBar); } } function deleteCustomForm() { var replaceForm = document.getElementById('customForm'); if (replaceForm != null) replaceForm.parentNode.removeChild(replaceForm); } // Initializes edit box function myOnloadHook() { // Textarea positioning doesn't work in Opera if (is_opera) return; // Find the element that comes right after the special character box var copywarn = document.getElementById('editpage-copywarn'); if (copywarn == null) { // Not in edit mode return; } var specCharBox = createSpecCharBox(); var par = copywarn.parentNode; par.insertBefore(specCharBox, copywarn); initjsDOMenu(); } if (window.addEventListener) window.addEventListener("load", myOnloadHook, false); else if (window.attachEvent) window.attachEvent("onload", myOnloadHook);