MediaWiki:FashionQuest.js

$(function() {

var eqClasses = ['Bard', 'Cleric', 'Druid', 'Enchanter', 'Magician', 'Monk', 'Necromancer', 'Paladin', 'Ranger', 'Rogue', 'Shadow Knight', 'Shaman', 'Warrior', 'Wizard'];

var armorSlots = ['Arms', 'Chest', 'Feet', 'Hands', 'Head', 'Legs', 'Wrist'];

// TODO: Get this like we get the colors, ie. by parsing fashionquest guide

// (that way if new styles are added they'll be added here)

var robeStyles = ['Crimson Robe of Alendine', 'Cryosilk Robe', 'Flowing Black Robe', 'Plain Robe', 'Robe of the Kedge', 'Robe of the Oracle', 'Shining Metallic Robes']

var fashionStyles = ['Cloth', 'Leather', 'Velious Leather 1', 'Velious Leather 2', 'Chain', 'Kunark Chain', 'Velious Chain 1', 'Velious Chain 2', 'Plate', 'Velious Plate 1', 'Velious Plate 2'];

/**

var extractColors = function(html) {

var colors = [];

var regex= /

var matched;

while(matched = regex.exec(html)) colors.push(matched[1]);

return colors;

};

/**

  • @returns a promise that evaluates to an object containing color categories,
  • by fetching the fashion quest guide and string-parsing it's HTML
  • (sloppy but it works).
  • /

var getColorCategories = function() {

return $.get('https://wiki.project1999.com/FashionQuest_Guide')

.then(function(html) {

return html

.split(/\/table/m)

// we split by table, but there were other tables we didn't care about,

// so filter through and find only the color ones

.filter(function(html) {

return html.includes('mw-headline') &&

html.includes('Category

})

.reduce(function(categories, html) {

var name = html.match('id=".*?">(.*?)')[1];

categories[name] = extractColors(html);

return categories;

}, {});

});

};

getColorCategories().then(function(colorCategories) {

var buildOptionsFromArray = function(arr, defaultText) {

return '' + arr

.flat(2)

.sort()

.map(function(value) {

return '';

}).join('\n');

};

var buildClassSelect = function() {

var options = buildOptionsFromArray(eqClasses, 'All');

return '';

};

var buildSlotSelect = function() {

var options = buildOptionsFromArray(armorSlots, 'All');

return '';

};

var buildStyleSelect = function() {

var options = buildOptionsFromArray(fashionStyles, 'All');

return '';

};

var buildRobeSelect = function() {

var options = buildOptionsFromArray(robeStyles, 'All');

return '';

};

var buildBaseColorSelect = function() {

var optionsHtml = buildOptionsFromArray(Object.keys(colorCategories), 'Any');

return '';

};

var buildSpecificColorSelect = function() {

var optionsHtml = buildOptionsFromArray(Object.values(colorCategories), 'Any');

return '';

};

$('#fashionQuestFinder').html(

'

'+

'

' +

'Basics' +

'

Class: ' + buildClassSelect() + '
' +

'

Armor Slot:' + buildSlotSelect() + '
' +

'

' +

'

' +

'Fashion Style' +

'

Specific Fashion Style:' + buildStyleSelect() + '
' +

'

' +

'

' +

'

' +

' Color' +

'

Search for base color or specific color (base is much slower as it has to check multiple specific colors; if you use it too often it can even slow down the whole wiki)
' +

'

Specific Color Style:' + buildSpecificColorSelect() + '
' +

'

Base Color Style:' + buildBaseColorSelect() + '
' +

'

' +

'' +

'

');

$('#slotSelect').change(function() {

var armorSlot = $('#slotSelect').val().trim();

$('#robeStyle').toggle(armorSlot.trim() === 'Chest');

});

var buildQuery = function() {

var categories = [];

var eqClass = $('#classSelect').val();

if (eqClass) categories.push(eqClass.trim() + '+Equipment');

var armorSlot = $('#slotSelect').val();

if (armorSlot) categories.push(armorSlot.trim());

if ($('[name="fashion"]:checked').val() === 'specific') {

var style = $('#styleSelect').val();

if (style) categories.push('Fashion: ' + style.trim());

}

if ($('[name="fashion"]:checked').val()

'robe' && armorSlot

'Chest') {

var robeStyle = $('#robeSelect').val();

if (robeStyle) categories.push('Fashion: ' + robeStyle.trim());

}

if ($('[name="color"]:checked').val() === 'specific') {

var color = $('#specificColorSelect').val();

if (color) categories.push('Fashion: ' + color.trim());

}

var query = '';

if (categories.length > 0) query += 'wpInCategory1=' + categories[0];

if (categories.length > 1) query += '&wpInCategory2=' + categories[1];

if (categories.length > 2) query += '&wpInCategory3=' + categories[2];

return query + '&limit=500';

};

var baseUrl = ' http://wiki.project1999.com/Special:MultiCategorySearch?';

var $search = $('#search').click(function(e) {

var query = buildQuery();

if (!query) return false;

location = baseUrl + query;

//$.get(baseUrl + query).then(function(html) {

// console.log(window.html = html);

//});

return false;

});

});

}); // Close of onReady call