MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* 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 }); })();