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
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(function () {
$(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 () {
     mw.loader.using('mediawiki.util').then(function () {
         console.log('[ReportAbuseLink] Starting...');
         console.log('[ReportAbuseLink] insert hover button...');
 
        const reportLinkText = '🐾 Report Abuse';
        const reportPageURL = mw.util.getUrl('Report_Animal_Abuse'); // Change if your page name differs
 
        let attempts = 0;
        const maxAttempts = 50;


         const tryInsert = function () {
         const pageTitle = 'Report_Animal_Abuse';
            const personalMenu = document.querySelector('#p-personal ul.vector-menu-content-list');
        const linkHref = mw.util.getUrl(pageTitle);
            const loginItem = document.querySelector('#pt-login-2');
        const linkText = '🚨 Report Animal Abuse';


            if (personalMenu && loginItem) {
        if (document.getElementById('report-abuse-button')) return;
                console.log('[ReportAbuseLink] Found login item. Inserting before it.');
                const li = document.createElement('li');
                li.id = 'pt-reportabuse';


                const a = document.createElement('a');
        // create <style> elements
                a.href = reportPageURL;
        const style = document.createElement('style');
                a.textContent = reportLinkText;
        style.textContent = `
                a.title = 'Report animal abuse to authorities or NGOs';
            #report-abuse-button a:hover {
 
                 background-color: #ff0000 !important;
                 li.appendChild(a);
                 box-shadow: 0 0 12px rgba(255, 0, 0, 0.8);
                 personalMenu.insertBefore(li, loginItem);
                 transform: scale(1.05);
                 return true;
                 transition: all 0.2s ease-in-out;
            } else if (personalMenu && attempts >= maxAttempts) {
                console.log('[ReportAbuseLink] Login item not found after max attempts. Appending to end.');
                 const li = document.createElement('li');
                li.id = 'pt-reportabuse';
 
                const a = document.createElement('a');
                a.href = reportPageURL;
                a.textContent = reportLinkText;
                a.title = 'Report animal abuse to authorities or NGOs';
 
                li.appendChild(a);
                personalMenu.appendChild(li);
                return true;
             }
             }
        `;
        document.head.appendChild(style);


             return false;
        // 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>`;


         const interval = setInterval(function () {
         document.body.appendChild(container);
            attempts++;
        console.log('[ReportAbuseLink]');
            if (tryInsert() || attempts >= maxAttempts) {
                clearInterval(interval);
                console.log('[ReportAbuseLink] Done.');
            }
        }, 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]');
    });
});