Jump to content

MediaWiki:Common.js: Difference between revisions

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


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


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


            if (!personalList) {
    // Style the link
                console.log('[ReportAbuseLink] personal tools list not found.');
    link.style.position = 'fixed';
                return false;
    link.style.top = '10px';
            }
    link.style.right = '10px';
    link.style.backgroundColor = '#c00';
    link.style.color = '#fff';
    link.style.padding = '8px 12px';
    link.style.borderRadius = '8px';
    link.style.fontWeight = 'bold';
    link.style.zIndex = '9999';
    link.style.textDecoration = 'none';
    link.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)';


            // Create the list item
    // Insert into body
            const li = document.createElement('li');
    document.body.appendChild(link);
            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) {
    console.log('[ReportAbuseLink] Floating button inserted.');
                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);
    });
});
});

Revision as of 05:49, 21 April 2025

$(function () {
    console.log('[ReportAbuseLink] Running (Forced Float)...');

    // Check if already exists
    if (document.getElementById('report-abuse-button')) return;

    // Create the link
    const link = document.createElement('a');
    link.id = 'report-abuse-button';
    link.href = mw.util.getUrl('Report_Animal_Abuse');
    link.textContent = '🐾 Report Abuse';

    // Style the link
    link.style.position = 'fixed';
    link.style.top = '10px';
    link.style.right = '10px';
    link.style.backgroundColor = '#c00';
    link.style.color = '#fff';
    link.style.padding = '8px 12px';
    link.style.borderRadius = '8px';
    link.style.fontWeight = 'bold';
    link.style.zIndex = '9999';
    link.style.textDecoration = 'none';
    link.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)';

    // Insert into body
    document.body.appendChild(link);

    console.log('[ReportAbuseLink] Floating button inserted.');
});