No edit summary |
No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | function |
+ | $(document).ready(function() { |
⚫ | |||
− | // Use MediaWiki's user interface elements to check the login status |
||
− | + | if (mw.user.isAnon()) { |
|
⚫ | |||
− | } |
||
⚫ | |||
− | |||
− | + | var $element = $(this); |
|
⚫ | |||
− | // Check if aria-disabled is set to "true" |
||
− | + | $element.after(loginMessage); |
|
− | + | }); |
|
⚫ | |||
− | |||
− | // Insert the message after the disabled button |
||
− | $element.after(loginMessage); |
||
− | } |
||
− | } |
||
− | |||
− | function observeDOM() { |
||
− | // Select the target node where you expect the dynamic changes |
||
− | var targetNode = document.body; // You can specify a more specific container if needed |
||
− | |||
− | // Create a MutationObserver instance |
||
− | var observer = new MutationObserver(function (mutationsList) { |
||
− | for (var mutation of mutationsList) { |
||
− | if (mutation.type === 'childList') { |
||
− | // Handle added nodes |
||
⚫ | |||
− | if (node.nodeType === Node.ELEMENT_NODE) { |
||
− | var $element = $(node); |
||
− | if ($element.hasClass('oo-ui-buttonElement-button')) { |
||
− | insertLoginMessage($element); |
||
− | } |
||
− | } |
||
− | }); |
||
− | } else if (mutation.type === 'attributes' && mutation.attributeName === 'aria-disabled') { |
||
− | // Handle attribute changes |
||
− | var $element = $(mutation.target); |
||
− | insertLoginMessage($element); |
||
− | } |
||
} |
} |
||
− | }); |
+ | }, 250); |
− | |||
− | // Configure and start the observer |
||
− | var config = { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-disabled'] }; |
||
− | observer.observe(targetNode, config); |
||
− | } |
||
− | |||
− | $(document).ready(function () { |
||
− | // Check the initial state |
||
− | checkElements(); |
||
− | |||
− | // Observe DOM for changes |
||
− | observeDOM(); |
||
− | |||
− | function checkElements() { |
||
− | // Select all elements with the specified class |
||
⚫ | |||
⚫ | |||
− | var $element = $(this); |
||
− | insertLoginMessage($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);
});