diff options
author | amelia <[email protected]> | 2022-04-03 20:28:38 -0500 |
---|---|---|
committer | amelia <[email protected]> | 2022-04-03 20:28:38 -0500 |
commit | fb11db87c5ff647c5bd3e2b63da2054acd91a5e3 (patch) | |
tree | c1980bfe016af28d223baaf48248be8603cf45bf | |
parent | 5a439a08016fbb5aee85f4ed21be3b653d313de4 (diff) |
Add files via uploadv1.1+2
-rw-r--r-- | crates.json | 6 | ||||
-rw-r--r-- | index.html | 485 |
2 files changed, 280 insertions, 211 deletions
diff --git a/crates.json b/crates.json index 96849f3..fb3ab78 100644 --- a/crates.json +++ b/crates.json @@ -1 +1,5 @@ -{"crates":[{"price":5,"name":"red#1","contents":[{"color":"#330000","rarity":"common","value":3},{"color":"#660000","rarity":"common","value":3},{"color":"#990000","rarity":"common","value":3},{"color":"#CC0000","rarity":"common","value":3},{"color":"#FF0000","rarity":"common","value":3},{"color":"#FF3333","rarity":"uncommon","value":7},{"color":"#FF6666","rarity":"uncommon","value":7},{"color":"#FF9999","rarity":"uncommon","value":7},{"color":"#FFCCCC","rarity":"rare","value":15}]}]}
\ No newline at end of file +{"crates":[ + {"price":5,"name":"red#1","contents":[{"color":"#330000","rarity":"common","value":3},{"color":"#660000","rarity":"common","value":3},{"color":"#990000","rarity":"common","value":3},{"color":"#CC0000","rarity":"common","value":3},{"color":"#FF0000","rarity":"common","value":3},{"color":"#FF3333","rarity":"uncommon","value":7},{"color":"#FF6666","rarity":"uncommon","value":7},{"color":"#FF9999","rarity":"uncommon","value":7},{"color":"#FFCCCC","rarity":"rare","value":15}]} +, {"price":10,"name":"blue#1","contents":[{"color":"#1313ff","rarity":"common","value":5},{"color":"#1d1dff","rarity":"common","value":5},{"color":"#2727ff","rarity":"common","value":5},{"color":"#3131ff","rarity":"common","value":5},{"color":"#3b3bff","rarity":"common","value":5},{"color":"#4545ff","rarity":"common","value":5},{"color":"#4f4fff","rarity":"uncommon","value":15},{"color":"#5959ff","rarity":"uncommon","value":15},{"color":"#6363ff","rarity":"uncommon","value":15},{"color":"#6d6dff","rarity":"uncommon","value":15},{"color":"#8181ff","rarity":"rare","value":30}]} + +]}
\ No newline at end of file @@ -1,241 +1,306 @@ <!DOCTYPE html> <html> - <head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width"> - <title>color;)</title> - - <style> - - - </style> - </head> - <body> - - - <script> - - function createCookie(name, value, days) { - var expires; - if (days) { + +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width"> + <title>color;)</title> + + <style> + + + </style> +</head> + +<body> + + + <script> + + function createCookie(name, value, days) { + var expires; + if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); - } - else { + } + else { expires = ""; + } + document.cookie = name + "=" + value + expires + "; path=/"; + } + function allowDrop(ev) { + ev.preventDefault(); } - document.cookie = name + "=" + value + expires + "; path=/"; -} -function getCookie(c_name) { - if (document.cookie.length > 0) { + function getCookie(c_name) { + if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { - c_start = c_start + c_name.length + 1; - c_end = document.cookie.indexOf(";", c_start); - if (c_end == -1) { - c_end = document.cookie.length; - } - return unescape(document.cookie.substring(c_start, c_end)); + c_start = c_start + c_name.length + 1; + c_end = document.cookie.indexOf(";", c_start); + if (c_end == -1) { + c_end = document.cookie.length; + } + return unescape(document.cookie.substring(c_start, c_end)); } + } + return ""; } - return ""; -} - function s(value, index){ - var inv = getCookie('inv'); - inv = JSON.parse(inv) - createCookie('bank', parseInt(getCookie('bank'))+parseInt(value)); - inv.splice(index,1) - console.log(inv) - createCookie('inv', JSON.stringify(inv)); - updateInv() - - - } - function updateInv(){ - var inve = document.getElementById("inv"); - var inv = getCookie('inv'); - inv = JSON.parse(inv) - var balance = document.getElementById("balance"); - balance.innerHTML = getCookie("bank") - let i = "" - /* - for(let item of inv){ - console.log(item) - i+=("<div style='color:"+item.color+";'>{color:"+String(item.color)+", rarity:"+String(item.rarity)+", value: "+String(item.value)+"}</div>") + function rgbToHex(r, g, b) { + return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); + } + function hexToRgb(hex) { //made by people smarter than me, ty stackoverflow! + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; + } + function averageColor(a, b) { + // force the input as numbers *1 + let e = ((a * 1 + b * 1) / 2) + if (e > 255) {e = 255} + if (e < 0) {e = 0} + return e; } - */ - for(let item of inv){ + function drag(ev) { + ev.dataTransfer.setData("text", ev.target.id); + } + function drop(ev, index) { + ev.preventDefault(); + + var data = ev.dataTransfer.getData("text"); + var inv = getCookie('inv'); + inv = JSON.parse(inv) + + let r = averageColor(hexToRgb(inv[data].color).r, hexToRgb(inv[index].color).r) + let g = averageColor(hexToRgb(inv[data].color).g, hexToRgb(inv[index].color).g) + let b = averageColor(hexToRgb(inv[data].color).b, hexToRgb(inv[index].color).b) + if(data>index){ + inv.splice(data, 1) + inv.splice(index, 1) + + } else { + inv.splice(index, 1) + inv.splice(data, 1) + + } + + createCookie('inv', JSON.stringify(inv)); + let hex = (rgbToHex(r, g, b)) + hex = hex.split(".")[0] + console.log(hex) + let v = Math.floor(((255*3)-(r+g+b))/5) + let ne = {"color": hex, "rarity": "crafted", "value": v} + //if(data!=index && inv[data].color != inv[data].color){ - let t = '{color:'+String(item.color)+', rarity:'+String(item.rarity)+', value: '+String(item.value)+'}' - - i+=("<div onclick='s("+item.value+","+inv.indexOf(item)+")' onmouseout='this.innerHTML = \""+t+"\"'onmouseover='this.innerHTML=\"sell?\"' id='"+inv.indexOf(item)+"'style='color:"+item.color+";'>"+t+"</div>") + var inv = getCookie('inv'); + inv = JSON.parse(inv) + inv.push(ne) + + createCookie('inv', JSON.stringify(inv)); + //} } - - inve.innerHTML = i - - } - function clear(){ - createCookie('inv', JSON.stringify([])); - } - let file = "./crates.json" - var bank = getCookie('bank'); + + function s(value, index) { var inv = getCookie('inv'); - if(bank == ""){ - createCookie('bank', 15); - var bank = getCookie('bank'); - } - if(inv == ""){ - - createCookie('inv', JSON.stringify([])); - var inv = getCookie('inv'); - } - var arr = JSON.parse(inv); - // console.log(arr) - // console.log(bank) - // createCookie('bank', 15); -function min(item){ - console.log(item) - x = document.getElementsByClassName(item) + inv = JSON.parse(inv) + createCookie('bank', parseInt(getCookie('bank')) + parseInt(value)); + inv.splice(index, 1) + console.log(inv) + createCookie('inv', JSON.stringify(inv)); + updateInv() + + + } + function updateInv() { + var inve = document.getElementById("inv"); + var inv = getCookie('inv'); + inv = JSON.parse(inv) + var balance = document.getElementById("balance"); + balance.innerHTML = getCookie("bank") + let i = "" + /* + for(let item of inv){ + console.log(item) + i+=("<div style='color:"+item.color+";'>{color:"+String(item.color)+", rarity:"+String(item.rarity)+", value: "+String(item.value)+"}</div>") + } + */ + for (let item of inv) { - //x[i].outerText="\ncontents: [ ... ] <div class='"+item+"'>"; + let t = '{color:' + String(item.color) + ', rarity:' + String(item.rarity) + ', value: ' + String(item.value) + '}' + + i += ("<div ondrop=\"drop(event," + inv.indexOf(item) + ")\" ondragstart=\"drag(event)\" ondragover=\"allowDrop(event)\" draggable=\"true\" onclick='s(" + item.value + "," + inv.indexOf(item) + ")' onmouseout='this.innerHTML = \"" + t + "\"'onmouseover='this.innerHTML=\"sell? (or drag to combine) \"' id='" + inv.indexOf(item) + "'style='color:" + item.color + ";'>" + t + "</div>") - x[0].hidden=!x[0].hidden - } - function roll(item) { - fetch(file) -.then(response => { - return response.json(); -}) -.then(data => { - var bank = getCookie('bank'); - var inv = getCookie('inv'); - var arr = JSON.parse(inv); - if(data.crates[item].price<=getCookie('bank')){ - //console.log(data.crates[item].contents[Math.floor(Math.random()*data.crates[item].contents.length)]) - var x = document.getElementById("popup"); - if(x.style.display != "block"){ //anti spam check thingy - x.style.display = "block"; - let select = Math.floor(Math.random()*data.crates[item].contents.length) - x.innerHTML="you got a:</br></br><code> >> "+(data.crates[item].contents[select].color) + (' ( r = '+data.crates[item].contents[select].rarity+ " && value = " +data.crates[item].contents[select].value + ")</code>").fontsize(1) - x.style.background=(data.crates[item].contents[select].color) - - - createCookie('bank', bank-data.crates[item].price); - console.log(getCookie('bank')) - arr.push(data.crates[item].contents[select]) - createCookie('inv', JSON.stringify(arr)); - updateInv() - setTimeout(function() { document.getElementById("popup").style.display = "none"; }, 1000); - - } - - }else { - var x = document.getElementById("popup"); - if(x.style.display != "block"){ //anti spam check thingy - x.style.display = "block"; - - x.innerHTML="you can't afford this:(" - x.style.background=("#000000") - setTimeout(function() { document.getElementById("popup").style.display = "none"; }, 1000); - } - } - -}) - - } - fetch(file) -.then(response => { - return response.json(); -}) - -.then(data => { - var intervalID = window.setInterval(myCallback, 500); - -function myCallback() { - updateInv() -} + inve.innerHTML = i + + } + function clear() { + createCookie('inv', JSON.stringify([])); + createCookie('bank', 15); + } + let file = "./crates.json" var bank = getCookie('bank'); var inv = getCookie('inv'); - inv = JSON.parse(inv) - document.write("<div style='position:absolute;right:5%;'>") - document.write("inv:{ //<a style='color:#696969;' href = \"https://github.com/squiresgrant\">https://github.com/squiresgrant</a> <a style='color:pink;' href=\"https://github.com/squiresgrant/colors\">v1.0+3</a><a style='color=purple;'>\<3</a></br>") - document.write("items:[</br>") -document.write("<div id='inv'>") - for(let item of inv){ - - let t = '{color:'+String(item.color)+', rarity:'+String(item.rarity)+', value: '+String(item.value)+'}' - document.write("<div id='"+inv.indexOf(item)+"'style='color:"+item.color+";'>"+t+"</div>") - let th = document.getElementById(inv.indexOf(item)); - th.onmouseover = function() { - th.innerHTML = "sell?" - } - th.onmouseout = function() { - th.innerHTML = t - } - th.onclick = function(){ - createCookie('bank', parseInt(getCookie('bank'))+parseInt(item.value)); - inv.splice(inv.indexOf(item),1) - createCookie('inv', JSON.stringify(inv)); - updateInv() - } + if (bank == "") { + createCookie('bank', 15); + var bank = getCookie('bank'); } - document.write("</div>") - document.write("],</br>") - document.write("bank:<div id='balance'>"+bank+"</br></div>") - document.write("}") - document.write("</div>") - for(let crate of data.crates){ - document.write("{</br>name: "+crate.name) - document.write("</br>price: "+crate.price) - document.write("<div onclick='min(\""+data.crates.indexOf(crate)+"\")'</br>contents: [<div class='"+data.crates.indexOf(crate)+"'>") - for(let item of crate.contents){ - if(item==crate.contents[0]){ - document.write("<div style='color:"+item.color+";'>{color:"+item.color+", rarity:"+item.rarity+", value:"+item.value+"}</div>") + if (inv == "") { + + createCookie('inv', JSON.stringify([])); + var inv = getCookie('inv'); + } + var arr = JSON.parse(inv); + // console.log(arr) + // console.log(bank) + // createCookie('bank', 15); + function min(item) { + console.log(item) + x = document.getElementsByClassName(item) + + //x[i].outerText="\ncontents: [ ... ] <div class='"+item+"'>"; + + x[0].hidden = !x[0].hidden + + } + function roll(item) { + fetch(file) + .then(response => { + return response.json(); + }) + .then(data => { + var bank = getCookie('bank'); + var inv = getCookie('inv'); + var arr = JSON.parse(inv); + if (data.crates[item].price <= getCookie('bank')) { + //console.log(data.crates[item].contents[Math.floor(Math.random()*data.crates[item].contents.length)]) + var x = document.getElementById("popup"); + if (x.style.display != "block") { //anti spam check thingy + x.style.display = "block"; + let select = Math.floor(Math.random() * data.crates[item].contents.length) + x.innerHTML = "you got a:</br></br><code> >> " + (data.crates[item].contents[select].color) + (' ( r = ' + data.crates[item].contents[select].rarity + " && value = " + data.crates[item].contents[select].value + ")</code>").fontsize(1) + x.style.background = (data.crates[item].contents[select].color) + + + createCookie('bank', bank - data.crates[item].price); + console.log(getCookie('bank')) + arr.push(data.crates[item].contents[select]) + createCookie('inv', JSON.stringify(arr)); + updateInv() + setTimeout(function () {document.getElementById("popup").style.display = "none";}, 1000); + + } + + } else { + var x = document.getElementById("popup"); + if (x.style.display != "block") { //anti spam check thingy + x.style.display = "block"; + + x.innerHTML = "you can't afford this:(" + x.style.background = ("#000000") + setTimeout(function () {document.getElementById("popup").style.display = "none";}, 1000); + } + } + + + }) + + } + fetch(file) + .then(response => { + return response.json(); + }) + + .then(data => { + var intervalID = window.setInterval(myCallback, 500); + + function myCallback() { + updateInv() + } + var bank = getCookie('bank'); + var inv = getCookie('inv'); + inv = JSON.parse(inv) + document.write("<div style='position:absolute;right:5%;'>") + document.write("inv:{ //<a style='color:#696969;' href = \"https://github.com/squiresgrant\">https://github.com/squiresgrant</a> <a style='color:pink;' href=\"https://github.com/squiresgrant/colors\">v1.1+2</a><a style='color=purple;'>\<3</a></br>") + document.write("items:[</br>") + document.write("<div id='inv'>") + for (let item of inv) { + + let t = '{color:' + String(item.color) + ', rarity:' + String(item.rarity) + ', value: ' + String(item.value) + '}' + document.write("<div draggable=\"true\" id='" + inv.indexOf(item) + "'style='color:" + item.color + ";'>" + t + "</div>") + let th = document.getElementById(inv.indexOf(item)); + th.onmouseover = function () { + th.innerHTML = "sell?" + } + th.onmouseout = function () { + th.innerHTML = t + } + th.onclick = function () { + createCookie('bank', parseInt(getCookie('bank')) + parseInt(item.value)); + inv.splice(inv.indexOf(item), 1) + createCookie('inv', JSON.stringify(inv)); + updateInv() + } + } + document.write("</div>") + document.write("],</br>") + document.write("bank:<div id='balance'>" + bank + "</br></div>") + document.write("}") + document.write("</div>") + for (let crate of data.crates) { + document.write("{</br>name: " + crate.name) + document.write("</br>price: " + crate.price) + document.write("<div onclick='min(\"" + data.crates.indexOf(crate) + "\")'</br>contents: [<div class='" + data.crates.indexOf(crate) + "'>") + for (let item of crate.contents) { + if (item == crate.contents[0]) { + document.write("<div style='color:" + item.color + ";'>{color:" + item.color + ", rarity:" + item.rarity + ", value:" + item.value + "}</div>") + } else { + document.write("<div style='color:" + item.color + ";'>{color:" + item.color + ", rarity:" + item.rarity + ", value:" + item.value + "}</div>") + } + + } + document.write("</div>]</div>}") + x = document.getElementsByClassName(data.crates.indexOf(crate)) + x[0].hidden = true + //x[i].outerText="\ncontents: [ ... ] <div class='"+item+"'>"; + + + + document.write("</br><button style=' padding: 3px 13px;font-size: 14px; display: inline-block;cursor: pointer;background-color: #FAFBFC; border: 1px solid rgba(27, 31, 35, 0.15); border-radius: 3px;'onclick='roll(" + data.crates.indexOf(crate) + ")'>roll</button>") + // document.write("<button style=' padding: 6px 16px;font-size: 14px; display: inline-block;cursor: pointer;background-color: #FAFBFC; border: 1px solid rgba(27, 31, 35, 0.15); border-radius: 6px;'onclick='createCookie(\"inv\", JSON.stringify([]));updateInv()'>reset</button>") + //document.write("<p>" + d.crates[0].price + "</p>") + + + } + + + return (0) + }).then((open) => { + var number = 5; //just for an example + //------------^ // Not sure but ; is a must in some places. + document.write('<div id = "popup"style="height:50%;position:absolute;width:100%;top:25%;background: #1a1a1a;color:#fff;">null</div>') + + var x = document.getElementById("popup"); + if (x.style.display === "none") { + x.style.display = "block"; } else { - document.write("<div style='color:"+item.color+";'>{color:"+item.color+", rarity:"+item.rarity+", value:"+item.value+"}</div>") + x.style.display = "none"; } - - } - document.write("</div>]</div>}") - x = document.getElementsByClassName(data.crates.indexOf(crate)) - x[0].hidden=true - //x[i].outerText="\ncontents: [ ... ] <div class='"+item+"'>"; - - - document.write("</br><button style=' padding: 6px 16px;font-size: 14px; display: inline-block;cursor: pointer;background-color: #FAFBFC; border: 1px solid rgba(27, 31, 35, 0.15); border-radius: 6px;'onclick='roll("+data.crates.indexOf(crate)+")'>roll</button>") - // document.write("<button style=' padding: 6px 16px;font-size: 14px; display: inline-block;cursor: pointer;background-color: #FAFBFC; border: 1px solid rgba(27, 31, 35, 0.15); border-radius: 6px;'onclick='createCookie(\"inv\", JSON.stringify([]));updateInv()'>reset</button>") - //document.write("<p>" + d.crates[0].price + "</p>") - - - } - - - return(0) - }).then((open)=>{ -var number = 5; //just for an example -//------------^ // Not sure but ; is a must in some places. -document.write('<div id = "popup"style="height:50%;position:absolute;width:100%;top:25%;background: #1a1a1a;color:#fff;">null</div>') - - var x = document.getElementById("popup"); - if (x.style.display === "none") { - x.style.display = "block"; - } else { - x.style.display = "none"; - } - - -}) + + }) // - - </script> - - </body> + </script> + + +</body> + </html>
\ No newline at end of file |