// ==UserScript==
// @name Krunker Market Tweaks
// @namespace http://tampermonkey.net/
// @version v1.0
// @description Tweaks the krunker market
// @author Catten
// @match https://krunker.io/social.html?p=*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @license GNU GPLv3
// ==/UserScript==
(function() {
'use strict';
//Delete popup holder when ESC is pressed
$(document).keyup(function(e) {
if(e.key === "Escape") {
hideElementById("popupHolder");
}
});
//Wait for page to fully load before doing other stuff
window.addEventListener('load', function() {
let popup = document.getElementById("popupHolder");
//popup.addEventListener("click", () => { hideElementById("popupHolder") });
createKrunkFlip();
setInterval(function(){
runKrunkFlip()
}, 100);
}, false);
//(new MutationObserver(check)).observe(document, {childList: true, subtree: true});
//Only play the music on the normal market tab, because otherwise there could be multiple going at the same time
if(document.URL == "https://krunker.io/social.html?p=market") {
playMusic();
}
})();
/*function check(changes, observer) {
if(document.querySelector('#profileKR')) {
observer.disconnect();
alert("it happened, you have" + document.getElementById("profileKR").innerHTML);
}
}*/
function hideElementById(id) {
let element = document.getElementById(id);
element.style.display = "none";
}
function playMusic() {
let music = new Audio("https://cdn.discordapp.com/attachments/1321922774008201229/1321923265463062581/marketplace.mp3?ex=676f007a&is=676daefa&hm=10a91301bf42eeb022dea945e7760b30e37c00a191a9dd253ce46e91d277b0f9&");
music.loop = true;
music.play();
}
function runKrunkFlip() {
cycleColor(2, 0, 30);
let krBox = document.getElementById("kr");
let costBox = document.getElementById("cost");
let priceBox = document.getElementById("price");
let profitOutput = document.getElementById("profit");
let markupOutput = document.getElementById("markup");
let verdictOutput = document.getElementById("verdict");
if(isNullOrEmpty(krBox.value) || isNullOrEmpty(costBox.value) || isNullOrEmpty(priceBox.value)) {
if(verdictOutput.innerText !== "Not enough info") {
profitOutput.innerText = "";
markupOutput.innerText = "";
verdictOutput.innerText = "Not enough info";
}
return;
}
let kr = parseFloat(krBox.value);
let cost = parseFloat(costBox.value);
let price = parseFloat(priceBox.value);
let krTaxForListing = Math.ceil(price * 0.10);
let profit = price - cost - krTaxForListing;
let markup = price / cost * 100;
if(kr - krTaxForListing - cost < 0) {
verdictOutput.innerHTML = "Can't pay fees";
return;
}
if(markup >= 20) {
verdictOutput.innerHTML = "Stonks";
} else {
verdictOutput.innerHTML = "Not stonks";
}
profitOutput.innerHTML = round(profit);
markupOutput.innerHTML = round(markup);
}
let hue = 0;
let adding = true;
function cycleColor(speed, hueMin, hueMax) {
const krunkFlipContainer = document.getElementById("krunkFlipContainer");
const title = document.getElementById("title");
krunkFlipContainer.style.borderColor = `hsl(${hue}, 100%, 50%)`;
title.style.color = `hsl(${hue}, 100%, 50%)`;
if(adding) {
if(hue + speed > hueMax) {
adding = false;
} else {
hue += speed;
}
} else {
if(hue - speed < hueMin) {
adding = true;
} else {
hue -= speed;
}
}
}
function round(num) {
return Math.ceil(num * 100) / 100;
}
function isNullOrEmpty(string) {
if(typeof(string) === "string" && string.length === 0) {
return true
} else if(string === null) {
return true
} else {
return false;
}
}
function createKrunkFlip() {
let itemsalesList = document.getElementById("itemsalesList");
let krunkFlipContainer = document.createElement("div");
krunkFlipContainer.id = "krunkFlipContainer";
let krunkFlipContainerSpace = document.createElement("br");
itemsalesList.appendChild(krunkFlipContainerSpace);
itemsalesList.appendChild(krunkFlipContainer);
document.getElementById("krunkFlipContainer").innerHTML = `
<style>
#krunkFlipContainer {
font-family: 'GameFont';
vertical-align: bottom;
font-size: 20px;
margin-bottom: 20px;
padding: 20px;
width: 680px;
text-align: left;
background-color: #292929;
display: inline-block;
border: medium solid orange;
border-radius: 12px;
}
#title {
padding: 10px
}
.text {
font-family: 'GameFont';
color:rgba(255,255,255,0.4);
}
.smallText {
font-family: 'GameFont';
color:rgba(255,255,255,0.4);
font-size: 14px;
}
.smallLightText {
font-family: 'GameFont';
color:rgba(255,255,255,0.8);
font-size: 14px;
}
.tiny {
font-family: 'GameFont';
color:rgba(255,255,255,0.4);
font-size: 9px;
text-align: left;
horizontal-align: left;
vertical-align: bottom;
position: relative;
display: block;
}
/*.author {
font-family: 'GameFont';
color:rgba(255,255,255,0.4);
font-size: 9px;
text-align: left;
horizontal-align: left;
vertical-align: bottom;
position: relative;
display: block;
}*/
input {
horizontal-align: left;
background: rgba(255,255,255,0.3);
color: rgba(255,255,255,0.6);
}
::placeholder {
color: rgba(255,255,255,0.3);
}
</style>
<div id="title" class="text"; style="max-width: fit-content; margin-left: auto; margin-right: auto;">KrunkFlip</div>
<div id="lhs" style="float:left; background-color: rgba(0, 0, 0, 0.2); border-radius: 12px; padding: 20px; width: 43%;">
<div id="krDiv">
<input id="kr" type="number" min="0" placeholder="KR Owned"/>
<label class="smallLightText">KR</label>
</div>
<div id="costDiv">
<input id="cost" type="number" min="0" placeholder="Cost of cosmetic"/>
<label class="smallLightText">KR</label>
<label class="smallText">Cost</label>
</div>
<div id="priceDiv">
<input id="price" type="number" min="0" placeholder="Sell price"/>
<label class="smallLightText">KR</label>
<label class="smallText">Price</label>
</div>
</div>
<div id="rhs" style="float:right; background-color: rgba(0, 0, 0, 0.2); border-radius: 12px; padding: 20px; width: 43%;">
<div id="profitsDiv">
<label class="smallText">Profit:</label>
<label id="profit" class="smallText"></label>
<label class="smallLightText">KR</label>
</div>
<div id="markupDiv">
<label class="smallText">Markup:</label>
<label id="markup" class="smallText"></label>
<label class="smallLightText" for="markup">%</label>
</div>
<div id="verdictDiv">
<label id="verdict" class="smallText">Not enough info</label>
</div>
</div>
<!--No clue why I need so many line breaks to get the thing off of rhs, (or why I need any to begin with) but it does work-->
<br>
<br>
<br>
<br>
<br>
<div id="detailsDiv">
<p class="tiny" style="display: inline;">Made by CattenWithGun - v1.0</p>
</div>
`;
let inputKRBox = document.getElementById("kr");
let currentKR = document.getElementById("profileKR").textContent;
let parsedKR = currentKR.substring(0, currentKR.length - 3).replace(/,/g, '');
inputKRBox.value = parsedKR;
}