This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
VPModelFileTool/dist/js/scripts.min.js

1 line
1.6 KiB
JavaScript
Raw Normal View History

2023-01-20 18:55:28 +00:00
$(document).ready(function(){function t(){const t=["red_car","blue_car","green_car","orange_car","blue_bicycle","red_bicycle","green_bicycle","orange_bicycle"];return t[Math.floor(Math.random()*t.length)]}const e=$("#calculatorForm"),a=$("#formItems"),n=$("#item"),r=$("#itemcount"),i=$("#items"),o=$("#content"),l=$("#copyButton"),c=$("#downloadButton"),s=$("#minus"),u=$("#plus"),d=$("input[name='quant']");s.click(function(t){const e=parseInt(d.attr("value"));isNaN(e)?d.attr("value","0"):(e>d.attr("min")&&d.attr("value",(e-1).toString()),e-1==d.attr("min")&&$(this).attr("disabled",!0),$("#iteminput"+e).remove())}),u.click(function(e){const a=parseInt(d.attr("value"));if(isNaN(a))d.attr("value","0");else{if(a<d.attr("max")&&d.attr("value",(a+1).toString()),a==d.attr("max"))return void $(this).attr("disabled",!0);parseInt(d.attr("value"))>1?s.prop("disabled",!1):s.prop("disabled",!0),i.append('<div id="iteminput'+(a+1)+'" class="mb-3 w-50"><label for="item'+(a+1)+'">Model for damage '+(a+1)+':</label><input type="text" class="form-control" id="item'+(a+1)+'" name="item'+(a+1)+'" placeholder="cars/'+t()+'" required></div>')}}),n.change(function(){if(""!==this.value){a.show();const t=itemDamages[this.value];r.prop("max",t),u.prop("disabled",!1)}else a.hide()}),e.on("submit",function(t){t.preventDefault();const e=n.val(),a=parseInt(d.attr("value")),r=[];for(let t=0;t<a;t++)r[t]=$("#item"+(t+1)).val();const i=buildJSON(e,r);o.html(syntaxHighlight(i));const l="data:text/json;charset=utf-8,"+encodeURIComponent(i);return c.attr("href",l),c.attr("download",e+".json"),!1}),l.click(function(t){t.preventDefault(),navigator.clipboard.writeText(o.text())})});