Add files via upload

This commit is contained in:
grant-kun 2022-04-03 20:28:38 -05:00 committed by GitHub
parent a29515b817
commit 9e5fa9eeb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 284 additions and 215 deletions

View File

@ -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}]}]}
{"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}]}
]}

View 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 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;
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev, index) {
ev.preventDefault();
}
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){
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>")
}
inve.innerHTML = i
}
function clear(){
createCookie('inv', JSON.stringify([]));
}
let file = "./crates.json"
var bank = getCookie('bank');
var data = ev.dataTransfer.getData("text");
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)
//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);
}
}
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)
}
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.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()
}
}
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>")
}
} else {
inv.splice(index, 1)
inv.splice(data, 1)
}
document.write("</div>]</div>}")
x = document.getElementsByClassName(data.crates.indexOf(crate))
x[0].hidden=true
//x[i].outerText="\ncontents: [ ... ] <div class='"+item+"'>";
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){
var inv = getCookie('inv');
inv = JSON.parse(inv)
inv.push(ne)
createCookie('inv', JSON.stringify(inv));
//}
}
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>")
}
*/
for (let item of inv) {
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>")
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";
}
inve.innerHTML = i
}
function clear() {
createCookie('inv', JSON.stringify([]));
createCookie('bank', 15);
}
let file = "./crates.json"
var bank = getCookie('bank');
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)
//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 {
x.style.display = "none";
}
})
//
</script>
</body>
</script>
</body>
</html>