Greasy Fork

MH: Inventry History

Coming Soon

目前为 2021-02-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         MH: Inventry History
// @author       Warden Slayer - Warden Slayer#2302
// @namespace    https://greasyfork.org/en/users/227259-wardenslayer
// @version      0.2
// @description  Coming Soon
// @include      https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @include      http://www.mousehuntgame.com/*
// @include      https://www.mousehuntgame.com/*
// @grant        GM_setClipboard
// @grant        GM_xmlhttpRequest
// @connect      self
// @connect      script.google.com
// ==/UserScript==
$(document).ready(function() {
    addTouchPoint()
});


function addTouchPoint() {
    if ($('.invHix').length == 0) {
        const invPages = $('.inventory .torn_pages');
        //Inventory History Button
        const invHix = document.createElement('li');
        invHix.classList.add('invHix');
        const invHixBtn = document.createElement('a');
        invHixBtn.href = "#";
        invHixBtn.innerText = "Inventory History";
        invHixBtn.onclick = function () {
            getInvNow();
        };
        const icon = document.createElement("div");
        icon.className = "icon";
        invHixBtn.appendChild(icon);
        invHix.appendChild(invHixBtn);
        $(invHix).insertAfter(invPages);
    }
}

function getInvNow() {
    let userInv = [];
    userInv[0] = Date().toString().split(' G')[0];
    fetchInventory();
    userInv[1] = localStorage.getItem('ws.mh.invHx');
    //GM_setClipboard(userInv);
    publishResults(userInv)
}

function fetchInventory() {
    const itemsToGet = ['weapon','base', 'trinket', 'bait', 'skin', 'crafting_item','convertible', 'potion', 'stat','collectible']; //future proof this to allow for exclusions
    let itemsArray = [];
    let finalCSV = "";hg.utils.UserInventory.getItemsByClass(itemsToGet,true,function(data) {
        data.forEach(function(arrayItem, index) {
            itemsArray[index] = [arrayItem.name,arrayItem.quantity];
        })
        //hunter stats
        itemsArray.push(['Rank',user.title_name],['Rank Percent',user.title_percent_accurate],['Wisdom',user.title_wisdom],['Points',user.points],['Gold',user.gold]);
        //format to CSV
        localStorage.setItem('ws.mh.invHx', JSON.stringify(itemsArray.map(e => e.join("\u0001F443")).join("\u0001F443")))
    })
    return itemsArray
}

function publishResults(results){
    const debug = localStorage.getItem('ws.debug');
    //console.log(results)
    GM_xmlhttpRequest({
        method: "POST",
        url: 'https://script.google.com/macros/s/AKfycbyQI3g4_hMLfUdhmz00P1cKZtyk4YKVI-TAUn_OtFiY8LtS5nFuCNjH7A/exec',
        data: results,
        onload: function(response) {
            if (debug == true) {
                console.log('Inventory Submitted')
            }
        }
    });
}






//Unsused, here for record only
//===================================================================================================================
// function getHunterStats() {
//     let hunterStats = {};
//     hunterStats.points = user.points;
//     hunterStats.gold = user.gold;
//     hunterStats.wisdom = user.title_wisdom;
//     hunterStats.rank = user.title_name;
//     hunterStats.rankPercent = user.title_percent_accurate;
//     return hunterStats
// }

// function getHunts() {
//     let hunts = {};
//     hg.utils.User.getUserData([user.sn_user_id],['num_active_turns','num_passive_turns','num_linked_turns','num_total_turns','map_num_clues_found','map_num_maps_dusted'],function(data) {
//         hunts.hornCalls = data[0].num_active_turns;
//         hunts.trapChecks = data[0].num_passive_turns;
//         hunts.friendHunts = data[0].num_link_turns;
//         hunts.totalHunts = data[0].num_total_turns;
//         hunts.clues = data[0].map_num_clues_found;
//         hunts.dusts = data[0].map_num_maps_dusted;
//     })
//     return hunts
// }

// function getWeapons() {
//     let weaponArray = [];
//     hg.utils.UserInventory.getItemsByClass('weapon',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             weaponArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return weaponArray
// }

// function getBases() {
//     let baseArray = [];
//     hg.utils.UserInventory.getItemsByClass('base',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             baseArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return baseArray
// }


// function getCheese() {
//     let cheeseArray = [];
//     hg.utils.UserInventory.getItemsByClass('bait',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             cheeseArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return cheeseArray
// }

// function getCharms() {
//     let charmArray = [];
//     hg.utils.UserInventory.getItemsByClass('trinket',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             charmArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return charmArray
// }

// function getSkins() {
//     let skinArray = [];
//     hg.utils.UserInventory.getItemsByClass('skin',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             skinArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return skinArray
// }

// function getCraftingItems() {
//     let craftingArray = [];
//     hg.utils.UserInventory.getItemsByClass('crafting_item',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             craftingArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return craftingArray
// }

// function getConvertibles() {
//     let convertibleArray = [];
//     hg.utils.UserInventory.getItemsByClass('convertible',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             convertibleArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return convertibleArray
// }

// function getPotions() {
//     let potionArray = [];
//     hg.utils.UserInventory.getItemsByClass('potion',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             potionArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return potionArray
// }

// function getStatItems() {
//     let statItemArray = [];
//     hg.utils.UserInventory.getItemsByClass('stat',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             statItemArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return statItemArray
// }

// function getCollectibles() {
//     let collectibleArray = [];
//     hg.utils.UserInventory.getItemsByClass('collectible',true,function(data) {
//         data.forEach(function(arrayItem, index) {
//             collectibleArray[index] = [arrayItem.name,arrayItem.quantity]
//         })
//     })
//     return collectibleArray
// }