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
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
$(function () {
     if (mw.config.get('skin') !== 'vector-2022') return;
    // check if MinervaNeue
     if (mw.config.get('skin') === 'minerva') {
        console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
        return;
    }


     // Wait for the menu to render
     mw.loader.using('mediawiki.util').then(function () {
    var interval = setInterval(function () {
         console.log('[ReportAbuseLink] insert hover button...');
         var userLinks = document.querySelector('#vector-user-links ul');


         if (userLinks) {
         const pageTitle = 'Report_Animal_Abuse';
            clearInterval(interval);
        const linkHref = mw.util.getUrl(pageTitle);
        const linkText = '🚨 Report Animal Abuse';


            // Create the new list item
        if (document.getElementById('report-abuse-button')) return;
            var li = document.createElement('li');
            li.id = 'pt-reportabuse';


            var link = document.createElement('a');
        // create <style> elements
             link.href = '/wiki/ReportAnimalAbuse'; // Change to your actual target
        const style = document.createElement('style');
            link.textContent = '🐾 Report Abuse';
        style.textContent = `
             link.title = 'Report animal abuse';
             #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);


             li.appendChild(link);
        // 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>`;


            // Find the login item to insert before
        document.body.appendChild(container);
            var loginItem = document.querySelector('#pt-login');
        console.log('[ReportAbuseLink]');
            if (loginItem) {
     });
                userLinks.insertBefore(li, loginItem);
            } else {
                userLinks.appendChild(li);
            }
        }
     }, 100); // Check every 100ms until menu appears
});
});

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