forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.js
More file actions
93 lines (84 loc) · 2.54 KB
/
items.js
File metadata and controls
93 lines (84 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Generated by CoffeeScript 2.5.1
(function() {
var JSSoup, fs, http, https, options, removeBg, request;
request = require('request');
JSSoup = require('jssoup').default;
fs = require('fs');
http = require("http");
https = require("https");
options = {
method: 'GET',
url: "https://www.digminecraft.com/lists/item_id_list_pc.php",
encoding: "utf-8"
};
removeBg = function() {
var dir_path, replaceColor;
replaceColor = require('replace-color');
fs = require("fs");
removeBg = function(filePath) {
return replaceColor({
image: filePath,
colors: {
type: 'rgb',
targetColor: [139, 139, 139],
replaceColor: [0, 0, 0, 0]
}
}, function(err, jimpObject) {
if (err) {
return console.log(err);
}
return jimpObject.write(filePath, function(err) {
if (err) {
return console.log(err);
}
});
});
};
dir_path = __dirname + "/client/assets/items/";
return fs.readdir(dir_path, function(err, files) {
files.forEach(function(file) {
var filePath;
filePath = __dirname + "/client/assets/items/" + file;
removeBg(filePath);
});
});
};
request(options, function(err, response, body) {
var i, ile, j, k, l, last, len, map, ref, ref1, soup, title, type, war, zal;
soup = new JSSoup(body);
map = {};
last = null;
ile = 0;
zal = 0;
ref = soup.findAll("td");
for (k = 0, len = ref.length; k < len; k++) {
i = ref[k];
if ((i.text !== " ") && (i.text.includes("minecraft:"))) {
ile += 1;
title = i.text.split("(")[0];
war = 0;
for (j = l = 0, ref1 = i.text.length - 1; (0 <= ref1 ? l <= ref1 : l >= ref1); j = 0 <= ref1 ? ++l : --l) {
if (i.text[j] === "(") {
war = j;
}
}
type = (i.text.substr(war + 11)).split(")")[0];
(function(type, url) {
var file;
file = fs.createWriteStream(`${__dirname}/client/assets/items/${type}.png`);
return https.get(url, function(response) {
console.log(type, url);
response.pipe(file);
zal += 1;
if (ile === zal) {
console.log("Removing gray backgrounds...");
return removeBg();
}
});
})(type, `https://www.digminecraft.com${last}`);
} else if (i.find("img") !== void 0) {
last = i.find("img").attrs["data-src"];
}
}
});
}).call(this);