Jump to content

MediaWiki:Common.js: Difference between revisions

From Artemis Archive
Created page with "Any JavaScript here will be loaded for all users on every page load.: $(function() { // Create the link element var reportLink = $('<li>') .attr('id', 'pt-report-abuse') .append( $('<a>') .attr('href', mw.util.getUrl('Report_Animal_Abuse')) // Assumes page is named Report_Animal_Abuse .text('Report Abuse') ); // Try to insert it before the login link, or after the ULS link var loginLink = $('#pt-login'); var ulsLink = $('..."
 
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(29 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() {
    // check if MinervaNeue
  // Create the link element
    if (mw.config.get('skin') === 'minerva') {
  var reportLink = $('<li>')
         console.log('[ReportAbuseLink] when MinervaNeue skin,disable button');
    .attr('id', 'pt-report-abuse')
         return;
    .append(
     }
      $('<a>')
         .attr('href', mw.util.getUrl('Report_Animal_Abuse')) // Assumes page is named Report_Animal_Abuse
         .text('Report Abuse')
     );


  // Try to insert it before the login link, or after the ULS link
    mw.loader.using('mediawiki.util').then(function () {
  var loginLink = $('#pt-login');
        console.log('[ReportAbuseLink] insert hover button...');
  var ulsLink = $('#pt-uls'); // ULS link/button ID


  if (loginLink.length) {
        const pageTitle = 'Report_Animal_Abuse';
    reportLink.insertBefore(loginLink);
        const linkHref = mw.util.getUrl(pageTitle);
  } else if (ulsLink.length) {
        const linkText = '🚨 Report Animal Abuse';
    reportLink.insertAfter(ulsLink);
 
  } else {
        if (document.getElementById('report-abuse-button')) return;
    // Fallback: Append to the end of the personal tools list (may need adjustment based on skin)
 
    $('#p-personal ul').append(reportLink);
        // 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]');
    });
});
});

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