Участник:EvilCat/monobook.js — различия между версиями
м (дебаг) |
м (локальные копии функций.) |
||
Строка 13: | Строка 13: | ||
function god () | function god () | ||
{ | { | ||
− | |||
var txt='', hidden = [], wpTextbox1 = document.editform.wpTextbox1 | var txt='', hidden = [], wpTextbox1 = document.editform.wpTextbox1 | ||
var winScroll = document.documentElement.scrollTop | var winScroll = document.documentElement.scrollTop | ||
− | + | ||
try {txt='ая'.replace(/а/g,'б').replace(/б(?=я)/,'в')} catch(e){}//check regexp support | try {txt='ая'.replace(/а/g,'б').replace(/б(?=я)/,'в')} catch(e){}//check regexp support | ||
if (txt != 'вя' || | if (txt != 'вя' || | ||
(navigator.appName=='Netscape' && navigator.appVersion.substr (0, 1) < 5)) | (navigator.appName=='Netscape' && navigator.appVersion.substr (0, 1) < 5)) | ||
{ alert(wmCantWork); return } | { alert(wmCantWork); return } | ||
− | + | ||
wpTextbox1.focus() | wpTextbox1.focus() | ||
− | + | ||
if (typeof wpTextbox1.selectionStart != 'undefined' | if (typeof wpTextbox1.selectionStart != 'undefined' | ||
&& (navigator.productSub > 20031000 || is_safari || is_opera)) { //Mozilla/Opera/Safari3 | && (navigator.productSub > 20031000 || is_safari || is_opera)) { //Mozilla/Opera/Safari3 | ||
Строка 30: | Строка 29: | ||
var endPos = wpTextbox1.selectionEnd | var endPos = wpTextbox1.selectionEnd | ||
txt = wpTextbox1.value.substring(startPos, endPos) | txt = wpTextbox1.value.substring(startPos, endPos) | ||
− | + | if (txt == '') loc_processAllText() | |
− | if (txt == '') | ||
else{ | else{ | ||
− | + | loc_processText() | |
wpTextbox1.value = wpTextbox1.value.substring(0, startPos) + txt + wpTextbox1.value.substring(endPos) | wpTextbox1.value = wpTextbox1.value.substring(0, startPos) + txt + wpTextbox1.value.substring(endPos) | ||
} | } | ||
− | |||
wpTextbox1.selectionStart = startPos | wpTextbox1.selectionStart = startPos | ||
wpTextbox1.selectionEnd = startPos + txt.length | wpTextbox1.selectionEnd = startPos + txt.length | ||
wpTextbox1.scrollTop = textScroll | wpTextbox1.scrollTop = textScroll | ||
− | + | ||
}else if (document.selection && document.selection.createRange) { //IE | }else if (document.selection && document.selection.createRange) { //IE | ||
var range = document.selection.createRange() | var range = document.selection.createRange() | ||
txt = range.text | txt = range.text | ||
− | + | if (txt == '') loc_processAllText() | |
− | if (txt == '') | ||
else{ | else{ | ||
− | + | loc_processText() | |
range.text = txt | range.text = txt | ||
if (range.moveStart) range.moveStart('character', - txt.length) | if (range.moveStart) range.moveStart('character', - txt.length) | ||
range.select() | range.select() | ||
} | } | ||
− | + | ||
}else // other browsers | }else // other browsers | ||
− | if (confirm(wmFullText)) | + | if (confirm(wmFullText)) loc_processAllText() |
− | + | ||
document.documentElement.scrollTop = winScroll // scroll back, for IE/Opera | document.documentElement.scrollTop = winScroll // scroll back, for IE/Opera | ||
Строка 61: | Строка 57: | ||
//functions | //functions | ||
− | + | function loc_processAllText(){ | |
− | + | txt = wpTextbox1.value | |
− | + | if (txt=='version') alert('Викификатор '+wmVersion) | |
− | + | loc_processText() | |
− | + | loc_r(/^[\n\r]+/, '') | |
− | + | wpTextbox1.value = txt | |
− | + | txt = '' | |
− | + | if (window.auto_comment && window.insertSummary && !document.editform.wpSection.value) | |
− | + | insertSummary('викификатор') | |
− | + | } | |
− | + | ||
− | + | function loc_processText(){ | |
− | + | ||
+ | var u = ' ' //messed by RK | ||
+ | if (wgNamespaceNumber % 2 || wgNamespaceNumber==4) { //is talk page | ||
+ | var sigs = txt.match(/\d\d:\d\d, \d\d? \S{3,8} 20\d\d \(UTC\)/g) | ||
+ | if (sigs && sigs.length > 1) { | ||
+ | alert(wmTalkPage); return | ||
+ | } | ||
+ | } | ||
+ | |||
+ | loc_hideTag('nowiki') | ||
+ | loc_hideTag('pre') | ||
+ | loc_hideTag('source') | ||
+ | loc_hideTag('code') | ||
+ | loc_hideTag('tt') | ||
+ | loc_hideTag('math') | ||
+ | |||
+ | loc_r(/( |\n|\r)+\{\{(·|•|\*)\}\}/g, '{{$2}}'); //before {{·/•/*}}, usually in templates | ||
+ | loc_hide(/{\{[\s\S]+?}}/g)//templates | ||
+ | loc_hide(/^ .*/mg) | ||
+ | loc_hide(/(https?|ftp|news|nntp|telnet|irc|gopher):\/\/[^\s\[\]<>"]+ ?/gi) | ||
+ | loc_hide(/^#(redirect|перенапр(авление)?)/i) | ||
+ | loc_hideTag('gallery') | ||
+ | |||
− | + | loc_r(/ +(\n|\r)/g,'$1')//spaces at EOL | |
− | |||
txt = '\n'+txt+'\n' | txt = '\n'+txt+'\n' | ||
− | + | loc_r(/\{\{Божество([\s\r\n]+)\|/, '{{Божество D&D/d20$1\|') | |
− | + | ||
+ | function loc_r(r1, r2){ txt = txt.replace(r1, r2) } | ||
+ | function loc_hide(re){ loc_r(re, function(s){return '\x01'+hidden.push(s)+'\x02'})} | ||
+ | function loc_hideTag(tag){ loc_hide(RegExp('<' + tag + '( [^>]+)?>[\\s\\S]+?<\\/' + tag + '>','gi')) } | ||
+ | |||
} | } |
Версия 16:56, 8 марта 2012
function addGodButton() { var toolbar = document.getElementById('toolbar') if (!toolbar) return var i = document.createElement('span') i.innerHTML='[Б]' i.onclick = god i.style.cursor = 'pointer' toolbar.appendChild(i) } addOnloadHook(addGodButton) function god () { 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 == '') loc_processAllText() else{ loc_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 == '') loc_processAllText() else{ loc_processText() range.text = txt if (range.moveStart) range.moveStart('character', - txt.length) range.select() } }else // other browsers if (confirm(wmFullText)) loc_processAllText() document.documentElement.scrollTop = winScroll // scroll back, for IE/Opera //functions function loc_processAllText(){ txt = wpTextbox1.value if (txt=='version') alert('Викификатор '+wmVersion) loc_processText() loc_r(/^[\n\r]+/, '') wpTextbox1.value = txt txt = '' if (window.auto_comment && window.insertSummary && !document.editform.wpSection.value) insertSummary('викификатор') } function loc_processText(){ var u = ' ' //messed by RK if (wgNamespaceNumber % 2 || wgNamespaceNumber==4) { //is talk page var sigs = txt.match(/\d\d:\d\d, \d\d? \S{3,8} 20\d\d \(UTC\)/g) if (sigs && sigs.length > 1) { alert(wmTalkPage); return } } loc_hideTag('nowiki') loc_hideTag('pre') loc_hideTag('source') loc_hideTag('code') loc_hideTag('tt') loc_hideTag('math') loc_r(/( |\n|\r)+\{\{(·|•|\*)\}\}/g, '{{$2}}'); //before {{·/•/*}}, usually in templates loc_hide(/{\{[\s\S]+?}}/g)//templates loc_hide(/^ .*/mg) loc_hide(/(https?|ftp|news|nntp|telnet|irc|gopher):\/\/[^\s\[\]<>"]+ ?/gi) loc_hide(/^#(redirect|перенапр(авление)?)/i) loc_hideTag('gallery') loc_r(/ +(\n|\r)/g,'$1')//spaces at EOL txt = '\n'+txt+'\n' loc_r(/\{\{Божество([\s\r\n]+)\|/, '{{Божество D&D/d20$1\|') function loc_r(r1, r2){ txt = txt.replace(r1, r2) } function loc_hide(re){ loc_r(re, function(s){return '\x01'+hidden.push(s)+'\x02'})} function loc_hideTag(tag){ loc_hide(RegExp('<' + tag + '( [^>]+)?>[\\s\\S]+?<\\/' + tag + '>','gi')) } }