User:Becasita/wikia.js
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: hold down Ctrl and click the Refresh or Reload button. Firefox: hold down ⇧ Shift while clicking Reload (or press Ctrl+⇧ Shift+R). Google Chrome and Safari users can just click the Reload button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* Appends «useskin=monobook» to the URL. */
function _appendMonobook(){
var url = window.location.href;
return url + ((url.indexOf('?') > -1) ? '&' : '?') + 'useskin=monobook';
}
/* Trying to make some pages automatically display using the monobook skin. */
$(function(){
switch (mw.config.get('wgPageName')) {
case 'Historic_Forbidden/Limited_Chart':
case 'User:Becasita/SubPages/Sandbox/13':
case 'User:Becasita/SubPages/Sandbox/10':
if (window.location.search.indexOf('action=edit') < 0) {
window.location = _appendMonobook();
}
break;
}
});
/* Add link to [[Special:Editcount]] on user contributions page. */
$('#contentSub').html(function(){
var userName = $('[itemprop="name"]').text();
var $link = $('<a>', {
href: '/wiki/Special:Editcount/' + userName,
title: 'Special:Editcount/' + userName,
text: 'count'
});
var _find = 'logs</a>';
var _replace = _find + ' | ' + $link.prop('outerHTML');
return $(this).html().replace(_find, _replace);
});
/* Add button to [[Special:RecentChanges]] on the page header. */
$(function(){
var _selector = '.wds-button.wds-is-squished.wds-is-secondary[data-tracking="wiki-activity"]';
return $(_selector).before(function(){
return $('<a>', {
'class': 'wds-button wds-is-squished wds-is-secondary',
href: '/wiki/Special:RecentChanges',
'data-tracking': 'recent-changes',
title: 'Recent Changes',
html: $('<span>', {
css: {
'font-weight': 'bolder',
'transform': 'scaleY(1.3) scaleX(1.2)'
},
text: 'S:RC'
})
});
});
});
/* Add "Browse" button to the page dropdown menu. * /
$(function(){
var _selector = 'div.wds-dropdown__content.wds-is-not-scrollable.wds-is-right-aligned ul.wds-list.wds-is-linked';
return $(_selector).append(function(){
return $('<li>', {
html: $('<a>', {
href: '/wiki/Special:Browse/' + wgPageName,
'data-tracking': 'ca-browse-dropdown',
accesskey: 'b',
text: 'Browse'
})
});
});
});*/
/* Move the FastDelete buttons. */
mw.hook('fastdelete.init').add(function(){
if (mw.config.get('wgNamespaceNumber') == 6) {
// Move:
$('[data-id="fastdelete"]').prependTo('.page-header__contribution-buttons .wds-button-group');
// Strip « »:
$('h1.page-header__title').html($('h1.page-header__title').html().replace(' ', ''));
}
});
/* Add link to [[Special:WhatLinksHere]] on the deletion banner. */
$(function(){
var _selector = '.wds-banner-notification__text'; // Selector (class).
var _selectorText = $(_selector).text(); // Its text.
if (_selectorText.indexOf('undelete') > 1) { // If it's an undelete banner:
var $a = $(_selector + '> a:first-of-type'); // Then find the first <a>,
var $aTitle = $a.prop('title'); // Get its «title».
var regex = /Undelete\/(.*?)$/m; // Create regex to find the pagename.
var pagename = regex.exec($aTitle)[1]; // Apply regex to the first <a> «title».
var path = 'Special:WhatLinksHere/' + pagename; // Concatenate to form the path.
var $link = $('<a>', { // Create link (<a>) object.
href: '/wiki/' + path,
title: path,
text: 'links'
});
$a.after(" | " + $link.prop('outerHTML')); // After the first <a>, add the new link.
}
});
/* Add links to pages I use often to the account dropdown menu. */
$(function(){
var _selector = 'div.wds-dropdown__content.wds-global-navigation__dropdown-content.wds-is-right-aligned ul li';
function _createElement(pagename, label){
return $('<li>', {
html: $('<a>', {
'class': 'wds-global-navigation__dropdown-link',
href: '/wiki/' + pagename,
text: label
})
});
}
var counter = 3;
var pageName = mw.config.get('wgPageName');
var pairs = {
/* My pages: */
'Regex': 'User:Becasita/SubPages/Regex',
'Utilities': 'User:Becasita/SubPages/Utilities',
'Notes': 'User:Becasita/SubPages/Notes/Galleries&Images',
/* Special pages: */
'Browse': 'Special:Browse/' + pageName,
'Search by Prefix': 'Special:PrefixIndex/' + pageName,
'Multiple Upload': 'Special:MultipleUpload',
'What Links Here': 'Special:WhatLinksHere/' + pageName
};
/* Add link to my contributions: */
$(_selector).eq(1).after(_createElement('Special:Contributions/' + mw.config.get('wgUserName'), 'My Contributions'));
/* Iterate over «pairs»: */
for (var key in pairs) {
$(_selector).eq(counter++).after(_createElement(pairs[key], key));
}
});
/* Add stuff to the bottom bar. */
$(function(){
var _selector = '.WikiaBarWrapper ul li';
function _createElement(path, label){
return $('<li>', {
html: $('<a>', {
href: path,
text: label
})
});
}
$(_selector).last().after(_createElement(_appendMonobook(), 'Monobook')); // Adds option to switch to monobook.
$(_selector).last().after(_createElement('#top', 'Top')); // Adds a «back to the top» button.
});
/* Squeeze the side bar on Lua, JS and CSS pages when editing. */
$(function(){
$('#EditPage').removeClass('editpage-sourcewidemode-off').addClass('editpage-sourcewidemode-on');
$('#EditPageToolbar').addClass('ace-editor-wide');
var styles = {
'margin-top': '-1px',
'width': '624px',
'height': '578px'
};
$('.ace_content').css(styles);
});