Idle-Pixel Teams Storage Manager

Library for parsing teams storage data.

Från och med 2024-07-24. Se den senaste versionen.

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greatest.deepsurf.us/scripts/501360/1416180/Idle-Pixel%20Teams%20Storage%20Manager.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Idle-Pixel Teams Storage Manager
// @namespace    luxferre.dev
// @version      1.2.1
// @description  Library for parsing teams storage data.
// @author       Lux-Ferre
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// ==/UserScript==

(function() {
	if(window.TStore) {
		// already loaded
		return;
	}

	class TeamStore extends IdlePixelPlusPlugin {
		constructor() {
			super("teamstore", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            })
			this.store = {}
			this.item_list = []
			this.category_map = {}
			this.categories = {
				"brewing": [],
				"mining": [],
				"crafting": [],
				"farming": [],
				"gathering": [],
				"woodcutting": [],
				"cooking": [],
				"fishing": [],
				"combat": [],
				"other": []
			}
		}
		
		onLogin(){
			if (window.var_team_name == null){
				delete IdlePixelPlus.plugins.teamstore
				return
			}
			this.spawn_observer()
			Modals.clicksAddItemTeamStorage()
			IdlePixelPlus.sendMessage("TEAM_REFRESH_STORAGE")
		}
		
		onMessageReceived(message) {
			if(TStore.item_list.length === 0 && message.startsWith("TEAMS_TRADABLES_MODAL")){
				TStore.item_list = message.split("=")[1].split("~")
				TStore.create_categories()
			}
			if(message.startsWith("TEAMS_STORAGE_DATA")){
				this.parse_and_update(message.split("=")[1])
			}
		}
		
		spawn_observer(){
			const targetNode = document.getElementById("modal-teamstorage-select-item")

			const config = { attributes: true, childList: true, subtree: true }
			const callback = function(mutationsList, observer) {
				$("#modal-teamstorage-select-item").modal("hide")
				observer.disconnect()
			}
			
			const observer = new MutationObserver(callback);
			observer.observe(targetNode, config);
		}
				
		parse_and_update(storage_string){
			TStore.store = {}
			const data_array = storage_string.split("~")
			for (let i = 0; i<data_array.length - 1; i+=2) {
				TStore.store[data_array[i]] = data_array[i+1]
			}
		}
		
		create_categories(){
			const unsorted_items = new Set(this.item_list)
			const panel_list = ["brewing", "mining", "crafting", "farming", "gathering", "woodcutting", "cooking", "fishing", "combat"]
			
			panel_list.forEach(panel =>{
				$("itembox", $(`#panel-${panel}`)).each((index, obj)=>{
				    const item_name = $(obj).data("item")
					if(unsorted_items.has(item_name)){
						TStore.category_map[item_name] = panel
						TStore.categories[panel].push(item_name)
						unsorted_items.delete(item_name)
					}
				})
			})
			unsorted_items.forEach(item_name=>{
				TStore.category_map[item_name] = "other"
				TStore.categories.other.push(item_name)
			})
		}
	}

	// Add to window and init
	window.TStore = new TeamStore()
	IdlePixelPlus.registerPlugin(TStore);
})();