User:Vprajkumar/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin can be added at User:Vprajkumar/monobook.css. |
// define custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdDiv', 'wikEdButton', 'Make the selection a html DIV element', '/media/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'DIV', 'javascript:WikEdEditButton(this, this.id, null, BracesHandler);' ];
wikEdButton[101] = ['wikEdTest', 'wikEdButton', 'This is a test button', '/media/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Test', 'javascript:WikEdEditButton(this, this.id, null, BracketsHandler);' ];
// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = {};
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1', 'wikEdButtonBarCustom1', 'wikEdButtonsCustom1', 'wikEdButtonsCustom1', 44, 'My custom buttons', [100, 'br', 101] ];
//This function adds or removes Brackets around the selected text
function BracketsHandler(obj) {
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
// make your changes to the plain target text in obj.changed.plain
// or remove the previously added formatting
if ( /{{(.*?)}}/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/( (.*?) )/gi, '$1');
}
// add the text formatting
else {
obj.changed.plain = '{{' + obj.changed.plain + '}}';
obj.changed.plain = obj.changed.plain.replace(/(()( *)(.*?)( *)())/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}
//This function adds or removes braces around the selected text
function BracesHandler(obj) {
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
// make your changes to the plain target text in obj.changed.plain
// or remove the previously added formatting
if ( /{{(.*?)}}/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/{{(.*?)}}/gi, '$1');
}
// add the text formatting
else {
obj.changed.plain = '{{' + obj.changed.plain + '}}';
obj.changed.plain = obj.changed.plain.replace(/({{)( *)(.*?)( *)(}})/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}
//===============================
// End of Custom features
//===============================
// addPurge
addOnloadHook(function () {
var hist; var url;
if (!(hist = document.getElementById('ca-history') )) return;
if (!(url = hist.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
'purge', 'ca-purge', 'Purge server cache for this page', '0');
});