MediaWiki:Gadget-Sections.js
Արտաքին տեսք
Ծանուցում. Հիշելուց հետո կատարված փոփոխությունները տեսնելու համար մաքրեք ձեր զննարկիչի հիշապահեստը. Mozilla / Firefox / Safari՝ Ctrl+Shift+R (Cmd+Shift+R Mac OS X-ում) Konqueror՝ F5 Opera՝ Tools→Preferences ընտրացանկից։ Internet Explorer՝ Ctrl+F5
/*
* Sections
*
* Button in the top-right corner, near the logout button. Formats the text typography according to the conventions defined in the [[Wikisource:Typographic Guide|Typographic Guide]] of Wikisource.
*
* This rule is used to automatically find and mark sections.
*/
$.sections = {
todo: [],
add: function(fonction) {
$.sections.todo.push(fonction);
},
exec: function() {
var namespace = mw.config.get('wgNamespaceNumber');
if (namespace % 2 === 1 || $.inArray(namespace, [ 4, 8 ]) !== -1) {
return;
}
var $textbox = $('#wpTextbox1');
var txt = $textbox.val();
for (var i = 0; i < $.sections.todo.length; ++i) {
txt = $.sections.todo[i](txt);
}
$textbox.val(txt);
},
};
$(function() {
if($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) === -1 ) {
return;
}
// Add the new transformation function
$.sections.add(function(str) {
const seenSections = new Set();
return str.replace(/\{\{x-larger\|\s*'?''?(.*?)''?'?\}\}/g, function(match, sectionName) {
const cleanSectionName = sectionName.replace(/'+/g, '').trim();
if (!seenSections.has(cleanSectionName)) {
seenSections.add(cleanSectionName);
return `## ${cleanSectionName} ##\n${match}`;
}
return match;
}).replace(/<big>\s*(.*?)\s*<\/big>/g, function(match, sectionName) {
const cleanSectionName = sectionName.trim();
if (!seenSections.has(cleanSectionName)) {
seenSections.add(cleanSectionName);
return `## ${cleanSectionName} ##\n${match}`;
}
return match;
});
});
var dependencies = ['ext.wikiEditor'];
if(mw.config.get('wgCanonicalNamespace') === 'Էջ') {
dependencies.push('ext.proofreadpage.page.edit');
}
mw.loader.using(dependencies, function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'main',
group: 'insert',
tools: {
'sections': {
label: 'Find and Mark Sections',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/8/82/Toolbaricon_regular_T.png',
action: {
type: 'callback',
execute: $.sections.exec,
},
},
},
});
});
});