MediaWiki:Common.js

Revision as of 07:47, 21 April 2025 by Bxuwd (talk | contribs)

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$(function () {
    const isMobile = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
    const reportPage = '/index.php/Report_Animal_Abuse';
    const linkText = '🚨 Report Abuse';

    if (!isMobile) {
        // desktop button
        const button = document.createElement('a');
        button.href = reportPage;
        button.textContent = linkText;
        button.id = 'report-abuse-button';

        Object.assign(button.style, {
            position: 'fixed',
            top: '10px',
            right: '10px',
            backgroundColor: '#b60000',
            color: 'white',
            padding: '12px 20px',
            fontSize: '16px',
            fontWeight: 'bold',
            borderRadius: '6px',
            textDecoration: 'none',
            zIndex: '9999',
            boxShadow: '0 4px 6px rgba(0,0,0,0.2)',
            transition: 'background-color 0.3s',
        });

        button.addEventListener('mouseover', function () {
            button.style.backgroundColor = '#ff0000';
        });
        button.addEventListener('mouseout', function () {
            button.style.backgroundColor = '#b60000';
        });

        document.body.appendChild(button);
    } else {
        // mobile footer link
        const footerCheckInterval = setInterval(function () {
            const footer = document.querySelector('#footer-places');
            if (footer) {
                clearInterval(footerCheckInterval);

                const li = document.createElement('li');
                const link = document.createElement('a');
                link.href = reportPage;
                link.textContent = linkText;
                link.style.color = '#b60000';
                link.style.fontWeight = 'bold';

                li.appendChild(link);
                footer.appendChild(li);
            }
        }, 500);
    }
});