Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
No edit summary
Tag: Reverted
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(8 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] Running...');
         console.log('[ReportAbuseLink] insert hover button...');


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


         const insertLink = function () {
         if (document.getElementById('report-abuse-button')) return;
            const personalList = document.querySelector('#p-personal ul.vector-menu-content-list');
            const langButton = document.querySelector('#p-lang-btn, #vector-lang-button'); // language button
            const loginItem = document.querySelector('#pt-login-2, #pt-login');


            if (!personalList) {
        // create <style> elements
                 console.log('[ReportAbuseLink] personal tools list not found.');
        const style = document.createElement('style');
                 return false;
        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);


            // Create the list item
        // build button
            const li = document.createElement('li');
        const container = document.createElement('div');
            li.id = 'pt-reportabuse';
        container.id = 'report-abuse-button';
            const link = document.createElement('a');
        container.innerHTML = `<a href="${linkHref}" style="
             link.href = mw.util.getUrl(reportPage);
             display: inline-block;
             link.textContent = linkText;
             background-color: #b10000;
             link.style.color = '#b10000';
             color: #fff;
             link.style.fontWeight = 'bold';
             font-weight: bold;
             li.appendChild(link);
             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>`;


            if (langButton && langButton.closest('li')?.parentNode === personalList) {
        document.body.appendChild(container);
                personalList.insertBefore(li, langButton.closest('li'));
         console.log('[ReportAbuseLink]');
                console.log('[ReportAbuseLink] Inserted before language button.');
            } else if (loginItem && loginItem.closest('li')?.parentNode === personalList) {
                personalList.insertBefore(li, loginItem.closest('li'));
                console.log('[ReportAbuseLink] Inserted before login.');
            } else {
                personalList.appendChild(li);
                console.log('[ReportAbuseLink] Appended to the end.');
            }
 
            return true;
        };
 
        // Try inserting with retry logic
        let attempts = 0;
        const maxAttempts = 30;
         const retryInterval = setInterval(() => {
            if (insertLink() || ++attempts >= maxAttempts) {
                clearInterval(retryInterval);
                console.log('[ReportAbuseLink] Done.');
            }
        }, 200);
     });
     });
});
});

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