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.
function isUserLoggedIn() {
return !mw.user.isAnon();
}
function handleElement($element) {
if ($element.attr('aria-disabled') === 'true') {
console.log('User not logged in; adding login message');
$element.after('<p>Please <a href="/wiki/Special:UserLogin">login</a> or <a href="/wiki/Special:UserSignup">sign up</a> to continue.</p>');
} else {
console.log('User is logged in; no message added');
}
}
function handleMutations(mutationsList) {
mutationsList.forEach(function (mutation) {
if (mutation.type === 'childList') {
Array.prototype.forEach.call(mutation.addedNodes, function (node) {
if ($(node).hasClass('oo-ui-buttonElement-button')) {
console.log('Handling dynamic element');
handleElement($(node));
}
});
} else if (mutation.type === 'attributes' && mutation.attributeName === 'aria-disabled') {
console.log('Handling attribute change');
handleElement($(mutation.target));
}
});
}
$(document).ready(function () {
console.log('Checking initial state');
var observer = new MutationObserver(handleMutations);
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-disabled'] });
$('.oo-ui-buttonElement-button').each(function (index, element) {
console.log('Handling initial element');
handleElement($(element));
});
});