Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
$(function () {
$(function () {
     // identify mobile device
     // check if MinervaNeue
     const isMobile = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
     if (mw.config.get('skin') === 'minerva') {
    if (isMobile) {
         console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
         console.log('[ReportAbuseLink] Mobile device detected – button disabled.');
         return;
         return;
     }
     }


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


    const linkURL = '/index.php/Report_Animal_Abuse'; // target page
        const pageTitle = 'Report_Animal_Abuse';
    const linkText = 'Report Abuse';
        const linkHref = mw.util.getUrl(pageTitle);
        const linkText = '🚨 Report Animal Abuse';


    const button = document.createElement('a');
        if (document.getElementById('report-abuse-button')) return;
    button.href = linkURL;
    button.textContent = linkText;
    button.style.position = 'absolute';
    button.style.top = '0.5rem';
    button.style.right = '1rem';
    button.style.padding = '10px 16px';
    button.style.backgroundColor = '#ff4444';
    button.style.color = 'white';
    button.style.fontWeight = 'bold';
    button.style.borderRadius = '6px';
    button.style.textDecoration = 'none';
    button.style.zIndex = '9999';
    button.style.fontSize = '16px';
    button.style.transition = 'background-color 0.3s ease';


    // Hover effect
        // create <style> elements
    button.addEventListener('mouseover', function () {
        const style = document.createElement('style');
         button.style.backgroundColor = '#cc0000';
         style.textContent = `
    });
            #report-abuse-button a:hover {
    button.addEventListener('mouseout', function () {
                background-color: #ff0000 !important;
         button.style.backgroundColor = '#ff4444';
                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]');
     });
     });
    document.body.appendChild(button);
    console.log('[ReportAbuseLink] Button inserted.');
});
});

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]');
    });
});