PageSourceSearch

https://sky-land.pl/skin/resources/js/skinCore.js

js sky-land.pl collected 2026-10-08 08:17:42 UTC 4,967 bytes, 178 lines download raw bytes

1$(document).ready(function(){
2  /* Initialize Variables */
3  var isSlim = false;
4  var skinURL;
5
6  /* OnSubmit uploadSkinForm */
7  $("#uploadSkinForm").on("submit", function(e){
8    e.preventDefault();
9    var formData = new FormData($("#uploadSkinForm")[0]);
10
11    $.ajax({
12      type : "POST",
13      url : "resources/server/skinCore.php",
14      cache : false,
15      contentType : false,
16      processData : false,
17      data : formData,
18      dataType : "JSON",
19      encode : true,
20    }).done(function(res){
21      if(res.success){
22        Swal.fire({
23          type : "success",
24          title : "Udało się!",
25          text : "Ciesz się nowym skinem! Jeśli jesteś na serwerze re-lognij aby zobaczyć zmiany!",
26          heightAuto : false
27        });
28      } else {
29        Swal.fire({
30          type : "error",
31          title : "Coś poszło nie tak!",
32          text : res.error,
33          heightAuto : false
34        });
35      }
36    }).fail(function(){
37      console.log("[ERROR] AJAX FAILED!");
38    });
39  });
40
41  /* If user changes uploadtype */
42  $("[id^=uploadtype-]").on("change", function(){
43    if($("#uploadtype-file")[0].checked == true){
44      $("#form-input-file").show();
45      $("#form-input-url").hide();
46      $("#input-url").prop("required", false);
47      $("#input-file").prop("required", true);
48    }
49    if($("#uploadtype-url")[0].checked == true){
50      $("#form-input-file").hide();
51      $("#form-input-url").show();
52      $("#input-url").prop("required", true);
53      $("#input-file").prop("required", false);
54    }
55  });
56
57  /* Initialize MineSkin */
58  var skinRender = new SkinRender({
59    autoResize : true,
60    controls : {
61      enabled : false,
62      zoom : false,
63      rotate : false,
64      pan : false
65    },
66    canvas : {
67      height : $("#skinViewerContainer")[0].offsetHeight,
68      width : $("#skinViewerContainer")[0].offsetWidth
69    },
70    camera : {
71      x : 15,
72      y : 25,
73      z : 24,
74      target: [0, 17, 0]
75    }
76  }, $("#skinViewerContainer")[0]);
77
78  /* Add some animate to a model in SkinPreview */
79  var startTime = Date.now();
80  var t;
81  $("#skinViewerContainer").on("skinRender", function(e){
82    if(!e.detail.playerModel){ return; }
83    e.detail.playerModel.rotation.y += 0.01;
84    t = (Date.now() - startTime) / 1000;
85    e.detail.playerModel.children[2].rotation.x = Math.sin(t * 5) / 2;
86    e.detail.playerModel.children[3].rotation.x = -Math.sin(t * 5) / 2;
87    e.detail.playerModel.children[4].rotation.x = Math.sin(t * 5) / 2;
88    e.detail.playerModel.children[5].rotation.x = -Math.sin(t * 5) / 2;
89  });
90
91  /* RENDER FUNCTION */
92  function render(){
93    if(skinURL === undefined){ return; }
94
95    if($('[id^=minerender-canvas-]')[0]){
96      skinRender.clearScene();
97    }
98
99    skinRender.render({
100      url : skinURL,
101      slim : isSlim
102    });
103  }
104
105  /* Check what type of skins (Alex or Steve) */
106  function skinChecker(callback){
107    var image = new Image();
108    image.crossOrigin = "Anonymous";
109    image.src = skinURL;
110
111    image.onload = function(){
112      var detectCanvas = document.createElement("canvas");
113      var detectCtx = detectCanvas.getContext("2d");
114      detectCanvas.width = image.width;
115      detectCanvas.height = image.height;
116      detectCtx.drawImage(image, 0, 0);
117
118      var px1 = detectCtx.getImageData(46, 52, 1, 12).data;
119      var px2 = detectCtx.getImageData(54, 20, 1, 12).data;
120      var allTransparent = true;
121      for(var i = 3; i < 12 * 4; i += 4){
122        if(px1[i] === 255){
123          allTransparent = false;
124          break;
125        }
126        if (px2[i] === 255) {
127          allTransparent = false;
128          break;
129        }
130      }
131
132      isSlim = allTransparent;
133      if(callback !== undefined){ callback(); }
134    }
135  }
136
137  /* If user changes skin file */
138  $("#input-file").on("change", function(event){
139    if($("#input-file")[0].files.length === 0){ return; }
140
141    skinURL = URL.createObjectURL(event.target.files[0]);
142    skinChecker(function(){
143      $("#skintype-alex").prop("checked", isSlim);
144      $("#skintype-steve").prop("checked", !isSlim);
145      render();
146    });
147  });
148
149  /* If user changes skin URL */
150  $("#input-url").on("change", function(){
151    if(!$("#input-url").val()){ return; }
152
153    skinURL = $("#input-url").val();
154    skinChecker(function(){
155      $("#skintype-alex").prop("checked", isSlim);
156      $("#skintype-steve").prop("checked", !isSlim);
157      render();
158    });
159  });
160
161  /* If user changes skintype radios */
162  $("[id^=skintype-]").on("change", function(){
163    isSlim = !isSlim;
164    render();
165  });
166
167  /* Change file name when user changes skin file */
168  $(".custom-file-input").on("change", function(){
169    var fileName = $(this).val().split("\\").pop();
170    if(fileName){
171      $(this).next(".custom-file-label").html(fileName);
172      console.log("File selected : " + fileName);
173    } else {
174      $(this).next(".custom-file-label").html("Choose skin...");
175      console.log("No file selected!");
176    }
177  });
178});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.