Dressing Room

Auto create item lists from wowhead.com comparisons, export dressing room sets to WoW Model Viewer

目前為 2016-03-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Dressing Room
// @description    Auto create item lists  from wowhead.com comparisons, export dressing room sets to WoW Model Viewer
// @namespace      http://mogboutique.tumblr.com/
// @author         http://mogboutique.tumblr.com/
// @include        http://*.wowhead.com/dressing-room*
// @version        0.0.9
// @grant          none
// ==/UserScript==


$('head').append('<style type="text/css" id="wmv_style">.dressing-room-controls-block.block-bg{display:none;}</style>');

$('#main-precontents').after('<h2 class="heading-size-3" style="display:inline-block;">Paste MogIt links and WoWhead comparisons here</h2><a id="error_text" style="font-size:12px;margin-left:10px;margin-left:20px;color:red;" href="javascript:void(0);"></a><a style="font-size:12px;margin-left:10px;" href="https://greasyfork.org/en/scripts/17882-dressing-room">Update Script</a><div style="clear:both;"></div><input id="comp_src" style="height:25px;border:1px solid gray;color:gray;background:rgba(255,255,255,.05);width:90%;"></input><button id="comp_click">Import</button>');


$('div.dressing-room-controls-block').after('<div id="wmv_pad" style="margin-top:30px;" ><a id="wmv_init" class="fa" href="javascript:void(0);" style="text-align:center;display:block;border:1px solid;padding:8px;">WoW Model Viewer Export</a><a id="download_file" download="MyCharacter.chr" style="display:none;" href="javascript:void:(0);"></a><a id="code_file" style="display:none;" target="File Code" href="javascript:void:(0);"></a><div class="text_block" style="margin-top:10px;padding:10px;font-size:12px;">For users of <a href="https://wowmodelviewer.net/wordpress/?page_id=27">WoW Model Viewer</a>.<br>Pressing the button below will create a "character" file. In WoW Model Viewer, select Character menu -> Load Character -> Select your file. Current set will be imported. Alternatively, you can copy the raw code.<br>For updates/bugs check <a href="https://greasyfork.org/en/scripts/17882-dressing-room">this link.</a><center><button class="generate_code" style="margin: 7px 0;">Download "Character" File</button><br /><a style="color:red;font-weight:bold;" id="show_code" href="javascript:void(0);">Show code</a></center><textarea id="wmv_export" style="width:90%;height:50px;font-size:10px;background:white;display:none;"></textarea></div></div>');




var my_character = {
    equipment: {
        1: {},
        2: {},
        3: {},
        4: {},
        5: {},
        6: {},
        7: {},
        8: {},
        9: {},
        10: {},
        11: {},
        12: {},
        13: {}
    },
    settings: {
        race: 1,
        gender: 1,
        "class": 5,
        specialization: 0,
        level: 100,
        skincolor: 0,
        hairstyle: 0,
        haircolor: 0,
        facetype: 0,
        features: 0,
        blindfolds: 0,
        hornstyle: 0,
        tattoos: 0,
        mount: 0,
        artifactAppearanceMod: 0
    }
};



var displaySlot = {
    //Head
    1: 1,
    //Shoulders
    3: 2,
    //Cloak
    16: 3,
    //Chest
    5: 4,
    //Shirt
    4: 5,
    //Tabard
    19: 6,
    //Wrists
    9: 7,
    //Hands
    10: 8,
    //Waist
    6: 9,
    //Legs
    7: 10,
    //Feet
    8: 11,
    //Ranged
    15: 12,
    //1-Hand 
    13: 12,
    //2-Hand
    17: 12,
    //Shield
    14: 13,
    //Off-Hand
    23: 13
};


var equipmentOrderToCharacterSlot = {
    1: 1,
    2: 3,
    3: 15,
    4: 5,
    5: 4,
    6: 19,
    7: 9,
    8: 10,
    9: 6,
    10: 7,
    11: 8,
    12: 16,
    13: 17
};




var summary = null;

var bonuses = {};

$('#comp_click').click(function() {

    $('#error_text').text('');

    var src = $('#comp_src').val();

    if (src.match(/wowhead\.com\/compare/)) {
        loadData("/compare?" + src.match(/items=(.+)/));
    } else {
        $('#error_text').text('Wrong URL');
    }


});

function loadData(src) {

    $.get(src, function(data) {
        g_match = data.match(/(g_items.add.+)/g);
        s_match = data.match(/new Summary(\(.+)/);



        if (s_match.length > 1) {
            var s = eval(s_match[1]);
            summary = s.groups[0];
        }


        for (var p in g_match) {
            eval(g_match[p]);
        }

        for (var i = 0; i < summary.length; i++) {

            bonuses[summary[i][0]] = 0;
            if (summary[i][10]) bonuses[summary[i][0]] = summary[i][10];

        }


        comparison();


    });

}




function comparison() {

    for (var e in my_character.equipment)
        my_character.equipment[e] = {};

    for (var propt in bonuses) {

        if (g_items[propt].jsonequip) {

            var dslot = displaySlot[g_items[propt].jsonequip.slot];

            if (dslot) {

                if (dslot == 12)
                    if (displaySlot[my_character.equipment[12].charSlot] == 12)
                        if (!my_character.equipment[13].itemId) {
                            for (var p in my_character.equipment[12])
                                my_character.equipment[13][p] = my_character.equipment[12][p];
                        }

                my_character.equipment[dslot].itemId = g_items[propt].jsonequip.id;
                my_character.equipment[dslot].charSlot = g_items[propt].jsonequip.slot;
                my_character.equipment[dslot].itemBonus = bonuses[propt];

            }

        }


    }
    if (g_items) {


        var last = localStorage.getItem("lastViewedModel");
        var model = eval(last);
        var settings = model[model.length - 1];
        my_character.settings = settings;




        DressingRoom.updateFromHash(my_character);
        bonuses = {};
        updateView();




    }

}




function updateView() {

    var items = [];

    for (var p in my_character.equipment) {
        var item = {};
        item.artifactAppearanceMod = 0;
        item.raw = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        item.raw[0] = equipmentOrderToCharacterSlot[p];

        if (my_character.equipment[p].charSlot && my_character.equipment[p].itemId) {



            item.raw[1] = my_character.equipment[p].itemId;
            item.raw[11] = my_character.equipment[p].itemBonus;


        }

        items.push(item);
    }



    var log = g_paperdolls['dressing-room-paperdoll'].updateSlots(items);



}




/***************WoW Model Viewer Export*****************/




$('button.generate_code').click(function() {
    observeChanges();
    exportWMV();

    $("#download_file")[0].click();

});




$('#show_code').click(function() {
    observeChanges();
    exportWMV();
 
    window.open($("#code_file").attr('href'), 'Code File', 'height=500,width=500');

});




var ishd = [
    'human',
    'draenei',
    'dwarf',
    'orc',
    'gnome',
    'nightelf',
    'bloodelf',
    'troll',
    'undead'
];


var filename = "MyCharacter";




function exportWMV() {




    //Head
    $('div.paperdoll-left > div.iconmedium:first-child > a').attr('slot', 0);
    //Shoulders
    $('div.paperdoll-left > div.iconmedium:nth-child(3) > a').attr('slot', 1);
    //Cloak
    $('div.paperdoll-left > div.iconmedium:nth-child(4) > a').attr('slot', 11);
    //Chest
    $('div.paperdoll-left > div.iconmedium:nth-child(5) > a').attr('slot', 6);
    //Shirt
    $('div.paperdoll-left > div.iconmedium:nth-child(6) > a').attr('slot', 4);
    //Tabard
    $('div.paperdoll-left > div.iconmedium:nth-child(7) > a').attr('slot', 12);
    //Wrist
    $('div.paperdoll-left > div.iconmedium:nth-child(8) > a').attr('slot', 7);

    //Main Hand
    $('div.paperdoll-bottom > div.iconmedium:first-child > a').attr('slot', 9);
    //Off Hand
    $('div.paperdoll-bottom > div.iconmedium:nth-child(2)> a').attr('slot', 10);

    //Hands
    $('div.paperdoll-right > div.iconmedium:first-child > a').attr('slot', 8);
    //Waist
    $('div.paperdoll-right > div.iconmedium:nth-child(2)> a').attr('slot', 3);
    //legs
    $('div.paperdoll-right > div.iconmedium:nth-child(3)> a').attr('slot', 5);
    //feet
    $('div.paperdoll-right > div.iconmedium:nth-child(4)> a').attr('slot', 2);


    var last = localStorage.getItem("lastViewedModel");
    var model = eval(last);




    var settings = model[model.length - 1];
    var race = g_file_races[settings.race];
    var gender = g_file_genders[settings.gender];

    var classs = settings.class;

    var eyeGlow = 1;
    if (settings.class == 6)
        eyeGlow = 2;



    var hd = "";
    if (ishd.indexOf(race) > -1) hd = "_hd";
    if (localStorage.getItem('paperdoll-hd') == "false") hd = "";




    var text = '<?xml version="1.0" encoding="UTF-8"?>\n' +
        ' <SavedCharacter version="1.0">\n' +
        '  <model>\n' +
        '   <file name="character\\' + race + '\\' + gender + '\\' + race + gender + hd + '.m2"/>\n' +
        '   <CharDetails>\n' +
        '     <skinColor value="' + settings.skincolor + '"/>\n' +
        '     <faceType value="' + settings.facetype + '"/>\n' +
        '     <hairColor value="' + settings.haircolor + '"/>\n' +
        '     <hairColor value="' + settings.haircolor + '"/>\n' +
        '     <hairStyle value="' + settings.hairstyle + '"/>\n' +
        '     <facialHair value="' + settings.features + '"/>\n' +
        '     <eyeGlowType value="' + eyeGlow + '"/>\n' +
        '     <showUnderwear value="0"/>\n' +
        '     <showEars value="1"/>\n' +
        '     <showHair value="1"/>\n' +
        '     <showFacialHair value="1"/>\n' +
        '     <showFeet value="1"/>\n' +
        '   </CharDetails>\n' +
        ' </model>\n' +
        '<equipment>\n';



    var e = {};

    $('div#dressing-room-paperdoll a[slot]').each(function() {

        var href = $(this).attr('href');

        if (href.match(/item=(\d+)/)) {
            e[href.match(/item=(\d+)/)[1]] = {};
            e[href.match(/item=(\d+)/)[1]].slot = $(this).attr('slot');

            if (href.match(/bonus=(\d+)/))
                e[href.match(/item=(\d+)/)[1]].bonus = href.match(/bonus=(\d+)/)[1];
        }


    });



    for (var p in e) {

        try {

            if (g_items[p].jsonequip) {


                var displayId = g_items[p].jsonequip.displayid;
				
				


                if (e[p].bonus) {
                    displayId = g_items.getAppearance(p, [e[p].bonus])[0];
                }

              

                var id = p;

                var level = g_items[p].jsonequip.level;

                if (g_items[p].json)
                    level = g_items[p].json.level;


                var slot = e[p].slot;


                if (slot == 6)
                    if (g_items[p].name_enus)
                        filename = g_items[p].name_enus;



                if (!displayId) displayId = -1;
                if (!id) id = -1;
                if (!level) level = 0;
                if (!slot) slot = -1;



                var a = g_items[p].jsonequip.appearances;



                var ar = [];
                var lvl = 0;

                for (var o in a)
                    ar.push(a[o]);

                level = 0;

                if (ar.length == 4) {
                    if (e[p].bonus == 566)
                        level = 2;
                    else if (e[p].bonus == 567)
                        level = 3;
                }
				else if (ar.length == 3) {
                    if (e[p].bonus == 566)
                        level = 1;
                    else if (e[p].bonus == 567)
                        level = 2;
                }



                text = text + '   <item>\n' +
                    '      <slot value="' + slot + '"/>\n' +
                    '      <id value="' + id + '"/>\n' +
                    '      <displayId value="' + displayId + '"/>\n' +
                    '      <level value="' + level + '"/>\n' +
                    '   </item>\n';
            }

        } //try
        catch (e) {

            var error = "Item Error";

        }

    } //for



    text = text + '  </equipment>\n' +
        ' </SavedCharacter>\n';

    $('#wmv_export').val(text);


    var file_uri = 'data:text/xml;charset=utf-8,' + encodeURIComponent(text);

    $("#download_file").attr('href', file_uri);
    $("#code_file").attr('href', file_uri);




    filename = filename.replace(/[^ \w]+/g, '_');




    $("#download_file").attr('download', filename + ".chr");


    filename = "My Character";



    return file_uri;

}



var observer = null;
var config = {
    attributes: true,
    childList: true,
    characterData: true,
    subtree: true
};



function observeChanges() {


    var target = $('table.listview-mode-default tbody.clickable')[0];



    if (!observer) {
        observer = new MutationObserver(function(mutations) {

            exportWMV();
        });

        observer.observe(target, config);

    }

}