MediaWiki:Common.js: Difference between revisions
Horia Modran (talk | contribs) No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 33: | Line 33: | ||
); | ); | ||
} | } | ||
// HIDE TOOLBOX for anonymous users | |||
if (mw.config.get('wgUserName') === null) { | |||
// For classic skins | |||
$('#p-tb').hide(); | |||
// For Vector 2022: also try hiding dropdown | |||
$('#p-toolbox, #vector-page-tools, #vector-page-tools-dropdown').hide(); | |||
} | |||
// ❌ Hide "Switch to old look" link for ALL users (including in dropdowns) | |||
function hideSkinSwitcher() { | |||
$('a').filter(function () { | |||
return $(this).text().trim() === 'Switch to old look'; | |||
}).closest('li, span, div').hide(); | |||
} | |||
hideSkinSwitcher(); // Run once immediately | |||
// 🕵️♂️ Watch for late rendering (e.g. in dropdowns) | |||
const observer = new MutationObserver(hideSkinSwitcher); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
}); | }); | ||
}); | }); |
Latest revision as of 11:20, 2 June 2025
mw.loader.using('mediawiki.util', function () {
$(function(){
// Get the list of categories assigned to this page
var cats = mw.config.get('wgCategories') || [];
// Specify the category you want to target
var targetCat = 'InternationalisationForms';
// Only proceed if the page is in that category
if ( cats.indexOf(targetCat) !== -1 ) {
// Create and style the button-like link
var $pdfLink = $('<a>')
.text('📄 Export this page to PDF')
.attr('href','#')
.css({
display: 'inline-block',
padding: '0.39em 0.77em',
'font-size': '0.82em',
'background-color': '#19529E',
color: '#fff',
'text-decoration': 'none',
'border-radius': '3px',
margin: '0.39em'
})
.click(function(e){
e.preventDefault();
window.print();
})
$('#content').before(
$('<div>')
.attr('id', 'export-to-pdf-container')
.css({ 'text-align': 'right', padding: '0.5em' })
.append($pdfLink)
);
}
// HIDE TOOLBOX for anonymous users
if (mw.config.get('wgUserName') === null) {
// For classic skins
$('#p-tb').hide();
// For Vector 2022: also try hiding dropdown
$('#p-toolbox, #vector-page-tools, #vector-page-tools-dropdown').hide();
}
// ❌ Hide "Switch to old look" link for ALL users (including in dropdowns)
function hideSkinSwitcher() {
$('a').filter(function () {
return $(this).text().trim() === 'Switch to old look';
}).closest('li, span, div').hide();
}
hideSkinSwitcher(); // Run once immediately
// 🕵️♂️ Watch for late rendering (e.g. in dropdowns)
const observer = new MutationObserver(hideSkinSwitcher);
observer.observe(document.body, { childList: true, subtree: true });
});
});