aboutsummaryrefslogtreecommitdiffstats
path: root/wacca/tachi/tachi_to_tachi_pb.js
blob: 286bbfee35e70bcbb63bc921cd45c28853f2d361 (plain) (blame)
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
javascript:(function(){
  var rows = document.querySelectorAll("table tbody tr"),
      songs = [];
  rows.forEach(function(row) {
    var songAnchor = row.querySelector("td:nth-child(4) a");
    if (!songAnchor) return;
    var cells = row.cells;
    var chartDiv = cells[1].querySelector("div.d-none.d-lg-block"),
        chart = chartDiv ? chartDiv.textContent.trim() : cells[1].textContent.trim();
    var songTitle = "", artist = "";
    if (songAnchor) {
      var parts = songAnchor.innerHTML.split("<br>");
      if (parts.length >= 2) {
        var temp = document.createElement("div");
        temp.innerHTML = parts[0];
        songTitle = temp.textContent.trim();
        temp.innerHTML = parts[1];
        artist = temp.textContent.trim();
      } else {
        songTitle = songAnchor.textContent.trim();
      }
    }

    var scoreCell = cells[5],
        scoreText = scoreCell.textContent.replace((scoreCell.querySelector("strong") || {}).textContent.trim() || "", "").trim(),
        scorePoints = parseInt(scoreText.replace(/,/g, ""));

    var judgementText = cells[6].textContent.trim(),
        judgements = judgementText.split("-").map(function(item) {
          return parseInt(item.trim());
        });

    var lamp = cells[7].textContent.trim();

    var timeCell = cells[10];
    var timeString = timeCell ? timeCell.querySelector("small")?.textContent?.trim() : null;
    var timeUnix = timeString ? new Date(timeString).getTime() : null;

    songs.push({
      difficulty: chart.split(" ")[0],
      matchType: "songTitle",
      identifier: songTitle,
      artist: artist,
      score: scorePoints,
      judgements: {
        marvelous: judgements[0],
        great: judgements[1],
        good: judgements[2],
        miss: judgements[3]
      },
      lamp: lamp,
      timeAchieved: timeUnix
    });
  });

  const results = {
    meta: {
      game: "wacca",
      playtype: "Single",
      service: "Tachi to Tachi PB Export"
    },
    scores: songs
  };

  var json = JSON.stringify(results, null, 2),
      blob = new Blob([json], { type: "application/json" }),
      url = URL.createObjectURL(blob),
      a = document.createElement("a");
  a.setAttribute("download", "songs.json");
  a.setAttribute("href", url);
  a.style.display = "none";
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
})();
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage