Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(function () {
$(function () {
     const isMobile = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
     // check if MinervaNeue
    const reportPage = '/index.php/Report_Animal_Abuse';
    if (mw.config.get('skin') === 'minerva') {
     const linkText = '🚨 Report Abuse';
        console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
        return;
     }


     if (!isMobile) {
     mw.loader.using('mediawiki.util').then(function () {
         // desktop button
         console.log('[ReportAbuseLink] insert hover button...');
        const button = document.createElement('a');
        button.href = reportPage;
        button.textContent = linkText;
        button.id = 'report-abuse-button';


         Object.assign(button.style, {
         const pageTitle = 'Report_Animal_Abuse';
            position: 'fixed',
        const linkHref = mw.util.getUrl(pageTitle);
            top: '10px',
        const linkText = '🚨 Report Animal Abuse';
            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 () {
         if (document.getElementById('report-abuse-button')) return;
            button.style.backgroundColor = '#ff0000';
        });
        button.addEventListener('mouseout', function () {
            button.style.backgroundColor = '#b60000';
        });


         document.body.appendChild(button);
         // create <style> elements
    } else {
        const style = document.createElement('style');
        // mobile footer link
        style.textContent = `
        const footerCheckInterval = setInterval(function () {
            #report-abuse-button a:hover {
            const footer = document.querySelector('#footer-places');
                background-color: #ff0000 !important;
             if (footer) {
                box-shadow: 0 0 12px rgba(255, 0, 0, 0.8);
                clearInterval(footerCheckInterval);
                transform: scale(1.05);
                transition: all 0.2s ease-in-out;
             }
        `;
        document.head.appendChild(style);


                const li = document.createElement('li');
        // build button
                const link = document.createElement('a');
        const container = document.createElement('div');
                link.href = reportPage;
        container.id = 'report-abuse-button';
                link.textContent = linkText;
        container.innerHTML = `<a href="${linkHref}" style="
                link.style.color = '#b60000';
            display: inline-block;
                link.style.fontWeight = 'bold';
            background-color: #b10000;
            color: #fff;
            font-weight: bold;
            font-size: 18px;
            padding: 10px 18px;
            border-radius: 8px;
            text-decoration: none;
            position: fixed;
            top: 12px;
            right: 12px;
            z-index: 9999;
            box-shadow: 0 4px 8px rgba(0,0,0,0.25);
        ">${linkText}</a>`;


                li.appendChild(link);
        document.body.appendChild(container);
                footer.appendChild(li);
        console.log('[ReportAbuseLink]');
            }
    });
        }, 500);
    }
});
});

Latest revision as of 08:03, 21 April 2025

$(function () {
    // check if MinervaNeue
    if (mw.config.get('skin') === 'minerva') {
        console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
        return;
    }

    mw.loader.using('mediawiki.util').then(function () {
        console.log('[ReportAbuseLink] insert hover button...');

        const pageTitle = 'Report_Animal_Abuse';
        const linkHref = mw.util.getUrl(pageTitle);
        const linkText = '🚨 Report Animal Abuse';

        if (document.getElementById('report-abuse-button')) return;

        // create <style> elements
        const style = document.createElement('style');
        style.textContent = `
            #report-abuse-button a:hover {
                background-color: #ff0000 !important;
                box-shadow: 0 0 12px rgba(255, 0, 0, 0.8);
                transform: scale(1.05);
                transition: all 0.2s ease-in-out;
            }
        `;
        document.head.appendChild(style);

        // build button
        const container = document.createElement('div');
        container.id = 'report-abuse-button';
        container.innerHTML = `<a href="${linkHref}" style="
            display: inline-block;
            background-color: #b10000;
            color: #fff;
            font-weight: bold;
            font-size: 18px;
            padding: 10px 18px;
            border-radius: 8px;
            text-decoration: none;
            position: fixed;
            top: 12px;
            right: 12px;
            z-index: 9999;
            box-shadow: 0 4px 8px rgba(0,0,0,0.25);
        ">${linkText}</a>`;

        document.body.appendChild(container);
        console.log('[ReportAbuseLink]');
    });
});