Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
$(function () {
$(function () {
     console.log('[ReportAbuseLink] Running (Styled Float)...');
     mw.loader.using('mediawiki.util').then(function () {
        console.log('[ReportAbuseLink] Running...');


    // Avoid duplicate buttons
        const reportPage = 'Report_Animal_Abuse'; // page title
    if (document.getElementById('report-abuse-button')) return;
        const linkText = '🚨 Report Abuse';


    const link = document.createElement('a');
        const insertLink = function () {
    link.id = 'report-abuse-button';
            const personalList = document.querySelector('#p-personal ul.vector-menu-content-list');
    link.href = mw.util.getUrl('Report_Animal_Abuse');
            const langButton = document.querySelector('#p-lang-btn, #vector-lang-button'); // language button
    link.textContent = '🐾 Report Abuse';
            const loginItem = document.querySelector('#pt-login-2, #pt-login');


    // Styling
            if (!personalList) {
    link.style.position = 'fixed';
                console.log('[ReportAbuseLink] personal tools list not found.');
    link.style.top = '16px';
                return false;
    link.style.right = '90px'; // shift left to avoid overlapping menus
            }
    link.style.backgroundColor = '#f8f9fa'; // vector skin bg
    link.style.color = '#202122';
    link.style.border = '1px solid #a2a9b1';
    link.style.padding = '6px 10px';
    link.style.borderRadius = '6px';
    link.style.fontSize = '14px';
    link.style.fontFamily = 'system-ui, sans-serif';
    link.style.fontWeight = 'normal';
    link.style.zIndex = '9999';
    link.style.textDecoration = 'none';
    link.style.boxShadow = '0 1px 3px rgba(0,0,0,0.1)';
    link.style.transition = 'background-color 0.2s, box-shadow 0.2s';


    // Hover effect
            // Create the list item
    link.addEventListener('mouseenter', () => {
            const li = document.createElement('li');
        link.style.backgroundColor = '#eaf3ff';
            li.id = 'pt-reportabuse';
        link.style.boxShadow = '0 2px 6px rgba(0,0,0,0.2)';
            const link = document.createElement('a');
    });
            link.href = mw.util.getUrl(reportPage);
    link.addEventListener('mouseleave', () => {
            link.textContent = linkText;
        link.style.backgroundColor = '#f8f9fa';
            link.style.color = '#b10000';
        link.style.boxShadow = '0 1px 3px rgba(0,0,0,0.1)';
            link.style.fontWeight = 'bold';
    });
            li.appendChild(link);
 
            if (langButton && langButton.closest('li')?.parentNode === personalList) {
                personalList.insertBefore(li, langButton.closest('li'));
                console.log('[ReportAbuseLink] Inserted before language button.');
            } else if (loginItem && loginItem.closest('li')?.parentNode === personalList) {
                personalList.insertBefore(li, loginItem.closest('li'));
                console.log('[ReportAbuseLink] Inserted before login.');
            } else {
                personalList.appendChild(li);
                console.log('[ReportAbuseLink] Appended to the end.');
            }


    document.body.appendChild(link);
            return true;
        };


    console.log('[ReportAbuseLink] Button inserted.');
        // Try inserting with retry logic
        let attempts = 0;
        const maxAttempts = 30;
        const retryInterval = setInterval(() => {
            if (insertLink() || ++attempts >= maxAttempts) {
                clearInterval(retryInterval);
                console.log('[ReportAbuseLink] Done.');
            }
        }, 200);
    });
});
});

Revision as of 05:48, 21 April 2025

$(function () {
    mw.loader.using('mediawiki.util').then(function () {
        console.log('[ReportAbuseLink] Running...');

        const reportPage = 'Report_Animal_Abuse'; // page title
        const linkText = '🚨 Report Abuse';

        const insertLink = function () {
            const personalList = document.querySelector('#p-personal ul.vector-menu-content-list');
            const langButton = document.querySelector('#p-lang-btn, #vector-lang-button'); // language button
            const loginItem = document.querySelector('#pt-login-2, #pt-login');

            if (!personalList) {
                console.log('[ReportAbuseLink] personal tools list not found.');
                return false;
            }

            // Create the list item
            const li = document.createElement('li');
            li.id = 'pt-reportabuse';
            const link = document.createElement('a');
            link.href = mw.util.getUrl(reportPage);
            link.textContent = linkText;
            link.style.color = '#b10000';
            link.style.fontWeight = 'bold';
            li.appendChild(link);

            if (langButton && langButton.closest('li')?.parentNode === personalList) {
                personalList.insertBefore(li, langButton.closest('li'));
                console.log('[ReportAbuseLink] Inserted before language button.');
            } else if (loginItem && loginItem.closest('li')?.parentNode === personalList) {
                personalList.insertBefore(li, loginItem.closest('li'));
                console.log('[ReportAbuseLink] Inserted before login.');
            } else {
                personalList.appendChild(li);
                console.log('[ReportAbuseLink] Appended to the end.');
            }

            return true;
        };

        // Try inserting with retry logic
        let attempts = 0;
        const maxAttempts = 30;
        const retryInterval = setInterval(() => {
            if (insertLink() || ++attempts >= maxAttempts) {
                clearInterval(retryInterval);
                console.log('[ReportAbuseLink] Done.');
            }
        }, 200);
    });
});