User:Ultimate Dark Carnage/wikia.js

$(document).ready(function{   var user_data_url = '/api/v1/User/Details?ids=' + wgUserName.replace(/\s/g, '+'),        user_avatar = ,        user_name = ,        user_link = '',        $toolbar = $('  '),        $user = $('  ');    $.ajax({ method: 'GET', dataType: 'json', url: '/api/v1/User/Details', data: { ids: wgUserName }   }).done(function(data){ var items = data.items[0]; user_avatar = items.avatar; user_name = items.name; user_link = items.url; });   function checkGroup(groups){        var _value = false;        if (groups.split(' ').length == 1){            if (wgUserGroups.indexOf(groups) > -1)                _value = true;            else                _value = false;        } else {            for (var i = 0; i < groups.split(' ').length; i++){                if (wgUserGroups.indexOf(groups.split(' ')[i]) > -1){                    _value = true;                    break;                }            }        }        return _value;    }    // User box    $user.find('> img').attr('src', user_avatar).addClass('toolbar-avatar avatar');    $user.find('> span').text(user_name).wrap('').addClass('toolbar-username');    // Toolbar    $toolbar.find('.toolbar-header').html($user);    $toolbar.find('.toolbar-navigation').html(function{ var toolbar_links = ''; function parseLinks(key, match){ var link = ' -1){                    txt = match.split('|');                    link += encodeURIComponent(txt[0].replace(temps_regex, function(k, m){                        return temps[m];                    })) + '">' + txt[1] + ''; } else { txt = match.replace(temps_regex, function(k, m){                       return temps[m];                    }); link += encodeURIComponent(txt) + '">' + txt + '';               }            }            return link;        }        $.ajax({            method: 'GET',            dataType: 'text',            url: mw.util.wikiScript('index'),            data: {                title: 'User:' + wgUserName + '/tools',                action: 'raw',                ctype: 'text/plain'            }        }).success(function(data){            var _data = data.split('\n'),                heading_regex = /\=\=(?:\s+)(.*)(?:\s+)\=\=/gi,                items_regex = /\*(?:\s+)(.*)/gi,                i = 0;            for (i < _data.length; i++){                if (heading_regex.test(_data[i])){                    if (i === 0)                        toolbar_links += _data[i].replace(heading_regex, '$1 ');                    else toolbar_links += _data[i].replace(heading_regex, '</ul><h2 class="toolbar-nav-heading">$1 <ul class="toolbar-items items">'); } else if (items_regex.test(_data[i])){ toolbar_links += _data[i].replace(items_regex, parseLinks); }           }            toolbar_links += '</ul>'; }).fail(function(error){ console.log(error); var _temp = '<h2 class="toolbar-nav-heading">[heading] <ul class="toolbar-items items">[items]</ul>', _temps = { 'page': wgPageName, 'user': wgUserName },               _data = { 'Actions': { 'Classic Editor': '[page]?action=edit', 'Visual Editor': '[page]?veaction=edit', 'History': '[page]?action=history', 'Rename': 'Special:MovePage/[page]' },                   'Contribute': { 'Add New Page': '', 'Wiki Activity': 'Special:WikiActivity', 'Admin Dashboard': { filterGroups: 'admin bureaucrat vstf helper staff', link: 'Special:AdminDashboard' },                       'Block': { filterGroups: 'admin bureaucrat vstf helper staff', link: 'Special:Block' }                   }                };            function _parse(key, temp){ var _i = _temps[temp]; return _i; }           for (var title in _data){ _temp = _temp.replace('[heading]', title); var items = _data[title], items_html = ''; for (var item in items){ var _item = items[item]; if (typeof _item == 'string') items_html += '<a href="/wiki/' + encodeURIComponent(_item.replace(/\[([a-zA-z]{1,})\]/, _parse)) + '">' + item + '</a></li>'; else if (typeof _item == 'object' && _item instanceof Object){ if (_item.filterGroups && checkGroup(_item.filterGroups)){ items_html += '<a href="/wiki/' + encodeURIComponent((_item.link || _item.href).replace(/\[([a-zA-z]{1,})\]/, _parse)) + '">' + item + '</a></li>'; }                   }                }                _temp = _temp.replace('[items]', items_html); }           toolbar_links += _temp; });       return toolbar_links;    }); $('.WikiaSiteWrapper').append($toolbar); });