Usuario:Chieftain Alex/monobook.js

De Guild Wars 2 Wiki
Ir a la navegaciónIr a la búsqueda

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
/* <pre> */
// DEFER LOADING SCRIPT UNTIL JQUERY IS READY. WAIT 25MS BETWEEN ATTEMPTS.
function defer(method) {
    if (window.jQuery) {
        method();
    } else {
        setTimeout(function() { defer(method) }, 60);
    }
}

// INITIALISATION
defer(function () {
    if (mw.config.get('wgPageName') == 'Especial:Registro/block' || (mw.config.get('wgPageName') == 'Especial:Registro' && new URLSearchParams(window.location.search).get('type') == 'block') ) {
        blocklogTable();
    }

    if (mw.config.get('wgPageName') == 'Especial:RegistroAbusos') {
        abuselogTable();
    }
});

// Scripts to use when viewing the Abuse Log
function abuselogTable() {
    // Make the array into a table
    function makeTableHTML(data) {
        var columns = Object.keys(data[0]);
        var result = '<table id="abuselogtable" class="wikitable" rules="all"><tr>';
        $.each(columns, function(i,v) { result += '<th style="text-align:left;">' + v + '</th>' });
        result += '</tr>';
        $.each(data, function(i,v) {
            result += '<tr>';
            $.each(columns, function(ii,vv){
              if ( typeof v[vv] == 'object') {
                result += '<td>' + '<a class="' + v[vv][2] + '" href="' + v[vv][0] + '">' + v[vv][1] + '</a>' + '</td>';
              } else if (v[vv].substring(0,4) == 'http') {
                result += '<td>' + '<a href="' + v[vv] + '">' + v[vv].replace('https://wiki-es.guildwars2.com/wiki/','') + '</a>' + '</td>';
              } else {
                result += '<td>' + v[vv] + '</td>';
              }
            });
            result += '</tr>';
        });
        result += '</table>';
        return result;
    }

    // Make an array from the wall of text
    var counter = 0;
    var abuselog = $.map( $('body.page-Especial_RegistroAbusos ul.plainlinks li'), function(v) {
      counter += 1;
      return {
         'Timestamp': v.childNodes[0].data.replace(': ',''),
         'Caught user': v.childNodes[1].innerText,
         'Block': [v.childNodes[3].childNodes[(v.childNodes[3].childNodes.length - 2)].href, '(block)', ''],
         'Action': v.childNodes[6].textContent.replace(', performing the action "','').replace('" on ',''),
         'Target page': [v.childNodes[7].href, v.childNodes[7].innerText.substring(0, 60), v.childNodes[7].className],
         'Response': v.childNodes[8].textContent.split('\n')[1].replace('Actions taken: ','').replace(';',''),
         'Filter': v.childNodes[5].innerText.replace('filter ','') + ': ' + v.childNodes[8].textContent.split('\n')[2].replace('Filter description: ','').slice(0, -2),
         'log details': [v.childNodes[9].href, 'examine']
      };
    });

    // Replace the wall of text with a table
    if (counter > 0) {
      $('body.page-Especial_RegistroAbusos ul.plainlinks').replaceWith(makeTableHTML(abuselog));
    }
}


// Scripts to use when viewing the Block Log
function blocklogTable() {
    // Make the array into a table
    function makeTableHTML(data) {
        if (data.length == 0) {
            return '(no data)'
        }

        var columns = Object.keys(data[0]);
        var result = '<table id="blocklogtable" class="wikitable" rules="all"><tr>';
        $.each(columns, function(i,v) { result += '<th style="text-align:left;">' + v + '</th>' });
        result += '</tr>';
        $.each(data, function(i,v) {
            result += '<tr>';
            $.each(columns, function(ii,vv){
              if ( typeof v[vv] == 'object') {
                result += '<td>' + '<a class="' + v[vv][2] + '" href="' + v[vv][0] + '">' + v[vv][1] + '</a>' + '</td>';
              } else {
                result += '<td>' + v[vv] + '</td>';
              }
            });
            result += '</tr>';
        });
        result += '</table>';
        return result;
    }

    // Make an array from the wall of text
    var counter = 0;
    var nomatchlog = [];
    var blocklog = $.map( $('#mw-log-deleterevision-submit ul li.mw-logline-block'), function(v) {
        counter += 1;
        
        // Clean up the plaintext with a trim and a few "find and replace" operations - Remove the links from the admin in question
        // then remove the links from the user or anonymous user.
        var plaintext = v.textContent.trim().replace('talk contribs block blocked','blocked');
        plaintext = plaintext.replace(' talk with an expiration',' with an expiration').replace(' talk contribs','').replace(' (unblock | change block)','');
        
        // Match on the pattern
        var pattern = /^(\d{2}:\d{2}, \d+ \w+ \d{4}) (.*?) blocked (.*?) with an expiration time of (.*?) \((?:.*?)\) \((.*?)\)$/;
        var m = plaintext.match(pattern);
        
        // Check something matched
        if (m) {
            return {
                'Admin': m[2],
                'Timestamp': m[1],
                'Caught user': m[3],
                'Duration': m[4],
                'Reason': m[5],
                'Contribs': ['https://wiki-es.guildwars2.com/wiki/Special:Contributions/' + m[3], 'contribs'],
                'Abuse log': ['https://wiki-es.guildwars2.com/index.php?title=Special:AbuseLog&wpSearchUser=' + m[3], 'abuse log'],
                'Block': ['https://wiki-es.guildwars2.com/wiki/Special:Block/' + m[3], 'block'],
                'Unblock': ['https://wiki-es.guildwars2.com/wiki/Special:Unblock/' + m[3], 'unblock']
            };
        } else {
            nomatchlog.push({
                'Plaintext': plaintext
            });
            return;
        }
    });

    // Replace the wall of text with a table
    if (counter > 0) {
        $('#mw-log-deleterevision-submit ul').replaceWith( makeTableHTML(blocklog) );
        $('#blocklogtable').after( makeTableHTML(nomatchlog) );
    }
}
/* </pre> */