MediaWiki:Common.js: Difference between revisions
Arisepedia (talk | contribs) (Created page with "→Any JavaScript here will be loaded for all users on every page load.: // Prevent right-click, double-click, and text selection (function () { // Disable right-click everywhere document.addEventListener('contextmenu', function (e) { e.preventDefault(); }); // Prevent text selection start document.addEventListener('selectstart', function (e) { e.preventDefault(); }); // Block double-click and triple-click document.addEventListener('mousedown'...") |
Arisepedia (talk | contribs) No edit summary |
||
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. */ | ||
// | // Public-only copy deterrent; admins/editors unaffected | ||
(function () { | (function () { | ||
// Disable right-click | var action = mw.config.get('wgAction'); // 'view', 'edit', etc. | ||
var groups = mw.config.get('wgUserGroups') || []; | |||
// Define who should be exempt (enable/trim as you like) | |||
var isPrivileged = | |||
groups.includes('sysop') || | |||
groups.includes('bureaucrat') || | |||
groups.includes('interface-admin') || | |||
groups.includes('editor') || // remove if you don't have this group | |||
groups.includes('patroller'); // remove if you don't use this | |||
// Run only on read/view pages and only for non-privileged users | |||
if (action !== 'view' || isPrivileged) return; | |||
// Mark page so CSS activates only for these users | |||
document.documentElement.classList.add('no-copy'); | |||
// Disable right-click (admins are exempt above) | |||
document.addEventListener('contextmenu', function (e) { | document.addEventListener('contextmenu', function (e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
}); | }, { capture: true }); | ||
// Prevent | // Prevent starting a selection (keeps links clickable) | ||
document.addEventListener('selectstart', function (e) { | document.addEventListener('selectstart', function (e) { | ||
// Allow in fields/editable areas just in case | |||
var t = e.target; | |||
var tag = (t.tagName || '').toLowerCase(); | |||
if (tag === 'input' || tag === 'textarea' || t.isContentEditable || (t.closest && t.closest('#wpTextbox1'))) { | |||
return; | |||
} | |||
e.preventDefault(); | e.preventDefault(); | ||
}); | }, { capture: true }); | ||
// Block double | // Block double/triple click selection | ||
document.addEventListener('mousedown', function (e) { | document.addEventListener('mousedown', function (e) { | ||
if (e.detail > 1) | // left/right clicks still work; we only block multi-click selection | ||
if (e.detail > 1) e.preventDefault(); | |||
}, { capture: true }); | |||
})(); | })(); |
Latest revision as of 16:26, 6 October 2025
/* Any JavaScript here will be loaded for all users on every page load. */ // Public-only copy deterrent; admins/editors unaffected (function () { var action = mw.config.get('wgAction'); // 'view', 'edit', etc. var groups = mw.config.get('wgUserGroups') || []; // Define who should be exempt (enable/trim as you like) var isPrivileged = groups.includes('sysop') || groups.includes('bureaucrat') || groups.includes('interface-admin') || groups.includes('editor') || // remove if you don't have this group groups.includes('patroller'); // remove if you don't use this // Run only on read/view pages and only for non-privileged users if (action !== 'view' || isPrivileged) return; // Mark page so CSS activates only for these users document.documentElement.classList.add('no-copy'); // Disable right-click (admins are exempt above) document.addEventListener('contextmenu', function (e) { e.preventDefault(); }, { capture: true }); // Prevent starting a selection (keeps links clickable) document.addEventListener('selectstart', function (e) { // Allow in fields/editable areas just in case var t = e.target; var tag = (t.tagName || '').toLowerCase(); if (tag === 'input' || tag === 'textarea' || t.isContentEditable || (t.closest && t.closest('#wpTextbox1'))) { return; } e.preventDefault(); }, { capture: true }); // Block double/triple click selection document.addEventListener('mousedown', function (e) { // left/right clicks still work; we only block multi-click selection if (e.detail > 1) e.preventDefault(); }, { capture: true }); })();