MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Created page with "→Any JavaScript here will be loaded for all users on every page load.: // Example to hide Edit Source for anonymous users document.addEventListener("DOMContentLoaded", function() { var userGroups = mw.config.get('wgUserGroups'); if (userGroups.includes('sysop')) { var editSourceLink = document.getElementById('ca-editsource'); if (editSourceLink) { editSourceLink.style.display = 'inline'; } } });" |
No edit summary Tag: Manual revert |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
// | // Function to hide 'Edit' for anonymous users | ||
document.addEventListener("DOMContentLoaded", function() { | document.addEventListener("DOMContentLoaded", function() { | ||
// Get the user groups from MediaWiki config | |||
var userGroups = mw.config.get('wgUserGroups'); | var userGroups = mw.config.get('wgUserGroups'); | ||
// Check if the user is logged in ('user') or an admin ('sysop') | |||
if (userGroups.includes('sysop')) { | if (userGroups.includes('sysop')) { | ||
var | var editLink = document.getElementById('ca-edit'); | ||
if ( | if (editLink) { | ||
editLink.style.display = 'inline'; // Show 'Edit' for logged-in users/admins | |||
} | |||
} else { | |||
// Hide 'Edit' link for anonymous users | |||
var editLink = document.getElementById('ca-edit'); | |||
if (editLink) { | |||
editLink.style.display = 'none'; // Hide 'Edit' for anonymous users | |||
} | } | ||
} | } | ||
}); | }); |
Latest revision as of 21:53, 14 October 2024
/* Any JavaScript here will be loaded for all users on every page load. */ // Function to hide 'Edit' for anonymous users document.addEventListener("DOMContentLoaded", function() { // Get the user groups from MediaWiki config var userGroups = mw.config.get('wgUserGroups'); // Check if the user is logged in ('user') or an admin ('sysop') if (userGroups.includes('sysop')) { var editLink = document.getElementById('ca-edit'); if (editLink) { editLink.style.display = 'inline'; // Show 'Edit' for logged-in users/admins } } else { // Hide 'Edit' link for anonymous users var editLink = document.getElementById('ca-edit'); if (editLink) { editLink.style.display = 'none'; // Hide 'Edit' for anonymous users } } });