Ted's market UI

Ted's Diamond Hunt 2 custom market user interface

目前為 2017-04-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Ted's market UI
// @namespace    Ted's market UI
// @version      1.25
// @description  Ted's Diamond Hunt 2 custom market user interface
// @author       ted120
// @match        http://*.diamondhunt.co/game.php
// @match        https://*.diamondhunt.co/game.php
// @run-at       document-idle
// @grant        none
// ==/UserScript==

$(document).ready(function () {

	// nothing needs to be changed in code

	/* TODO
	make shit look better
    */

	var debugToConsole = false;

	// big thanks to John / WhoIsYou / CodeCretin (author: Dh2QoL)
	// viewing his code helped me understand a lot about localStorage
	const defaultSettings = {
		notEnoughCoinsOpacity : {
			text : "Display unaffordable market items as transparent?",
			value : true
		},
		showMaxCanBuy : {
			text : "Display maximum quantity purchasable when cannot afford to buy all?",
			value : true
		},
		smallMarketImages : {
			text : "Resize market images smaller?",
			value : true
		},
		itemTooltips : {
			text : "Display item tooltips? (shows after searching market for all items)",
			value : true
		},
		autoUndercut : {
			text : "Smart autofill price to undercut when posting an item?",
			value : true
		},
		marketSlotsCustomUi : {
			text : "Display custom market box? (cooldown, refresh all button)",
			value : true
		},
		hideItemList : [
		],
		myItemList : [
		],
		colorMinPrice : {
			text : "Background color of min priced items",
			bgcolor : "#90ee90", //lightgreen
		},
		colorNextLowestToMinPrice : {
			text : "Background color of next lowest offer to min priced items",
			bgcolor : "#ffcc66", //lightorange
		},
		colorSingleItems : {
			text : "Background color of single items",
			bgcolor : "#ffff66", //lightyellow
		},
		colorMyListedLowest : {
			text : "Background color of your listed item at lowest price",
			bgcolor : "#bffffd", //lightblue
		},
		colorMyListedLowestCanRaisePrice : {
			text : "Background color of your listed item at lowest price when you undercut too much",
			bgcolor : "#6ffffd", //blue
		},
		colorMyListedNotLowest : {
			text : "Background color of your listed item not at lowest price",
			bgcolor : "#ffcccc", //lighterred
		},
		colorLowestForMyListed : {
			text : "Background color of lowest offer for an item you have listed",
			bgcolor : "#ff7878", //lightred
		},
		colorMyItemList : {
			text : "Background color of items that match myItemList",
			bgcolor : "#ff99ff", //lightpink
		},
		colorMyItemListNextLowest : {
			text : "Background color of next lowest offer when an item matches myItemList",
			bgcolor : "#ffccff", //pink
		},
	};

	if (typeof(localStorage.tedSettings) == "undefined") {
		localStorage.tedSettings = JSON.stringify(defaultSettings);
		console.log("localstorage.tedSettings not found, creating based on defaultSettings");
		console.log(localStorage.tedSettings);
	}
	var tedStoredSettings = JSON.parse(localStorage.getItem("tedSettings"));
	for (var key in defaultSettings) {
		if (!defaultSettings.hasOwnProperty(key)) continue;
		/*var obj = defaultSettings[key];
		for (var prop in obj) {
			if (!obj.hasOwnProperty(prop)) continue;
			//
		}*/

		if (tedStoredSettings[key] === undefined) {
			//add from default
			console.log("undefined "+key);
			tedStoredSettings[key] = defaultSettings[key];
			localStorage.tedSettings = JSON.stringify(tedStoredSettings);
			console.log("Key not found, added from default: "+tedStoredSettings[key]);
		} else if (debugToConsole) { console.log("matched "+key); }

		if (tedStoredSettings[key].text && tedStoredSettings[key].text != defaultSettings[key].text) {
			tedStoredSettings[key].text = defaultSettings[key].text;
		}
	}
	var notEnoughCoinsOpacity, showMaxCanBuy;
	var smallMarketImages, marketImageSize = 30; //pixels, default:50, suggested: 30-40
	var itemTooltips;
	var autoUndercut, undercutBy = 2, matchLowestPriceAt = 20;
	var marketSlotsCustomUi;
	var hideItemList, myItemList;
	var colorMinPrice, colorNextLowestToMinPrice, colorSingleItems, colorMyListedLowest, colorMyListedLowestCanRaisePrice, colorMyListedNotLowest, colorLowestForMyListed, colorMyItemList, colorMyItemListNextLowest;

	function updateVariables() {
		tedStoredSettings.hideItemList.sort();
		tedStoredSettings.myItemList.sort();
		localStorage.tedSettings = JSON.stringify(tedStoredSettings);
		notEnoughCoinsOpacity = tedStoredSettings.notEnoughCoinsOpacity.value;
		showMaxCanBuy = tedStoredSettings.showMaxCanBuy.value;
		smallMarketImages = tedStoredSettings.smallMarketImages.value;
		marketImageSize = 30; //pixels, default:50, suggested: 30-40
		itemTooltips = tedStoredSettings.itemTooltips.value;
		autoUndercut = tedStoredSettings.autoUndercut.value;
		marketSlotsCustomUi = tedStoredSettings.marketSlotsCustomUi.value;
		hideItemList = tedStoredSettings.hideItemList;
		myItemList = tedStoredSettings.myItemList;
		undercutBy = 2;
		matchLowestPriceAt = 20;
		colorMinPrice = tedStoredSettings.colorMinPrice.bgcolor;
		colorNextLowestToMinPrice = tedStoredSettings.colorNextLowestToMinPrice.bgcolor;
		colorSingleItems = tedStoredSettings.colorSingleItems.bgcolor;
		colorMyListedLowest = tedStoredSettings.colorMyListedLowest.bgcolor;
		colorMyListedLowestCanRaisePrice = tedStoredSettings.colorMyListedLowestCanRaisePrice.bgcolor;
		colorMyListedNotLowest = tedStoredSettings.colorMyListedNotLowest.bgcolor;
		colorLowestForMyListed = tedStoredSettings.colorLowestForMyListed.bgcolor;
		colorMyItemList = tedStoredSettings.colorMyItemList.bgcolor;
		colorMyItemListNextLowest = tedStoredSettings.colorMyItemListNextLowest.bgcolor;
	}
	updateVariables();

	var arrMarketItems = [];
	var arrMarketSlots = [[0, 0]]; //updateMarketSlots()
	var marketInterval;
	var marketOn = true;
	var quickCalcOn = true, quickCalcElement = document.createElement('div');
	var defaultUndercutOnce;
	var zMarket = document.createElement("div");
	var zMap = document.createElement("span");
	zMap.setAttribute("id","mapSpan");
	zMap.setAttribute("style","color:gold");
	zMap.innerHTML = " You have an incomplete map!";
	var tickStart = new Date().getTime();
	var tickEnd = new Date().getTime();
	var tickTime = tickEnd - tickStart;
	var tickCheck = 0;
	var marketCancelCooldownElement;
	var myItemListAddName,myItemListAddPrice;
	var arrSortItemsList = [
		"Stardust",
		"Blood Diamond","Diamond","Emerald","Ruby","Sapphire",
		"Empty Chisel",
		"Blue Axe Orb","Blue Rake Orb","Blue Hammer Orb","Blue Pickaxe Orb","Blue Chisel Orb","Blue Fishing Rod Orb","Blue Oil Pipe Orb","Blue Shovel Orb",
		"Essence",
		"Skeleton Sword","Skeleton Shield","Bone Amulet",
		"Iron Dagger","Stinger",
		"Stardust Logs","Maple Logs","Willow Logs","Oak Logs","Logs",
		"Bones","Ashes",
		"Stardust Tree Seeds","Maple Tree Seeds","Willow Tree Seeds","Oak Tree Seeds","Tree Seeds",
		"Striped Crystal Leaf Seeds","Crystal Leaf Seeds","Striped Gold Leaf Seeds","Gold Leaf Seeds","Blewit Mushroom Seeds","Red Mushroom Seeds","Lime Leaf Seeds","Green Leaf Seeds","Dotted Green Leaf Seeds","Snapegrass Seeds",
		"Striped Crystal Leaf","Crystal Leaf","Striped Gold Leaf","Gold Leaf","Blewit Mushroom","Red Mushroom","Strange Leaf","Lime Leaf","Green Leaf","Dotted Green Leaf","Snapegrass",
		"Rainbowfish","Whale","Shark","Eel","Swordfish","Lobster","Tuna","Salmon","Sardine","Shrimp",
		"Raw Rainbowfish","Raw Whale","Raw Shark","Raw Eel","Raw Swordfish","Raw Lobster","Raw Tuna","Raw Salmon","Raw Sardine","Raw Shrimp","Wheat",
		"Runite Bar","Promethium Bar","Gold Bar","Silver Bar","Iron Bar","Bronze Bar","Glass",
		"Promethium","Marble","Quartz","Sand","Stone",
		"Bear Fur","Bat Skin","Snake Skin"
	];

	function drawButtons() {
		zMarket = document.createElement("div");
		zMarket.setAttribute("id","zMarketId");
		zMarket.innerHTML = "<button id='marketButton' type='button'>Ted's market UI = "+marketOn+"</button><button id='quickCalcButton' type='button'>quickCalc = "+quickCalcOn+"</button>";
		document.getElementById("game-div").appendChild(zMarket);
		document.getElementById("zMarketId").appendChild(zMap);
		document.getElementById("marketButton").addEventListener(
			"click", marketButtonClickAction, false
		);
		document.getElementById("quickCalcButton").addEventListener(
			"click", quickCalcButtonClickAction, false
		);
	}
	function removeButtons() {
		document.getElementById("game-div").removeChild(zMarket);
	}
	function buttonMain() {
		removeButtons();
		drawButtons();
	}
	function nextTick() {
		if (playtime > tickCheck) {
			tickCheck = playtime;
			tickEnd = new Date().getTime();
			tickTime = tickEnd - tickStart;
			if (debugToConsole) { console.log("Tick time: "+ tickTime); }
			tickStart = new Date().getTime();
			return true;
		} else return false;
	}
	function isInArray(array, search)
	{
		return array.indexOf(search) >= 0;
	}
	function itemNameFix(string) { // market style name to var style name; Bat Skin > batSkin
		var a = string.replace(/\s/g, "");
		return a.charAt(0).toLowerCase() + a.slice(1);
	}
	function numberWithCommas(x) {
		return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	}
	function tedMarketUiSettings() {
		var i,j;
		var arrSettingsTH = ["tedMarket Configuration (may require refresh)","Active"];
		var zSettingsTable = document.createElement("table");
		zSettingsTable.setAttribute("id","marketSettingsTable");
		zSettingsTable.setAttribute("style","width:40%;margin-top:3%;margin-bottom:3%;");
		zSettingsTable.setAttribute("class","table-style1");
		zSettingsTable.setAttribute("align", "center");
		var zSettingsTBody = document.createElement("tbody");
		zSettingsTBody.setAttribute("style","border-color:black");
		for (i = 0; i < 1; i++) {
			var zSettingsTHRow = document.createElement("tr");
			zSettingsTHRow.setAttribute("style","background-color:grey;color:black;border-color:grey");
			for (j = 0; j < 2; j++) {
				var zSettingsTH = document.createElement("th");
				var cellText = document.createTextNode(arrSettingsTH[j]);
				zSettingsTH.appendChild(cellText);
				zSettingsTHRow.appendChild(zSettingsTH);
			}
			zSettingsTBody.appendChild(zSettingsTHRow);
		}
		changeSetting = function(prop) {
			if (tedStoredSettings && tedStoredSettings[prop]) {
				if (tedStoredSettings[prop].value === true) {
					tedStoredSettings[prop].value = false;
					document.getElementById("celltick-"+prop).setAttribute("src","images/icons/x.png");
					updateVariables();
				} else if (tedStoredSettings[prop].value === false) {
					tedStoredSettings[prop].value = true;
					document.getElementById("celltick-"+prop).setAttribute("src","images/icons/check.png");
					updateVariables();
				} else if (prop == "hideItemList") {
					hideItemListModal.setAttribute("style","display:block;position:fixed;z-index:1;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);");
					while (hideItemListModalBody.firstChild) {
						hideItemListModalBody.removeChild(hideItemListModalBody.firstChild);
					}
					var hideItemListModalBodyText = document.createTextNode("hideItemList: Hides these items when searching all unless myItemList finds a match. Click to remove from hideItemList: ");
					hideItemListModalBody.append(hideItemListModalBodyText);
					hideItemListModalBody.innerHTML += "<br><br>";
					for (i = 0; i < tedStoredSettings.hideItemList.length; i++) {
						var hideItemListRemoveBtn = document.createElement("button");
						hideItemListRemoveBtn.setAttribute("id",tedStoredSettings.hideItemList[i]);
						hideItemListRemoveBtn.setAttribute("onclick","hideItemListRemove(this.id);changeSetting('hideItemList')");
						hideItemListRemoveBtn.append(tedStoredSettings.hideItemList[i]);
						hideItemListModalBody.append(hideItemListRemoveBtn);
					}
				} else if (prop == "myItemList") {
					myItemListModal.setAttribute("style","display:block;position:fixed;z-index:1;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);");
					while (myItemListModalBody.firstChild) {
						myItemListModalBody.removeChild(myItemListModalBody.firstChild);
					}
					var myItemListModalBodyNameInput = document.createElement("input");
					myItemListModalBodyNameInput.setAttribute("id","myItemListModalBodyNameInput");
					myItemListModalBodyNameInput.setAttribute("value",myItemListAddName);
					myItemListModalBody.append(myItemListModalBodyNameInput);
					var myItemListModalBodyPriceInput = document.createElement("input");
					myItemListModalBodyPriceInput.setAttribute("id","myItemListModalBodyPriceInput");
					myItemListModalBodyPriceInput.setAttribute("value",myItemListAddPrice);
					myItemListModalBody.append(myItemListModalBodyPriceInput);
					var myItemListAddBtn = document.createElement("button");
					myItemListAddBtn.setAttribute("id","myItemListAddBtn");
					myItemListAddBtn.setAttribute("onclick","myItemListAdd(myItemListModalBodyNameInput.value,myItemListModalBodyPriceInput.value);changeSetting('myItemList')");
					myItemListAddBtn.append("Add");
					myItemListModalBody.append(myItemListAddBtn);

					var myItemListModalBodyRemove = document.createElement("div");
					myItemListModalBodyRemove.innerHTML = "<br><br>";
					myItemListModalBody.append(myItemListModalBodyRemove);
					var myItemListModalBodyText = document.createTextNode("myItemList: Highlights these items pink when searching all if price is matched. Click to remove from myItemList: ");
					myItemListModalBody.append(myItemListModalBodyText);
					myItemListModalBody.innerHTML += "<br><br>";
					for (i = 0; i < tedStoredSettings.myItemList.length; i++) {
						var myItemListRemoveBtn = document.createElement("button");
						myItemListRemoveBtn.setAttribute("id",tedStoredSettings.myItemList[i][0]);
						myItemListRemoveBtn.setAttribute("onclick","myItemListRemove(this.id);changeSetting('myItemList')");
						myItemListRemoveBtn.append(tedStoredSettings.myItemList[i][0]+" @ <= "+numberWithCommas(tedStoredSettings.myItemList[i][1]));
						myItemListModalBody.append(myItemListRemoveBtn);
					}
				} else if (tedStoredSettings[prop].bgcolor) {
					document.getElementById("celltick-"+prop).style.backgroundColor = tedStoredSettings[prop].bgcolor;
					colorModal.setAttribute("style","display:block;position:fixed;z-index:1;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);");
					while (colorModalBody.firstChild) {
						colorModalBody.removeChild(colorModalBody.firstChild);
					}
					var colorModalBodyContent = document.createElement("div");
					colorModalBody.appendChild(colorModalBodyContent);
					colorModalBodyContent.innerHTML = "";
					KEYS.forEach((key) => {
						if (tedStoredSettings[key].bgcolor) {
							var colorModalInput = document.createElement("input");
							colorModalInput.setAttribute("id",key);
							colorModalInput.setAttribute("value",tedStoredSettings[key].bgcolor);
							colorModalInput.setAttribute("style","background-color:"+tedStoredSettings[key].bgcolor);
							colorModalBodyContent.appendChild(colorModalInput);
							var colorModalAddBtn = document.createElement("button");
							colorModalAddBtn.setAttribute("onclick","changeColor('"+key+"',document.getElementById('"+key+"').value);changeSetting('"+key+"')");
							colorModalAddBtn.append("Change");
							colorModalBodyContent.append(colorModalInput);
							colorModalBodyContent.append(colorModalAddBtn);
							colorModalBodyContent.append(tedStoredSettings[key].text);
							// tedStoredSettings[key].text+" = "+colorModalInput+" = "+colorModalBtn
							colorModalBodyContent.innerHTML += '<br><br>';
						}
					});
					var colorResetBtn = document.createElement("button");
					colorResetBtn.append("RESET COLORS");
					colorResetBtn.setAttribute("onclick","resetColors();changeSetting('colorMinPrice');");
					colorModalBodyContent.append(colorResetBtn);
				}
			}
		};
		const KEYS = Object.keys(tedStoredSettings);
		KEYS.forEach((key) => {
			var zSettingsRow = document.createElement("tr");
			var zSettingsCell = document.createElement("td");
			var cellText = document.createTextNode(tedStoredSettings[key].text);
			if (key == "hideItemList") {
				cellText = document.createTextNode("Click to open hideItemList");
			} else if (key == "myItemList") {
				cellText = document.createTextNode("Click to open myItemList");
			}
			var cellTick = document.createElement("div");
			if (tedStoredSettings[key].value === true) {
				cellTick = document.createElement("img");
				cellTick.setAttribute("src","images/icons/check.png");
				cellTick.setAttribute("style","width:20px;height:20px;vertical-align:bottom");
			} else if (tedStoredSettings[key].value === false) {
				cellTick = document.createElement("img");
				cellTick.setAttribute("src","images/icons/x.png");
				cellTick.setAttribute("style","width:20px;height:20px;vertical-align:bottom");
			} else if (tedStoredSettings[key].bgcolor) {
				cellTick.setAttribute("style","display:block;background-color:"+tedStoredSettings[key].bgcolor);
				cellTick.innerHTML = "+";
			}
			zSettingsRow.setAttribute("id","checkbox-"+key);
			zSettingsRow.setAttribute("onclick","changeSetting('"+key+"')");
			cellTick.setAttribute("id","celltick-"+key);
			zSettingsCell.appendChild(cellText);
			zSettingsRow.appendChild(zSettingsCell);
			zSettingsCell = document.createElement("td");
			zSettingsCell.appendChild(cellTick);
			zSettingsRow.appendChild(zSettingsCell);
			//}
			zSettingsRow.setAttribute("align","center");
			zSettingsTBody.appendChild(zSettingsRow);
		});
		zSettingsTable.appendChild(zSettingsTBody);
		document.getElementById("tab-container-profile").appendChild(zSettingsTable);

		var hideItemListModal = document.createElement("div");
		hideItemListModal.setAttribute("id","hideItemListModal");
		hideItemListModal.setAttribute("style","display:none");
		var hideItemListModalBody = document.createElement("div");
		hideItemListModalBody.setAttribute("id","hideItemListModalBody");
		hideItemListModalBody.setAttribute("style","position:fixed;bottom:0;background-color:#fefefe;width:100%;padding:5%");
		document.getElementById("game-div").append(hideItemListModal);
		document.getElementById("hideItemListModal").append(hideItemListModalBody);

		hideItemListRemove = function(itemName) {
			var index = tedStoredSettings.hideItemList.indexOf(itemName);
			if (index >= 0) {
				tedStoredSettings.hideItemList.splice(index,1);
				updateVariables();
			} else console.log("error: "+itemName+" not in tedStoredSettings.hideItemList");
		};
		myItemListRemove = function(itemName) {
			var index, indexi;
			for (var i = 0; i < tedStoredSettings.myItemList.length; i++) {
				for (var j = 0; j < tedStoredSettings.myItemList[i].length; j++) {
					index = tedStoredSettings.myItemList[i].indexOf(itemName);
					indexi = i;
					if (index >= 0) break;
				}
				if (index >= 0) break;
			}
			if (index >= 0) {
				tedStoredSettings.myItemList.splice(indexi,1);
				updateVariables();
			} else console.log("error: "+itemName+" not in tedStoredSettings.myItemList");
		};
		myItemListAdd = function(itemName, price) {
			if (!isNaN(price)) {
				myItemListRemove(itemName);
				tedStoredSettings.myItemList.push([itemName,price]);
				updateVariables();
			} else console.log("myItemListAdd price not a number"+typeof(itemName),itemName);
		};

		var myItemListModal = document.createElement("div");
		myItemListModal.setAttribute("id","myItemListModal");
		myItemListModal.setAttribute("style","display:none");
		var myItemListModalBody = document.createElement("div");
		myItemListModalBody.setAttribute("id","myItemListModalBody");
		myItemListModalBody.setAttribute("style","position:fixed;bottom:0;background-color:#fefefe;width:100%;padding:5%");
		document.getElementById("game-div").append(myItemListModal);
		document.getElementById("myItemListModal").append(myItemListModalBody);

		changeColor = function(key,color) {
			var isOk  = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
			//if (isOk) {
			tedStoredSettings[key].bgcolor = color;
			updateVariables();
			//} else tedStoredSettings[key].bgcolor = "#FFFFFF";
		};
		resetColors = function() {
			KEYS.forEach((key) => {
				if (tedStoredSettings[key].bgcolor) {
					tedStoredSettings[key].bgcolor = defaultSettings[key].bgcolor;
					document.getElementById("celltick-"+key).style.backgroundColor = tedStoredSettings[key].bgcolor;
				}
			});
			updateVariables();
		};
		var colorModal = document.createElement("div");
		colorModal.setAttribute("id","colorModal");
		colorModal.setAttribute("style","display:none");
		var colorModalBody = document.createElement("div");
		colorModalBody.setAttribute("id","colorModalBody");
		colorModalBody.setAttribute("style","position:fixed;bottom:0;background-color:#fefefe;width:100%;padding:5%");
		document.getElementById("game-div").append(colorModal);
		document.getElementById("colorModal").append(colorModalBody);

		window.onclick = function(event) {
			if (event.target == hideItemListModal) {
				hideItemListModal.style.display = "none";
			}
			if (event.target == myItemListModal) {
				myItemListModal.style.display = "none";
			}
			if (event.target == colorModal) {
				colorModal.style.display = "none";
			}
		};
	}
	function defaultUndercut() {
		if (autoUndercut) {
			if (document.getElementById("dialogue-market-chosenpostitem").parentElement.style.display != "none" && document.getElementById("chosenpostitem-price").value === "" && document.getElementById("chosenpostitem-itemName").value != defaultUndercutOnce) {
				defaultUndercutOnce = document.getElementById("chosenpostitem-itemName").value;
				for (var i = 0; i < arrMarketItems.length; i++) {
					if (itemNameFix(arrMarketItems[i][0]) == document.getElementById("chosenpostitem-itemName").value) {
						if (arrMarketItems[i][2][0] > matchLowestPriceAt) {
							document.getElementById("chosenpostitem-price").value = (arrMarketItems[i][2][0] - undercutBy);
						} else if (arrMarketItems[i][2][0] <= matchLowestPriceAt) {
							document.getElementById("chosenpostitem-price").value = arrMarketItems[i][2][0];
						}
					}
				}
			} else if (document.getElementById("dialogue-market-chosenpostitem").parentElement.style.display == "none") {
				if (defaultUndercutOnce !== "") {
					defaultUndercutOnce = "";
				}
				if (document.getElementById("chosenpostitem-price").value !== "") {
					document.getElementById("chosenpostitem-price").value = "";
				}
				if (document.getElementById("chosenpostitem-itemName").value !== "") {
					document.getElementById("chosenpostitem-itemName").value = "";
				}
			}
		}
	}
	function addItemTooltips() {
		if (itemTooltips) {
			for (var i = 0; i < arrMarketItems.length; i++) {
				var fixedName = itemNameFix(arrMarketItems[i][0]);
				if (document.getElementById("tooltip-"+fixedName) !== null) {
					var newTooltip = "<b>Market price: </b><img class='image-icon-20' src='images/coins.png'> "+numberWithCommas(arrMarketItems[i][2][0]);
					if (document.getElementById("tooltip-"+fixedName).lastElementChild.tagName == "DIV") {
						document.getElementById("tooltip-"+fixedName).removeChild(document.getElementById("tooltip-"+fixedName).lastChild);
					}
					var tooltipElement = document.createElement("div");
					tooltipElement.innerHTML = newTooltip;
					document.getElementById("tooltip-"+fixedName).appendChild(tooltipElement);
				}
			}
		}
	}
	function quickCalcMain() {
		if (quickCalcOn) {
			var i, a, b;
			var arrQuickCalcHeat = ["Error, search for all (infinity symbol)", 999999, 0, 999999]; // name, heatprice, amount, logprice, heat
			var arrStargemInput = [["Blewit Mushroom",100,0,0],["Gold Leaf",1,0,0],["Sapphire",1,0,0],["Emerald",1,0,0],["Ruby",1,0,0],["Diamond",1,0,0]];//name,amt need, amt have, ttl price
			var arrStargemOutput = [["Stardust",0]];
			quickCalcElement.style.display = "";
			quickCalcElement.style.color = "#F5F5F5";
			quickCalcElement.innerHTML = "Quick Calc: (for accurate data search market>all before using Quick Calc)<br><br>";
			if (typeof(document.getElementById("market-table").rows[1]) == "undefined" || document.getElementById("market-table").rows[1] === null) {
				quickCalcElement.innerHTML += "Invalid data: search market for ALL first";
			} else if (typeof(document.getElementById("market-table").rows[1]) != "undefined" || document.getElementById("market-table").rows[1] !== null) {
				//heat calc
				for (i = 0; i < arrMarketItems.length; i++) {
					var arrLogs = [["Logs",1],["Oak Logs",2],["Willow Logs",5],["Maple Logs",10],["Stardust Logs",20]];
					for (a = 0; a < arrLogs.length; a++) {
						if (arrMarketItems[i][0] == arrLogs[a][0]) {
							if (arrMarketItems[i][2][0]/arrLogs[a][1] < arrQuickCalcHeat[1]) {
								arrQuickCalcHeat[0] = arrMarketItems[i][0];
								arrQuickCalcHeat[1] = arrMarketItems[i][2][0]/arrLogs[a][1];
								arrQuickCalcHeat[2] = arrMarketItems[i][2][1];
								arrQuickCalcHeat[3] = arrMarketItems[i][2][0];
								arrQuickCalcHeat[4] = arrLogs[a][1];
							}
							if (debugToConsole) { console.log(arrMarketItems[i][0],arrMarketItems[i][2][0]/arrLogs[a][1],arrMarketItems[i][2][1]); }
							if (debugToConsole) { console.log(arrQuickCalcHeat[0],arrQuickCalcHeat[1],arrQuickCalcHeat[2]); }
						}
					}
					//stargem
					for (a = 0; a < arrStargemInput.length; a++) {
						if (arrMarketItems[i][0] == arrStargemInput[a][0]) {
							for (b = 2; b < arrMarketItems[i].length; b++) {
								if (arrStargemInput[a][2] < arrStargemInput[a][1]) {
									if (arrMarketItems[i][b][1] < arrStargemInput[a][1]-arrStargemInput[a][2]) {
										arrStargemInput[a][2] += arrMarketItems[i][b][1];
										arrStargemInput[a][3] += arrMarketItems[i][b][0]*arrMarketItems[i][b][1];
									} else if (arrMarketItems[i][b][1] >= arrStargemInput[a][1]-arrStargemInput[a][2]) {
										arrStargemInput[a][3] += (arrStargemInput[a][1]-arrStargemInput[a][2])*arrMarketItems[i][b][0];
										arrStargemInput[a][2] = arrStargemInput[a][1];
									}
									if (debugToConsole) { console.log(arrStargemInput[a][0], arrStargemInput[a][1], arrStargemInput[a][2], arrStargemInput[a][3]); }
								}
							}
						}
					}
					for (a = 0; a < arrStargemOutput.length; a++) {
						if (arrMarketItems[i][0] == arrStargemOutput[a][0]) {
							arrStargemOutput[a][1] = arrMarketItems[i][2][0];
							break;
						}
					}
				}
				quickCalcElement.innerHTML += "Cheapest heat:<br>"+arrQuickCalcHeat[0]+"<br>Total logs: "+numberWithCommas(arrQuickCalcHeat[2])+" | Total Heat: "+numberWithCommas(arrQuickCalcHeat[4]*arrQuickCalcHeat[2])+"<br>Heat price: "+numberWithCommas(arrQuickCalcHeat[1])+" | Log price: "+numberWithCommas(arrQuickCalcHeat[3])+" | Total price: "+numberWithCommas((arrQuickCalcHeat[3]*arrQuickCalcHeat[2]))+"<br><br>";
				quickCalcElement.innerHTML += "Stargem potion:<br>Input: ";
				for (a = 0; a < 2; a++) {
					if (arrStargemInput[a][2] != arrStargemInput[a][1]) {
						quickCalcElement.innerHTML += "!!! < "+arrStargemInput[a][1]+" "+arrStargemInput[a][0]+" x"+arrStargemInput[a][2]+" + ";
					} else quickCalcElement.innerHTML += numberWithCommas(arrStargemInput[a][3])+" "+arrStargemInput[a][0]+" x"+arrStargemInput[a][2]+" + ";
				}
				for (a = 2; a < arrStargemInput.length; a++) {
					if (arrStargemInput[a][2] != arrStargemInput[a][1]) {
						quickCalcElement.innerHTML += "<br>!!! < "+arrStargemInput[a][1]+" "+arrStargemInput[a][0]+" x"+arrStargemInput[a][2]+" + ";
					} else quickCalcElement.innerHTML += "<br>"+numberWithCommas(arrStargemInput[a][3])+" "+arrStargemInput[a][0]+" = "+numberWithCommas((arrStargemInput[a][3]+arrStargemInput[0][3]+arrStargemInput[1][3]));
				}
				quickCalcElement.innerHTML += "<br>Output: "+arrStargemOutput[0][0]+"<br>@ "+arrStargemOutput[0][1]+" | @ "+(arrStargemOutput[0][1]-1)+" net gain/loss";
				for (a = 2; a < arrStargemInput.length; a++) {
					if (arrStargemInput[a][2] != arrStargemInput[a][1]) {
						//
					} else if (arrStargemInput[a][2] == arrStargemInput[a][1]) {
						var stargemNet, stargemNet1;
						if (a == 5) {
							stargemNet = numberWithCommas(((arrStargemOutput[0][1]-1)*(a*120000))-(arrStargemInput[a][3]+arrStargemInput[0][3]+arrStargemInput[1][3]));
							stargemNet1 = numberWithCommas(((arrStargemOutput[0][1]-1)*(a*120000))-(arrStargemInput[a][3]+arrStargemInput[0][3]+arrStargemInput[1][3]));
							quickCalcElement.innerHTML += "<br>"+stargemNet+" | "+stargemNet1+" "+arrStargemInput[a][0]+": "+arrStargemOutput[0][0]+ " x"+numberWithCommas(a*120000)+" = "+numberWithCommas((arrStargemOutput[0][1]*(a*120000)));
							continue;
						}
						stargemNet = numberWithCommas((arrStargemOutput[0][1]*((a-1)*100000))-(arrStargemInput[a][3]+arrStargemInput[0][3]+arrStargemInput[1][3]));
						stargemNet1 = numberWithCommas(((arrStargemOutput[0][1]-1)*((a-1)*100000))-(arrStargemInput[a][3]+arrStargemInput[0][3]+arrStargemInput[1][3]));
						quickCalcElement.innerHTML += "<br>"+stargemNet+" | "+stargemNet1+" "+arrStargemInput[a][0]+": "+arrStargemOutput[0][0]+ " x"+numberWithCommas(((a-1)*100000))+" = "+numberWithCommas((arrStargemOutput[0][1]*((a-1)*100000)));
					}
				}
			}
		} else if (quickCalcOn === false) {
			quickCalcElement.style.display = "none";
		}

	}
	function quickCalcButtonClickAction (zEvent) {
		if (quickCalcOn === true) {
			quickCalcOn = false;
			quickCalcMain();
			buttonMain();
		} else if (quickCalcOn === false) {
			quickCalcOn = true;
			quickCalcMain();
			buttonMain();
		}
	}
	function getMarketItems() {
		var currentItemId, itemName, itemId, itemPrice, itemAmount, itemMarketId, uniqueMarketItems = 0;
		arrMarketItems = [];
		for (var i = 1; i < document.getElementById("market-table").rows.length; i++) {
			if (typeof(document.getElementById("market-table").rows[i].childNodes[0]) != "undefined" && document.getElementById("market-table").rows[i].childNodes[0] !== null) {
				itemName = document.getElementById("market-table").rows[i].childNodes[0].innerHTML;
				itemId = document.getElementById("market-table").rows[i].getAttribute("data-market-itemid");
				itemPrice = parseInt(document.getElementById("market-table").rows[i].getAttribute("data-market-price"));
				itemAmount = parseInt(document.getElementById("market-table").rows[i].getAttribute("data-market-amount"));
				itemMarketId = document.getElementById("market-table").rows[i].getAttribute("data-market-marketid");
				if (itemId != currentItemId) {
					currentItemId = itemId;
					uniqueMarketItems++;
					arrMarketItems.push([itemName, itemId]);
				}
				arrMarketItems[uniqueMarketItems-1].push([itemPrice, itemAmount, itemMarketId, parseInt(i)]);
			}
		}
	}
	disableBtn = function(btn) {
		if (btn.childNodes[0].disabled === false) {
			btn.childNodes[0].disabled = true;
			btn.setAttribute("style","box-shadow: 0 0 30px 6px rgba(255, 0, 0, 1) inset;transition: box-shadow 0.3s ease-out;");
			setTimeout(function() {
				btn.setAttribute("style","box-shadow: 0 0 30px 6px rgba(255, 0, 0, 0) inset;transition: box-shadow 0.3s ease-out;");
				btn.childNodes[0].disabled = false;
			}, 3000);
		}
	};
	function alterMarketSlots() {
		if (marketSlotsCustomUi) {
			if (typeof(document.getElementById("market-slot-1").parentNode) != "undefined" && document.getElementById("market-slot-1").parentNode.id != "tedMarketSlotContainer") {
				var tedMarketUiElement = document.createElement("div");
				tedMarketUiElement.setAttribute("style","position:relative;height:325px;width:230px;margin:0px 1%;background:linear-gradient(gold,silver);");
				tedMarketUiElement.setAttribute("id","ted-market-ui");
				var tedMarketTopImageElement = document.createElement("img");
				tedMarketTopImageElement.setAttribute("src","images/shootingstar.png");
				tedMarketTopImageElement.setAttribute("class","image-icon-70");
				marketCancelCooldownElement = document.createElement("div");
				marketCancelCooldownElement.setAttribute("style","border-bottom:1px solid black;border-top:1px solid black;");
				marketCancelCooldownElement.innerHTML = "<br>Cooldown<br><br>"+marketCancelCooldown+"<br><br>";
				var noteElement = document.createTextNode("If you have any suggestions on what else to put in this box, pm ted120");
				var browseAllElementWrapper = document.createElement("div");
				browseAllElementWrapper.setAttribute("id","browseAllElementWrapper");
				browseAllElementWrapper.setAttribute("style","position:absolute;left:0;bottom:0;width:100%;");
				var browseAllElement = document.createElement("div");
				browseAllElement.setAttribute("style","margin:10px");
				browseAllElement.setAttribute("class","basic-smallbox-grey");
				browseAllElement.setAttribute("id","ted-browse-all");
				browseAllElement.innerHTML = "<input type='image' data-item-name='All Items' onclick='disableBtn(this.parentNode);document.getElementById(&quot;dialogue-market-postitem-buyorsell&quot;).value = &quot;buy&quot;;postItemDialogue(document.getElementById(&quot;dialogue-market-postitem-buyorsell&quot;), &quot;ALL&quot;, this);' src='images/icons/infinity.png' class='image-icon-50'>";
				var tedMarketSlotContainer = document.createElement("div");
				tedMarketSlotContainer.setAttribute("style","display:flex;justify-content:center;width:100%");
				document.getElementById("market-slot-1").parentNode.appendChild(tedMarketSlotContainer);
				for (var i = 0; i < arrMarketSlots.length; i++) {
					document.getElementById("market-slot-"+(i + 1)).style.margin = "0px 1%";
					tedMarketSlotContainer.appendChild(document.getElementById("market-slot-"+(i + 1)));
				}
				tedMarketSlotContainer.appendChild(tedMarketUiElement);
				document.getElementById("ted-market-ui").appendChild(tedMarketTopImageElement);
				document.getElementById("ted-market-ui").appendChild(marketCancelCooldownElement);
				document.getElementById("ted-market-ui").appendChild(noteElement);
				document.getElementById("ted-market-ui").appendChild(browseAllElementWrapper);
				document.getElementById("browseAllElementWrapper").appendChild(browseAllElement);
			}
		}
	}
	function sortMarketTable() {
		var i, arrToAppend = [];
		if (document.getElementById("market-table").getAttribute("isSorted") == "false") {
			for (var s = 0; s < arrSortItemsList.length; s++) {
				for (i = 0; i < arrMarketItems.length; i++) {
					if (arrMarketItems[i][0] == arrSortItemsList[s]) {
						for (var a = 2; a < arrMarketItems[i].length; a++) {
							arrToAppend.push(document.getElementById("market-table").rows[arrMarketItems[i][a][3]]);
						}
						break;
					}
				}
			}
			for (i = 0; i < arrToAppend.length; i++) {
				document.getElementById("market-table").append(arrToAppend[i]);
			}
			document.getElementById("market-table").setAttribute("isSorted","true");
		}
	}

	hideItemListBtnAction = function(itemName) {
		if (!isInArray(tedStoredSettings.hideItemList,itemName)) {
			tedStoredSettings.hideItemList.push(itemName);
			updateVariables();
		} else console.log("already on hideItemList:"+itemName);
	};
	myItemListBtnAction = function(itemName, itemPrice) {
		myItemListAddName = itemName;
		myItemListAddPrice = itemPrice;
		changeSetting("myItemList");
	};

	function alterMarketTable() {
		var i, a, b, s, maxCanBuy;
		document.getElementById("market-table").rows[0].style.backgroundColor = "gold";
		document.getElementById("market-table").setAttribute("isSorted", "false");
		if (document.getElementById("market-table").nextSibling.id != "tedMarketTable") {
			var tedMarketTable = document.createElement("table");
			tedMarketTable.setAttribute("id","tedMarketTable");
			tedMarketTable.setAttribute("class","market-table");
			document.getElementById("market-table").style.display = "none";
			if (document.getElementById("market-table").nextSibling) {
				document.getElementById("market-table").parentNode.insertBefore(tedMarketTable, document.getElementById("market-table").nextSibling);
			}
			else {
				document.getElementById("market-table").parentNode.appendChild(document.getElementById("tedmarketTable"));
			}
		}
		if (debugToConsole) { console.log(arrMarketItems); }
		for (i = 0; i < arrMarketItems.length; i++) {
			document.getElementById("market-table").rows[arrMarketItems[i][2][3]].removeAttribute("onclick");
			for (b = 1; b < document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes.length; b++) {
				document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[b].setAttribute("onclick","openBuyFromPlayerMarketDialogue(this.parentNode);");
			}
			var btnMyItemListDiv = document.createElement("div");
			btnMyItemListDiv.setAttribute("style","float:left;margin-left:5%");
			var btnMyItemList = document.createElement("BUTTON");
			btnMyItemList.setAttribute("onclick","myItemListBtnAction(this.parentNode.parentNode.childNodes[2].innerHTML,this.parentNode.parentNode.parentNode.getAttribute('data-market-price'));");
			btnMyItemList.setAttribute("style","background-color:#ffccff");
			btnMyItemList.setAttribute("title","Add to myItemList");
			var btnMyItemListText = document.createTextNode("+");
			btnMyItemList.appendChild(btnMyItemListText);
			btnMyItemListDiv.appendChild(btnMyItemList);

			var btnHideItemListDiv = document.createElement("div");
			btnHideItemListDiv.setAttribute("style","float:left;margin-left:5%");
			var btnHideItemList = document.createElement("BUTTON");
			btnHideItemList.setAttribute("onclick","hideItemListBtnAction(this.parentNode.parentNode.childNodes[2].innerHTML);");
			btnHideItemList.setAttribute("style","color:white;background-color:black");
			btnHideItemList.setAttribute("title","Add to hideItemList (removable in Profile & Settings > click hideItemList)");
			var btnHideItemListText = document.createTextNode("-");
			btnHideItemList.appendChild(btnHideItemListText);
			btnHideItemListDiv.appendChild(btnHideItemList);

			var itemNameTextDiv = document.createElement("div");
			itemNameTextDiv.setAttribute("onclick","openBuyFromPlayerMarketDialogue(this.parentNode.parentNode);");
			var itemNameText = document.createTextNode(arrMarketItems[i][0]);
			itemNameTextDiv.append(itemNameText);
			while (document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].firstChild) {
				document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].removeChild(document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].firstChild);
			}
			document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].append(btnMyItemListDiv);
			document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].append(btnHideItemListDiv);
			document.getElementById("market-table").rows[arrMarketItems[i][2][3]].childNodes[0].append(itemNameTextDiv);
			for (a = 2; a < arrMarketItems[i].length; a++) {
				for (b = 0; b < 4; b++) {
					if (b == 1) continue;
					document.getElementById("market-table").rows[arrMarketItems[i][a][3]].childNodes[b].setAttribute("style","text-align:right;padding-right:2%");
					if (b === 0) document.getElementById("market-table").rows[arrMarketItems[i][a][3]].childNodes[b].setAttribute("style","text-align:right;padding-right:2%;width:auto;");
				}
				if (smallMarketImages) {
					document.getElementById("market-table").childNodes[0].childNodes[arrMarketItems[i][a][3]].childNodes[1].childNodes[0].style = "height: "+marketImageSize+"px;width: "+marketImageSize+"px;";
				}
				maxCanBuy = Math.floor(coins / arrMarketItems[i][a][0]);
				if (showMaxCanBuy) {
					if (maxCanBuy < arrMarketItems[i][a][1]) {
						var maxCanBuyDiv = document.createElement("div");
						maxCanBuyDiv.setAttribute("style","float:left;margin-left:5%");
						maxCanBuyDiv.append(" (x"+numberWithCommas(maxCanBuy)+") ");
						document.getElementById("market-table").rows[arrMarketItems[i][a][3]].cells[3].prepend(maxCanBuyDiv);
					} else if (maxCanBuy >= arrMarketItems[i][a][1]) {
						maxCanBuy = arrMarketItems[i][a][1];
					}
				}
				var oldOnclick = document.getElementById('market-table').rows[arrMarketItems[i][a][3]].getAttribute('onclick');
				document.getElementById("market-table").rows[arrMarketItems[i][a][3]].setAttribute("onclick",oldOnclick+";document.getElementById('buyFromMarket-input').value = "+maxCanBuy+";");
				if (notEnoughCoinsOpacity && maxCanBuy === 0) {
					document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.opacity = "0.3";
				}
				if (document.getElementById("market-table").rows.length > 12) {
					if (document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.backgroundColor === "") {
						document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.backgroundColor = "red"; //hidden
					}
					if (document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.display === "" ) {
						document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.display = "none";
					}
					if (i == arrMarketItems.length - 1 && a == arrMarketItems[i].length - 1) { //after last item in arrMarketItems
						quickCalcMain();
					}
				}
				if (arrMarketItems[i].length == 3 && (!isInArray(hideItemList,arrMarketItems[i][0]))) {
					document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.backgroundColor = colorSingleItems;
					document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.display = "table-row";
				} else if (arrMarketItems[i].length >= 4 && !isInArray(hideItemList,arrMarketItems[i][0])) {
					if (arrMarketItems[i][2][0] < Math.ceil(arrMarketItems[i][3][0] * 0.86) && arrMarketItems[i][2][0]) {
						document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.backgroundColor = colorNextLowestToMinPrice;
						document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.display = "table-row";
					}
				}
				for (s = 0; s < arrMarketSlots.length; s++) {
					if (arrMarketSlots[s][1] === false) {
						if (arrMarketItems[i][a][2] == arrMarketSlots[s][0]) {
							if (a == 2) {
								document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.display = "table-row";
								document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.backgroundColor = colorMyListedLowest;
								if (arrMarketItems[i].length >= 4) {
									if ((arrMarketItems[i][3][0] - arrMarketItems[i][2][0]) >= 3) {
										document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.display = "table-row";
										document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.backgroundColor = colorMyListedLowestCanRaisePrice;
									}
								}
							} else if (a > 2) {
								document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.backgroundColor = colorMyListedNotLowest;
								document.getElementById("market-table").rows[arrMarketItems[i][a][3]].style.display = "table-row";
								document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.backgroundColor = colorLowestForMyListed;
								document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.display = "table-row";
							} else console.log("for (a... error");
						}
					}
				}
			}
			if (arrMarketItems[i].length >= 4 && !isInArray(hideItemList,arrMarketItems[i][0])) {
				if (arrMarketItems[i][2][0] < Math.ceil(arrMarketItems[i][3][0] * 0.86) && arrMarketItems[i][2][0]) {
					document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.backgroundColor = colorMinPrice;
					document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.display = "table-row";
					document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.fontWeight = 700;
				}
			}
			// myItemList
			for (b = 0; b < myItemList.length; b++) {
				if (myItemList[b][0] == arrMarketItems[i][0]) {
					//console.log(arrMarketItems[i][2][0],myItemList[b][1]);
					//console.log(typeof(arrMarketItems[i][2][0]),typeof(myItemList[b][1]));
					if (arrMarketItems[i][2][0] <= myItemList[b][1]) {
						document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.backgroundColor = colorMyItemList;
						document.getElementById("market-table").rows[arrMarketItems[i][2][3]].style.display = "table-row";
						if (arrMarketItems[i].length >= 4) {
							document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.backgroundColor = colorMyItemListNextLowest;
							document.getElementById("market-table").rows[arrMarketItems[i][3][3]].style.display = "table-row";
						}
					}
				}
			}
		}
		sortMarketTable();
		var toAppend = [];
		for (i = 0; i < document.getElementById("market-table").childNodes.length; i++) {
			toAppend.push(document.getElementById("market-table").childNodes[i]);
		}
		while (document.getElementById("tedMarketTable").firstChild) {
			document.getElementById("tedMarketTable").removeChild(document.getElementById("tedMarketTable").firstChild);
		}
		for (i = 0; i < toAppend.length; i++) {
			document.getElementById("tedMarketTable").append(toAppend[i]);
		}
	}
	function updateMarketSlots() {
		arrMarketSlots = [[marketSlot1, false]];
		for (var i = 0; i < arrMarketSlots.length; i++) {
			if (document.getElementById("market-slot-"+(i + 1)+"-free").style.display === "") {
				arrMarketSlots[i][1] = true;
			}
		}
	}
	function marketReloaded() {
		if (typeof(document.getElementById("market-table").rows[0]) != "undefined" && document.getElementById("market-table").rows[0] !== null) {
			// exists
			if (document.getElementById("market-table").rows[0].style.backgroundColor != "gold") {
				updateMarketSlots();
				getMarketItems();
				addItemTooltips();
				alterMarketTable();
			}
		}
	}
	function marketMain() {
		if (marketOn === true) {
			marketInterval = setInterval(marketReloaded, 0);
		}
	}
	function marketButtonClickAction(zEvent) {
		if (marketOn === true) {
			marketOn = false;
			clearInterval(marketInterval);
			document.getElementById("market-table").style.display = "";
			if (document.getElementById("tedMarketTable")) {document.getElementById("tedMarketTable").style.display = "none";}
			buttonMain();
		} else if (marketOn === false) {
			marketOn = true;
			document.getElementById("market-table").style.display = "none";
			if (document.getElementById("tedMarketTable")) {document.getElementById("tedMarketTable").style.display = "";}
			marketMain();
			buttonMain();
		}
	}
	function persistentInterval() {
		if (nextTick()) {
			if (treasureMap > 0 && document.getElementById("mapSpan").style.display !== "") {
				document.getElementById("mapSpan").style.display = "";
			} else if (treasureMap === 0 && document.getElementById("mapSpan").style.display != "none") {
				document.getElementById("mapSpan").style.display = "none";
			}
			marketCancelCooldownElement.innerHTML = "<br>Cooldown<br><br>"+marketCancelCooldown+"<br><br>";
		}
		defaultUndercut();
	}
	function otherSettings() {
		//enter in input box when buying item to buy
		document.getElementById("buyFromMarket-input").setAttribute("onkeydown","if (event.keyCode == 13) { confirmBuyFromMarket(document.getElementById('buyFromMarket-marketId'), document.getElementById('buyFromMarket-price'), document.getElementById('buyFromMarket-input'));$(this).closest('.ui-dialog-content').dialog('close'); }");
		//enter on confirm dialogue to confirm buy
		//document.getElementById("dialogue-confirm").setAttribute("onkeydown","if (event.keyCode == 13) { confirmedDialogue(this, document.getElementById('dialogue-confirm-cmd').value) }");
	}
	tedMarketUiSettings();
	drawButtons();
	marketMain();
	document.body.append(quickCalcElement);
	alterMarketSlots();
	otherSettings();
	setInterval(persistentInterval, 100);
});