-
Notifications
You must be signed in to change notification settings - Fork 2
/
50.js
133 lines (123 loc) · 4.23 KB
/
50.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
async function crawl(...levels) {
let domparser = new DOMParser();
console.log("popn data crawler running.\nPLZ wait a minute...");
const PLAY_DATA_URL = "https://p.eagate.573.jp/game/popn/unilab/playdata";
function resToText(res) {
return res.arrayBuffer().then((buffer) => {
if (res.headers.get("Content-Type").includes("UTF-8")) {
return new TextDecoder().decode(buffer);
} else {
return new TextDecoder("Shift_JIS").decode(buffer)
}
})
}
function searchPopperz() {
const POP_UPPER_HYPER_URL = "https://p.eagate.573.jp/game/popn/unilab/playdata/mu_lv.html?page=3&level=46";
return fetch(POP_UPPER_HYPER_URL)
.then(resToText)
.then((text) => domparser.parseFromString(text, "text/html"))
.then((doc) => doc.querySelectorAll("ul.mu_list_table > li"))
.then((lis) => {
return Array.from(lis)
.filter((li) => li.firstElementChild.className.startsWith("col"))
.find(li => li.firstElementChild.firstElementChild.textContent == "Popperz Chronicle")
.firstElementChild.firstElementChild.href
})
}
function whatever(url, level, hash) {
return fetch(url)
.then(resToText)
.then((text) => domparser.parseFromString(text, "text/html"))
.then((doc) => doc.querySelectorAll("ul.mu_list_table > li"))
.then((lis) => {
return Array.from(lis)
.filter((li) => li.firstElementChild.className.startsWith("col"))
.map((li) => [
li.children[3].textContent,
li.children[3].firstChild.src,
`${li.firstElementChild.firstElementChild.textContent}${li.firstElementChild.firstElementChild.href == hash ? "U" : ""}`,
])
.map(([score, medal, song]) => {
return {
song,
score,
medal,
level,
};
});
});
}
let arr = new Array();
for (let i = 0; i < 15; i++) {
arr.push(...(levels.map(level => [i, level])));
}
const popperzHash = await searchPopperz();
console.log(`popperzHash: ${popperzHash}`);
const promises = arr.map(([page, level]) =>
whatever(`${PLAY_DATA_URL}/mu_lv.html?page=${page}&level=${level}`, level, popperzHash)
);
const s = (await Promise.all(promises))
.flat()
.sort((a, b) => b.point - a.point);
console.log({ s })
return s;
}
async function render49(playData) {
function logMapElements(value, key, map) {
console.log(`m[${key}] = ${value.x}, ${value.y}`);
}
const csv49 = `25 o'clock the WORLD,1095,693
BabeL ~MODEL DD101~,263,1770
Blue River,678,2219
Chaos:Q,678,471
F/S,1095,896
НУМЛ,678,1997
ma plume,678,1547
L-an!ma,263,693
o†o,263,471
perditus†paradisus,678,693
Popperz ChronicleU,1095,471
Popperz Chronicle,678,1118
virkatoの主題によるperson09風超絶技巧変奏曲,263,1547
音楽,678,896
シュレーディンガーの猫,263,1997
序,678,1344
少年は空を辿る,263,1344
真超深TION,1095,1344
生命の焔纏いて,1095,1118
生命の環を紡いで,263,2219
辿る君を超えて,263,1118
ピアノ協奏曲第1番”蠍火”,263,896
ΔΟΓΜΑ,1095,2219`
let newCsv = csv49.trim();
const m = new Map();
newCsv.split('\n').map(line => {
var song = line.split(',');
m.set(song[0], { x: song[1], y: song[2] })
});
m.forEach(logMapElements);
document.body.innerHTML = `
<body>
<canvas id="canvas" width="1500" height="2344">
</canvas>
</body>
`;
const canvas = document.getElementById("canvas");
const bg = new Image();
bg.src = "https://rawcdn.githack.com/sonohoshi/children-s-sketchbook/96906144d80d0dc758520853a421eee62d10777b/img/50table.png";
bg.crossOrigin = 'anonymous';
bg.onload = function () {
canvas.getContext("2d").drawImage(bg, 0, 0)
playData.forEach(element => {
console.log(`try draw ${element.song}`);
var ctx = canvas.getContext("2d");
var xy = m.get(element.song);
var img = new Image();
img.onload = function () {
ctx.drawImage(img, xy.x, xy.y, 52, 52)
}
img.src = element.medal;
});
}
}
crawl(50).then(data => render49(data));