Користувач:Konstrooktor/Verseficator.js
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
- Opera: натисніть Ctrl-F5
function versefy()
{
strTxt = document.editform.wpTextbox1.value;
strTxt = strTxt.replace(/([А-Яа-яЁёІіЄєҐґЇї]*\s)([0-9]*)(\n\n1\s)/g, '\n== $1$2 ==\n{{глава|$2}}$3');
arrTxt = strTxt.split(/\u007B\u007Bглава\u007C/);
for (i = 1; i < arrTxt.length; i++)
{
strCh = arrTxt[i].match(/[0-9]*\u007D\u007D/);
strCh = strCh[0].match(/[0-9]*/);
if (strCh.length > -1)
{
arrTxt[i] = arrTxt[i].replace(/\n([0-9][0-9]*)\s/g, '\n\u007B\u007Bвірш\u007Cглава='+strCh+'\u007Cвірш=$1\u007D\u007D ');
}
}
strTxt = arrTxt.join('{{глава|');
document.editform.wpTextbox1.value = strTxt;
}
var customizeToolbar = function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'bible': {
'type': 'toolbar',
'label': 'Біблія',
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'bible',
'groups': {
'bible': {
//'label': 'Біблія'
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'bible',
'group': 'bible',
'tools': {
'versefy': {
label: 'Стихи',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/5/5b/Button_check.png',
action: {
type: 'callback',
execute: function(context){
versefy();
}
}
}
}
} );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
mw.loader.using( 'user.options', function () {
if ( mw.user.options.get('usebetatoolbar') ) {
mw.loader.using( 'ext.wikiEditor', function () {
$(document).ready( customizeToolbar );
} );
}
} );
}