Usuaria:Doodleplex/Sandbox 3

De Guild Wars 2 Wiki
Saltar a: navegación, buscar
Nota Nota: Other than Uploadtext and Edittools needing to be translated into Spanish, all you need to do is just copy and paste it into the box.
MediaWiki
Búsquedadeenlacesdechat.js - no idea if we need this still
This may be trial and error to get this to work. This is to ping items directly from the game and to go to the wiki page. Please check the grammer of the messages at the bottom. Also please remove "(Sayleth remove this text)" a the bottom as otherwise it wouldn't let me save the page(and the link won't work)
/** window.atob & window.btoa polyfill
 * WTFPLv2 – https://github.com/davidchambers/Base64.js
 */
!function(){function t(t){this.message=t}var e=this,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.prototype=new Error,t.prototype.name="InvalidCharacterError",e.btoa||(e.btoa=function(e){for(var o,n,a=0,i=r,c="";e.charAt(0|a)||(i="=",a%1);c+=i.charAt(63&o>>8-a%1*8)){if(n=e.charCodeAt(a+=.75),n>255)throw new t("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|n}return c}),e.atob||(e.atob=function(e){if(e=e.replace(/=+$/,""),e.length%4==1)throw new t("'atob' failed: The string to be decoded is not correctly encoded.");for(var o,n,a=0,i=0,c="";n=e.charAt(i++);~n&&(o=a%4?64*o+n:n,a++%4)?c+=String.fromCharCode(255&o>>(-2*a&6)):0)n=r.indexOf(n);return c})}();

/**
 * GW2W Chat link search
 *
 * Decodes Guild Wars 2 chat links in the search panel, and tries to find the
 * corresponding article using the SMW property `Has game id`.
 *
 * by Patrick Westerhoff [User:Poke]
 */
(function chatLinkSearch (window, document, $) {
    var searchBar = document.querySelector('#searchText input');
    if (!searchBar) {
        return;
    }
    var mwApi;
    function smwAskArticle (type, id, callback) {
        var apiData = { action: 'ask', query: '?Tiene nombre canónico|?Tiene contexto|limit=1|' };
        var query = '[[Has game id::' + id + ']]';
        if (type == 'objeto') {
            query += '[[Tiene contexto::Objeto]]';
        }
        else if (type == 'localización') {
            query += '[[Tiene contexto::Localización]]';
        }
        else if (type == 'habilidad') {
            query = query + '[[Tiene contexto::Habilidad]] OR ' + query + '[[Tiene contexto::Efecto]]';
        }
        else if (type == 'rasgo') {
            query += '[[Tiene contexto::Rasgo]]';
        }
        else if (type == 'receta') {
            query = '[[Tiene id de receta::' + id + ']]';
        }
        else if (type == 'diseño') {
            query += '[[Tiene contexto::Diseño]]';
        }
        else if (type == 'atuendo') {
            query += '[[Tiene contexto::Atuendo]]';
        }
        apiData.query += query;
        mwApi.get(apiData)
        .done(function (data) {
            if (data.query.results.length === 0) {
                callback(null);
            }
            else {
                for (var title in data.query.results) {
                    var canonicalName = data.query.results[title].printouts['Tiene nombre canónico'][0];
                    var gameContexts = data.query.results[title].printouts['Tiene contexto']
                    callback(title, canonicalName, gameContexts.length ? gameContexts[0] : null);
                    return;
                }
            }
        })
        .fail(function (data) {
            callback(null);
        });
    }

    function decodeChatLink (code) {
        var binary = window.atob(code);
        var octets = new Array(binary.length);
        for (var i = 0; i < binary.length; i++) {
            octets[i] = binary.charCodeAt(i);
        }
        return octets;
    }

    function display (code, listItem) {
        var data = decodeChatLink(code);
        var id = data[2] << 8 | data[1];
        var type;
        if (data[0] == 2) {
            type = 'item';
            id = data[3] << 8 | data[2];
            id = (data.length > 4 ? data[4] << 16 : 0) | id;
        }
        else if (data[0] == 4) {
            type = 'localización';
        }
        else if (data[0] == 6) {
            type = 'habilidad';
        }
        else if (data[0] == 7) {
            type = 'rasgo';
        }
        else if (data[0] == 9) {
            type = 'receta';
        }
        else if (data[0] == 10) {
            type = 'diseño';
        }
        else if (data[0] == 11) {
            type = 'atuendo';
        }
        else {
            var span = document.createElement('span');
            span.innerHTML = 'Este tipo de enlace de chat no se admite actualmente.';
            console.log('Unsupported chatlink. (TYPE '+data[0]+' / ID #'+id+')');
            $(span).fadeIn(1000).appendTo(listItem);
            return;
        }
        smwAskArticle(type, id, function (title, canonicalName, gameContext) {
            var span = document.createElement('span');
            if (title) {
                // If a single chatlink returns a single result, redirect to that page
                //  but don't redirect if it contains anything except a chatlink, e.g. interwiki prefix
                if ($('.mw-search-nonefound').length == 1 && searchBar.value.match(/^\[&[A-Za-z0-9+/=]+\]$/)) {
                    // Redirect only once for the current browsing session for that precise result
                    var key = 'searchredirected-' + searchBar.value;
                    try {
                        if (!sessionStorage.getItem(key)) {
                            sessionStorage.setItem(key, 'true');
                            document.location = '/index.php?title=' + encodeURIComponent(title.replace(/ /g, '_'));
                        }
                    } catch(e) {
                        // This might throw if session storage is disabled or unsupported. Just don't redirect if so.
                    }
                }
                var link = document.createElement('a');
                link.href = '/wiki/' + encodeURIComponent(title.replace(/ /g, '_'));
                link.title = title;
                link.innerHTML = canonicalName || title;
                span.appendChild(link);
                if (type == 'skill' && gameContext == 'Effect') {
                    type = 'effect';
                    }
                span.appendChild(document.createTextNode(' (' + type + ' #' + id + ')'));
            }
            else {
                var msg = 'No hay ningún artículo relacionado con este ID (' + id + ') todavía.';
                msg += ' Si sabes que ' + type + ' este vínculo de chat enlaza con, por favor, agregue el ID al artículo o cree si aún no existe.';
                span.innerHTML = msg;
            }
            $(span).fadeIn(1000).appendTo(listItem);
            $(listItem).attr('data-gameid', id)
        });
    }

    window.mw.loader.using('mediawiki.api', function() {
        mwApi = new window.mw.Api();

        // find chat links
        var ul = document.createElement('ul');
        var expr = /\[&([A-Za-z0-9+/]+=*)\]/g;
        var match;
        while ((match = expr.exec(searchBar.value))) {
            var li = document.createElement('li');
            li.innerHTML = '<tt>' + match[0] + '</tt>';
            ul.appendChild(li);
            display(match[1], li);
        }

        // display results
        if (ul.children.length) {
            var div = document.createElement('div');
            div.className = 'gw2w-chat-link-search';
            div.innerHTML = 'Los siguientes <a href(Sayleth remove this text)="/wiki/Enlace_de_chat" title="Enlace de chat">enlaces de chat</a> se incluyeron en tu consulta de búsqueda:';
            div.appendChild(ul);

            var topTable = document.getElementById('mw-search-top-table');
            $(div).hide().insertAfter(topTable).show('fast');
        }
    });
})(window, document, $);

In progress[editar]

Nothing at the moment