Last active
March 1, 2016 16:43
-
-
Save mormegil-cz/c62632bc53ec640ff595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global mediaWiki, jQuery */ | |
/*jslint browser: true, plusplus: true, white: true */ | |
/*jshint browser:true, laxbreak:false, plusplus:false, white:false, undef:true, unused:true */ | |
( function ( mw, $ ) { | |
'use strict'; | |
if ( /*mw.config.get( 'wgNamespaceNumber' ) || */ !/^(edit|submit)$/.test( mw.config.get( 'wgAction' ) ) ) { | |
return; | |
} | |
$( document ).ready( function () { | |
var replacements = [ | |
[ | |
/(^|\n)(==+)([^=]+)(\2) *(?=\n)/g, | |
function ( $0, $1, $2, $3, $4 ) { | |
return $1 + '\n' + $2 + ' ' + $.trim( $3 ) + ' ' + $4; | |
} | |
], [ | |
/\n\{\{\s*[Ss][Uu][Bb][Ss][Tt]\s*:\s*Vzor /g, | |
'\n\n{{subst:Vzor ' | |
], [ | |
/\n([#\*]+)([^\n]*)/g, | |
function ( $0, $1, $2 ) { | |
return '\n' + $1 + ' ' + $.trim( $2 ); | |
} | |
], [ | |
/# [-–] */g, | |
'# —' | |
], [ | |
/# \{\{Překlady *\}\}/g, | |
'# {{Překlady\n}}' | |
], [ | |
/\[\[ *Kategorie *:([^\]]+)\]\]/gi, | |
function ( $0, $1 ) { | |
return '\n[[Kategorie:' + $.trim( $1 ) + ']]\n'; | |
} | |
], [ | |
/(\[\[Kategorie:[^\]]+\]\])\n+(?!\[\[[a-z])/g, | |
'$1\n' | |
], [ | |
/\n+ *\|([^=\n]+)=(?![^\n\|]*\|\|[^\n]*\n)([^\n]*)(?=\n)/g, | |
function ( $0, $1, $2 ) { | |
return '\n | ' + $.trim( $1 ) + ' = ' + $.trim( $2 ); | |
} | |
], [ | |
/([^=]) +\n/g, | |
'$1\n' | |
], [ | |
/([^\n]) +/g, | |
'$1 ' | |
], [ | |
/\n{3,}/g, | |
'\n\n' | |
], [ | |
/=== starší varianta zápisu ===/g, | |
'=== varianty ===' | |
], [ | |
/=== novější varianta zápisu ===/g, | |
'=== varianty ===' | |
], [ | |
/(snom|sgen|sdat|sacc|svoc|sloc|sins|pnom|pgen|pdat|pacc|pvoc|ploc|pins|spre1|spre2|spre3|ppre1|ppre2|ppre3|simp2|pimp1|pimp2|sactm|sactf|sactn|pactm|pactf|actn|ptram|ptraf|ptrap|mtram|mtraf|mtrap|spasm|spasf|spasn|ppasm|ppasf|ppasn|snomma|snomm|snomf|snomn|pnomma|pnomm|pnomf|pnomn|sgenma|sgenm|sgenf|sgenn|pgenma|pgenm|pgenf|pgenn|sdatma|sdatm|sdatf|sdatn|pdatma|pdatm|pdatf|pdatn|saccma|saccm|saccf|saccn|paccma|paccm|paccf|paccn|slocma|slocm|slocf|slocn|plocma|plocm|plocf|plocn|sinsma|sinsm|sinsf|sinsn|pinsma|pinsm|pinsf|pinsn|snomma-jm|snomm-jm|snomf-jm|snomn-jm|pnomma-jm|pnomm-jm|pnomf-jm|pnomn-jm|saccma-jm|saccm-jm|saccf-jm|saccn-jm|paccma-jm|paccm-jm|paccf-jm|paccn-jm) *= *((({{Příznak2\|[^}]*}} *)?[^[\]{}\/\n]+)( *\/ *({{Příznak2\|[^}]*}} *)?[^[\]{}\/\n]+)*)$/gm, | |
function ($0,$1,$2) { | |
var pageName = mw.config.get( 'wgPageName' ); | |
var innerRe = /({{Příznak2\|[^}]*}})? *([^[\]{}\/\n]+)( \/ |$)/gm; | |
var text = $1 + " = " + $2.replace( innerRe, function($0,$1,$2,$3) { | |
var result = $1 ? $1 + " " : ""; | |
if ($2 === pageName) { | |
result += $2; | |
} else { | |
result += "[[" + $2 + "]]"; | |
} | |
if ($3) result += " / "; | |
return result; | |
}); | |
return text; | |
} | |
], | |
]; | |
var $button = $('<button>'); | |
$button.text('AKÚ'); | |
$('#wpDiff').after($button); | |
$button.click( function () { | |
$( '#wpTextbox1' ).val( function ( index, oldPageText ) { | |
var newPageText = oldPageText; | |
$.each( replacements, function ( index, replacement ) { | |
newPageText = newPageText.replace( replacement[0], replacement[1] ); | |
}); | |
newPageText = $.trim( newPageText ) + '\n'; | |
if ( newPageText !== oldPageText ) { | |
$( '#wpSummary' ).val( function ( index, summary ) { | |
var summarySeparator = ''; | |
summary = $.trim( summary ); | |
if ( summary !== '' ) { | |
summarySeparator = /^\/\*.*\*\/$/.test( summary ) ? ' ' : '; '; | |
} | |
return summary + summarySeparator + '[[WS:AKÚ|AKÚ]]+'; | |
}); | |
} | |
return newPageText; | |
}); | |
return false; | |
}); | |
}); | |
}( mediaWiki, jQuery ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment