MediaWiki:Citizen.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
function isUserLoggedIn() {
+
$(document).ready(function() {
  +
setTimeout(function() {
return !mw.user.isAnon();
+
if (mw.user.isAnon()) {
}
 
  +
var elements = $('.cs-header > .oo-ui-widget-disabled');
 
  +
elements.each(function() {
function handleElement($element) {
 
if ($element.attr('aria-disabled') === 'true') {
+
var $element = $(this);
 
var loginMessage = '<p style="cs-custom-login-prompt">Please <a href="/wiki/Special:UserLogin">login</a> or <a href="/wiki/Special:CreateAccount">sign up</a> to continue.</p>';
$element.after(
+
$element.after(loginMessage);
'<p>Please <a href="/wiki/Special:UserLogin">login</a> or <a href="/wiki/Special:UserSignup">sign up</a> to continue.</p>'
 
);
 
}
 
}
 
 
function handleMutations(mutationsList) {
 
mutationsList.forEach((mutation) => {
 
if (mutation.type === 'childList') {
 
mutation.addedNodes.forEach((node) => {
 
if ($(node).hasClass('oo-ui-buttonElement-button')) {
 
handleElement($(node));
 
}
 
 
});
 
});
} else if (mutation.type === 'attributes' && mutation.attributeName === 'aria-disabled') {
 
handleElement($(mutation.target));
 
 
}
 
}
});
+
}, 250);
}
 
 
const observer = new MutationObserver(handleMutations);
 
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-disabled'] });
 
 
$(document).ready(() => {
 
$('.oo-ui-buttonElement-button').each((index, element) => {
 
handleElement($(element));
 
});
 
 
});
 
});

Latest revision as of 01:31, 15 October 2023

$(document).ready(function() {
    setTimeout(function() {
        if (mw.user.isAnon()) {
            var elements = $('.cs-header > .oo-ui-widget-disabled');
            elements.each(function() {
                var $element = $(this);
                var loginMessage = '<p style="cs-custom-login-prompt">Please <a href="/wiki/Special:UserLogin">login</a> or <a href="/wiki/Special:CreateAccount">sign up</a> to continue.</p>';
                $element.after(loginMessage);
            });
        }
    }, 250);
});