toriayl / Journal copier Chara

// ==UserScript==
// @name         Journal copier Chara
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       toriayl
// @match        http://game.granbluefantasy.jp/*
// @grant        GM_setClipboard
// ==/UserScript==
 
(function() {
    'use strict';
   
    function readSelector(aElement, aSelector) {
        var el = aElement.querySelector(aSelector);
        if (!el) return '';
        return el.innerHTML.trim();
    }
   
    var keyboardHandler = function(aEvent) {
        try {
            if (aEvent.altKey || aEvent.ctrlKey || aEvent.shiftKey)
                return;
            if (aEvent.key == 'j') {
                var temp;
                var i;
                var entry;
                aEvent.preventDefault();
                // Assuming this is a weapon journal entry for now
 
                var elWrapper = document.getElementsByClassName('cnt-detail-wrapper')[0];
                if (!elWrapper) throw new Error('Unable to find wrapper.');
               
                var elImage = elWrapper.querySelector('div.prt-image img.img-element');
                if (!elImage) throw new Error('Unable to main image.');
                var dataImageUrl = elImage.src;
                console.log(dataImageUrl);
                var dataVA = readSelector(elWrapper, 'div.txt-acter-name');
                console.log(dataVA);
                var dataImageNumber = dataImageUrl.match(/\/npc\/[a-z]\/(.+)\_01\./)[1];
                console.log(dataImageNumber);
               
                var elTitle = elWrapper.querySelector('div.prt-scroll-brown div.prt-scroll-title');
                if (!elTitle) throw new Error('Unable to title div.');
               
                var dataName = readSelector(elTitle, 'span.txt-item-name');
                console.log(dataName);
                var dataTitle = readSelector(elTitle, 'div.txt-evo-name');
                console.log(dataTitle);
                var dataRarity = 'N';
                for (i = 0; i < elTitle.classList.length; i++) {
                    switch (elTitle.classList.item(i)) {
                        case 'prt-rarity-2-large': dataRarity = 'R'; break;
                        case 'prt-rarity-3-large': dataRarity = 'SR'; break;
                        case 'prt-rarity-4-large': dataRarity = 'SSR'; break;
                    }
                }
                console.log(dataRarity);
               
                var elDetailMain = elWrapper.querySelector('div.prt-scroll-brown div.prt-detail-main');
                var dataDescription = readSelector(elWrapper, 'div.prt-scroll-brown div.prt-flavor');
                console.log(dataDescription);
               
                var elDetailMainList = elDetailMain.querySelector('div.prt-icon').getElementsByClassName('txt-spec-title');
                var dataElement = '';
                var dataMaxLvl = '';
                var dataStyle = '';
		var dataType = '';
                for (i = 0; i < elDetailMainList.length; i++) {
                    entry = elDetailMainList.item(i);
                    switch (entry.innerHTML) {
                        case 'Element':
                            switch (entry.nextElementSibling.className) {
                                case 'ico-type1': dataElement = 'Fire'; break;
                                case 'ico-type2': dataElement = 'Water'; break;
                                case 'ico-type3': dataElement = 'Earth'; break;
                                case 'ico-type4': dataElement = 'Wind'; break;
                                case 'ico-type5': dataElement = 'Light'; break;
                                case 'ico-type6': dataElement = 'Dark'; break;
                            }
                            break;
                        case 'Type':
                            switch (entry.nextElementSibling.className) {
                                case 'ico-chara-race1': dataType = 'Human'; break;
                                case 'ico-chara-race2': dataType = 'Erune'; break;
                                case 'ico-chara-race3': dataType = 'Draph'; break;
                                case 'ico-chara-race4': dataType = 'Harvin'; break;
                                case 'ico-chara-race5': dataType = 'None'; break;
                                case 'ico-chara-race6': dataType = 'Primal'; break;
                            }
                            break;
                        case 'Lvl':
                            dataMaxLvl = entry.nextElementSibling.innerHTML.match(/MAX\s([0-9]+)/)[1];
                        case 'Style':
                            switch (entry.nextElementSibling.className) {
                                case 'ico-chara-type1': dataStyle = 'Balanced'; break;
                                case 'ico-chara-type2': dataStyle = 'Attack'; break;
                                case 'ico-chara-type3': dataStyle = 'Defense'; break;
                                case 'ico-chara-type4': dataStyle = 'Heal'; break;
                                case 'ico-chara-type5': dataStyle = 'Special'; break;
                            }
                            break;
                    }
                }
                console.log(dataElement);
                console.log(dataType);
                console.log(dataMaxLvl);
                console.log(dataStyle);
               
                var dataLvlWhiteHP = elDetailMain.querySelector('div.prt-hp div.prt-min-hp div.txt-hp-value').attributes.getNamedItem('title').value;
                console.log(dataLvlWhiteHP);
                var dataLvlYellowHP = elDetailMain.querySelector('div.prt-hp div.prt-max-hp div.txt-hp-value').attributes.getNamedItem('title').value;
                console.log(dataLvlYellowHP);
                var dataLvlWhiteATK = elDetailMain.querySelector('div.prt-attack div.prt-min-atk div.txt-atk-value').attributes.getNamedItem('title').value;
                console.log(dataLvlWhiteATK);
                var dataLvlYellowATK = elDetailMain.querySelector('div.prt-attack div.prt-max-atk div.txt-atk-value').attributes.getNamedItem('title').value;
                console.log(dataLvlYellowATK);
               
                var elSkillsBox = elWrapper.querySelector('div.prt-scroll-brown div.prt-skills-box');
                var elSpecialBox = elSkillsBox.querySelector('div.prt-detail-special div.prt-box');
           	var elActionBox = elSkillsBox.querySelector('div.prt-detail-action div.prt-box');
           	var elSupportBox = elSkillsBox.querySelector('div.prt-detail-support div.prt-box');
               
                var dataSpecialName = readSelector(elSkillsBox, 'div.name-m');
                console.log(dataSpecialName);
                var dataSpecialDescription = readSelector(elSkillsBox, 'div.comment-m');
                console.log(dataSpecialDescription);
                var dataSpecialIcon = elSpecialBox.firstElementChild.className.match(/ico\-([a-z0-9_\-]+)/)[1];
                console.log(dataSpecialIcon);
               
                var elSkillsBoxList = elSkillsBox.querySelector('div.prt-detail-action').getElementsByClassName('prt-box');
                var dataSkills = '';
                for (i = 0; i < elSkillsBoxList.length; i++) {
                    entry = elSkillsBoxList.item(i);
                    var dataSkillName = readSelector(entry, 'div.name-m');
                    console.log(dataSkillName);
                    var dataSkillDescription = readSelector(entry, 'div.comment-m');
                    console.log(dataSkillDescription);
                    var dataSkillIcon = entry.firstElementChild.className.match(/ico\-([a-z0-9_\-]+)/)[1];
                    console.log(dataSkillIcon);
                    var cd = entry.querySelector('div.txt-recast');
                    var cdt = cd.innerHTML.match(/Cooldown\: ([a-z0-9_\-]+)/)[1];
                    var dur = entry.querySelector('div.txt-duration');
                    var dataSkillDuration='';
                    if (dur) {var dataSkillDuration=dur.firstElementChild.innerHTML;}
                    console.log(dataSkillDuration);
                    dataSkills += dataSkillName + "\t" + dataSkillDescription + "\t" + dataSkillIcon + "\t" + cdt + "\t" + dataSkillDuration + "\t" ;
                }
               
                var elSupportBoxList = elSkillsBox.querySelector('div.prt-detail-support').getElementsByClassName('prt-box');
                var dataSupport = '';
                for (i = 0; i < elSupportBoxList.length; i++) {
                    entry = elSupportBoxList.item(i);
                var dataSupportName = readSelector(entry, 'div.name-m');
                console.log(dataSupportName);
                var dataSupportDescription = readSelector(entry, 'div.comment-m');
                console.log(dataSupportDescription);
                var dataSupportIcon = entry.firstElementChild.className.match(/ico\-([a-z0-9_\-]+)/)[1];
                console.log(dataSupportIcon);
                    dataSupport += dataSupportName + "\t" + dataSupportDescription + "\t" + dataSupportIcon + "\t";
                }

 
                GM_setClipboard(
                    dataName + "\t" +
                    dataTitle + "\t" +
                    dataType + "\t" +
                    dataRarity + "\t" +
                    dataVA + "\t" +
                    dataImageUrl + "\t" +
                    dataImageNumber + "\t" +
                    dataDescription + "\t" +
                    dataElement + "\t" +
                    dataMaxLvl + "\t" +
                    dataStyle + "\t" +
                    dataLvlWhiteHP + "\t" +
                    dataLvlYellowHP + "\t" +
                    dataLvlWhiteATK + "\t" +
                    dataLvlYellowATK + "\t" +
                    dataSpecialName + "\t" +
                    dataSpecialIcon + "\t" +
                    dataSpecialDescription + "\t" +
                    dataSkills +
                    dataSupport
                );
 
            }
        } catch (e) {
            alert(e.message);
        }
    };
   
    window.addEventListener('keydown', keyboardHandler, false);
})();