MediaWiki:Wikificator.js
Dėmesio: Išsaugoję turite išvalyti naršyklės spartinančią saugyklą (cache): Mozilla/Safari/Konqueror: spausdami Shift pasirinkite reload (arba Ctrl-Shift-R), IE: Ctrl-F5, Opera: F5.
var wmVersion = '2011-04-26' var wmCantWork = 'Vikifikatorius negali dirbti Jūsų naršiklėje\n\nWikificator can not work in your browser' var wmFullText = 'Vikifikatorius apdoroja VISĄ tekstą šiame puslapyje. Ar tęsti?' var wmTalkPage = 'Viso aptarimų puslapio Vikifikatorius neapdoroja.\n\n Išsirinkite savo komentarą. Apdorota bus tik išrinktoji dalis.' function Wikify(){ var txt='', hidden = [], wpTextbox1 = document.editform.wpTextbox1 var winScroll = document.documentElement.scrollTop try {txt='ая'.replace(/а/g,'б').replace(/б(?=я)/,'в')} catch(e){}//check regexp support if (txt != 'вя' || (navigator.appName=='Netscape' && navigator.appVersion.substr (0, 1) < 5)) { alert(wmCantWork); return } wpTextbox1.focus() if (typeof wpTextbox1.selectionStart != 'undefined' && (navigator.productSub > 20031000 || is_safari || is_opera)) { //Mozilla/Opera/Safari3 var textScroll = wpTextbox1.scrollTop var startPos = wpTextbox1.selectionStart var endPos = wpTextbox1.selectionEnd txt = wpTextbox1.value.substring(startPos, endPos) if (txt == '') processAllText() else{ processText() wpTextbox1.value = wpTextbox1.value.substring(0, startPos) + txt + wpTextbox1.value.substring(endPos) } wpTextbox1.selectionStart = startPos wpTextbox1.selectionEnd = startPos + txt.length wpTextbox1.scrollTop = textScroll }else if (document.selection && document.selection.createRange) { //IE var range = document.selection.createRange() txt = range.text if (txt == '') processAllText() else{ processText() range.text = txt if (range.moveStart) range.moveStart('character', - txt.length) range.select() } }else // other browsers if (confirm(wmFullText)) processAllText() document.documentElement.scrollTop = winScroll // scroll back, for IE/Opera //functions function processAllText(){ txt = wpTextbox1.value if (txt=='version') alert('Vikifikatorius '+wmVersion) processText() r(/^[\n\r]+/, '') wpTextbox1.value = txt txt = '' } function processText(){ var u = '\u00A0' //unbreakable space if (wgNamespaceNumber % 2 || wgNamespaceNumber==4) { //is talk page u = ' ' var sigs = txt.match(/\d\d:\d\d, \d\d? \S{3,8} 20\d\d \(EET\)/g) if (sigs && sigs.length > 1) { alert(wmTalkPage); return } } var txt_old = txt if (window.auto_comment && window.insertSummary && !document.editform.wpSection.value) { var ss = document.editform.wpSection.value.match(/\[\[Enciklopedija\:Vikifikatorius\|vikifikuota\]\]/g) if (!ss || ss.length < 2) insertSummary('[[Enciklopedija:Vikifikatorius|vikifikuota]]') } hideTag('nowiki') hideTag('pre') hideTag('source') hideTag('code') hideTag('tt') hideTag('math') // r(/( |\n|\r)+\{\{(·|•|\*)\}\}/g, '{{$2}}'); //before {{·/•/*}}, usually in templates for (var i=1; i<=4; i++) hide(/\{\{[^\{\}]*?\}\}/g)//templates hide(/^ .*/mg) hide(/(https?|ftp|news|nntp|telnet|irc|gopher):\/\/[^\s\[\]<>"]+ ?/gi) hide(/^#(redirect|nukreipimas)/i) hideTag('gallery') r(/ +(\n|\r)/g,'$1')// naukinami tarpai eilutės gale txt = '\n'+txt+'\n' //LINKS r(/(\[\[:?)(category|kategorija):( *)/ig, '$1Kategorija:') r(/(\[\[:?)(image|vaizdas|file):( *)/ig, '$1Vaizdas:') r(/(\(|\s)(\[\[[12]?\d{3}\]\]|[12]?\d{3})[\u00A0 ]?(-{1,3}|–|—) ?(\[\[[12]?\d{3}\]\]|[12]?\d{3})(\W)(?![^\[\]]*\]\])/g, '$1$2–$4$5') r(/(\[\[[12]?\d{3}\]\]) ?(m\.)/g, '$1'+u+'$2') r(/(\(|\s)(\[\[[IVX]{1,5}\]\]|[IVX]{1,5})[\u00A0 ]?(-{1,3}|–|—) ?(\[\[[IVX]{1,5}\]\]|[IVX]{1,5})(\W)/g, '$1$2–$4$5') hide(/\[\[[^\]\|]+/g)//links //TAGS r(/<<(\S.+\S)>>/g, '„$1“') //<< >> r(/(sup>|sub>|\s)-(\d)/g, '$1-$2') //minus r(/²/gi, '²') r(/³/gi, '³') r(/<(b|strong)>(.*?)<\/(b|strong)>/gi,"'''$2'''") r(/<(i|em)>(.*?)<\/(i|em)>/gi,"''$2''") r(/^<hr ?\/?>/gim, '----') r(/<\/?(hr|br)( [^\/>]+?)? ?\/?>/gi, '<$1$2 />') // r(/(\n== *[a-zа-я\s\.:]+ *==\n+)<references *\/>/ig,'$1{\{примечания}}') hide(/<[a-z][^>]*?>/gi) hide(/^({\||\|-).*/mg)//table/row def hide(/(^\||^!|!!|\|\|) *[a-z]+=[^|]+\|(?!\|)/mgi)//cell style hide(/\| +/g)//formatted cell r(/[ \t]+/g,' ')//double spaces // Headings r(/^(=+)[ \t\f\v]*(.*?)[ \t\f\v]*=+$/gm, '$1 $2 $1') //add spaces inside r(/([^\r\n])(\r?\n==.*==\r?\n)/g, '$1\n$2') //add empty line before r(/^== (.+)[.:] ==$/gm, '== $1 ==') // Brūkšnys r(/( |\s)-{1,3} /g, '$1– ') // hyphen -> — r(/(\d)--(\d)/g, '$1–$2') // -> — // Entities etc. → Unicode chars r(/&#x([0-9a-f]{1,4});/gi, function(n,a){return String.fromCharCode(eval('0x'+a.substr(-4)))}) //́ r(/©/gi,'©') r(/®/gi,'®') r(/§/gi,'§') r(/€/gi,'€') r(/¥/gi,'¥') r(/£/gi,'£') r(/°/g,'°') r(/\(tm\)|™/gi,'™') r(/\.\.\.|…/g,'…') r(/\+-(?!\+|-)|±/g,'±') r(/~=/g,'≈') r(/\^2(\D)/g,'²$1') r(/\^3(\D)/g,'³$1') r(/&((la|ra|bd|ld)quo|quot);/g,'"') r(/([\wа-яА-ЯёЁ])'([\wа-яА-ЯёЁ])/g,'$1’$2') //' r(/№№/g,'№') // Insert/delete spaces r(/(\d)(?:[\u00A0 ]|\ \;)?((?:(?:m|c|d|k|M)?m|[km]g|in|W)(?:²|³)?\.?)(?=[,;. ]| "?[a-ząčęėįšųūž])/g, '$1'+u+'$2') hide(/\ \;/g) r(/^([#*:]+)[ \t\f\v]*(?!\{\|)([^ \t\f\v*#:;])/gm, '$1 $2') //space after #*: unless before table r(/(\S) (-{1,3}|—|–) (\S)/g, '$1'+u+'– $3') r(/([\"\)\]a-ząčęėįšųūž“]|\sm|\sd) ?(\.|\!|\?|…) ?([„\(\[\"A-ZĄČĘĖĮŠŲŪŽ])/g, '$1$2 $3') r(/([\)\"a-ząčęėįšųūž\]“]) *([,;:]) ?([„\(\[\"a-ząčęėįšųūž])/g, '$1$2 $3') r(/\( +/g, '('); r(/ +\)/g, ')') //inside () //Kabutės //"" → «» for (var i=1; i<=3; i++) r(/"([^\s"][^"]*[^\s"])"/ig, '„$1“') //" //Temperature r(/([\s\d=≈≠≤≥<>—("'|])([+±−-]?\d+?(?:[.,]\d+?)?)(([ °^*]| [°^*])C)(?=[\s"').,;!?|])/gm, '$1$2'+u+'°C') //' r(/([\s\d=≈≠≤≥<>—("'|])([+±−-]?\d+?(?:[.,]\d+?)?)(([ °^*]| [°^*])F)(?=[\s"').,;|!?])/gm, '$1$2'+u+'°F') //' txt=txt.substr(1, txt.length-2) if ('0'.replace('0','$$') == '$') ////$ in replacing string is special, except in IE for (var i=0; i<hidden.length; i++) hidden[i] = hidden[i].replace(/\$/g, '$$$$') while (hidden.length>0) r('\x01'+hidden.length+'\x02', hidden.pop()) if (txt_old != txt) document.editform.wpSummary.value += ' [[Enciklopedija:Vikifikatorius|vikifikuota]]' } function r(r1, r2){ txt = txt.replace(r1, r2) } function hide(re){ r(re, function(s){return '\x01'+hidden.push(s)+'\x02'})} function hideTag(tag){ hide(RegExp('<' + tag + '( [^>]+)?>[\\s\\S]+?<\\/' + tag + '>','gi')) } }