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
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(function () {
$(function () {
     // Wait until the header tools are available
     // check if MinervaNeue
     const checkInterval = setInterval(function () {
     if (mw.config.get('skin') === 'minerva') {
         const headerTools = document.querySelector('.vector-header-end');
         console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
         if (headerTools) {
         return;
            clearInterval(checkInterval);
    }


            // Avoid adding the link multiple times
    mw.loader.using('mediawiki.util').then(function () {
            if (document.querySelector('#report-abuse-link')) return;
        console.log('[ReportAbuseLink] insert hover button...');


            // Create the link element
        const pageTitle = 'Report_Animal_Abuse';
            const reportLink = document.createElement('a');
        const linkHref = mw.util.getUrl(pageTitle);
            reportLink.id = 'report-abuse-link';
        const linkText = '🚨 Report Animal Abuse';
            reportLink.href = mw.util.getUrl('Report_Animal_Abuse'); // Update with your actual page
            reportLink.textContent = '🐾 Report Abuse';
            reportLink.style.marginLeft = '1em';
            reportLink.style.fontWeight = 'bold';
            reportLink.style.color = '#d33'; // Red color for visibility


            // Insert the link before the login link if it exists
        if (document.getElementById('report-abuse-button')) return;
            const loginLink = headerTools.querySelector('a[href*="Special:UserLogin"]');
 
             if (loginLink) {
        // create <style> elements
                 headerTools.insertBefore(reportLink, loginLink);
        const style = document.createElement('style');
            } else {
        style.textContent = `
                 headerTools.appendChild(reportLink);
             #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>`;


            console.log('[ReportAbuseLink] Inserted into header');
        document.body.appendChild(container);
        }
        console.log('[ReportAbuseLink]');
     }, 100);
     });
});
});

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