Last active
September 3, 2021 01:33
-
-
Save nogic1008/253c99b0d961febe5c9a623045b5df7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==ClosureCompiler== | |
// @output_file_name eagate.min.js | |
// @compilation_level ADVANCED_OPTIMIZATIONS | |
// @language_out ECMASCRIPT_2015 | |
// ==/ClosureCompiler== | |
(function ($, location) { | |
const idRegex = /^.+\/ddr\/ddra20\/p.+=([01689bdiloqDIOPQ]{32}).*$/; | |
const srcRegex = /^.+\/ddr\/ddra20\/p\/images\/play_data\/(.+)\.png$/; | |
const playStyleRegex = /^.+\/ddr\/ddra20\/p.+_data_(double|single)\.html.*/; | |
const apiBaseUri = "https://www.ddradar.app/api/v1/scores"; | |
const dt = $("#data_tbl"); | |
if (!dt.length) { | |
alert("DDR A20PLUSの楽曲データ一覧ページではありません。"); | |
return; | |
} | |
const playStyle = location.href.replace(playStyleRegex, "$1"); | |
if (!playStyle) { | |
alert("DDR A20PLUSの楽曲データ一覧ページではありません。"); | |
return; | |
} | |
const result = {}; | |
$(".data", dt).each(function () { | |
// Get songName & songId from first column | |
const songId = $("td:first > .music_info:first", this) | |
.attr("href") | |
.replace(idRegex, "$1"); | |
const jacketAlt = $("td:first > .music_info:first > img:first", this).attr("alt"); | |
const songName = $("td:first > .music_info:first", this).text() || jacketAlt; | |
result[songId] = []; | |
$(".rank", this).each(function () { | |
// Get difficulty | |
const id = $(this).attr("id"); | |
const difficulty = | |
id === "beginner" | |
? 0 | |
: id === "basic" | |
? 1 | |
: id === "difficult" | |
? 2 | |
: id === "expert" | |
? 3 | |
: 4; | |
// Get score | |
const scoreText = $(".data_score:first", this).text().trim(); | |
const score = parseInt(scoreText, 10); | |
if (!Number.isInteger(score)) return; | |
// Get clearLamp | |
const fileName = $(".music_info:first > img:eq(1)", this) | |
.attr("src") | |
.replace(srcRegex, "$1"); | |
const rankImageFileName = $(".music_info:first > img:first", this) | |
.attr("src") | |
.replace(srcRegex, "$1"); | |
const isFailed = rankImageFileName === "rank_s_e"; | |
const clearLamp = | |
fileName === "full_mar" | |
? 7 | |
: fileName === "full_perfect" | |
? 6 | |
: fileName === "full_great" | |
? 5 | |
: fileName === "full_good" | |
? 4 | |
: isFailed | |
? 0 | |
: score === 0 | |
? 1 | |
: 2; | |
// Get rank | |
const rank = isFailed | |
? "E" | |
: score >= 990000 | |
? "AAA" | |
: score >= 950000 | |
? "AA+" | |
: score >= 900000 | |
? "AA" | |
: score >= 890000 | |
? "AA-" | |
: score >= 850000 | |
? "A+" | |
: score >= 800000 | |
? "A" | |
: score >= 790000 | |
? "A-" | |
: score >= 750000 | |
? "B+" | |
: score >= 700000 | |
? "B" | |
: score >= 690000 | |
? "B-" | |
: score >= 650000 | |
? "C+" | |
: score >= 600000 | |
? "C" | |
: score >= 590000 | |
? "C-" | |
: score >= 550000 | |
? "D+" | |
: "D"; | |
result[songId].push({ | |
playStyle: playStyle === "single" ? 1 : 2, | |
difficulty, | |
songName, | |
score, | |
clearLamp, | |
rank, | |
}); | |
}); | |
}); | |
const userId = prompt("DDRadarのユーザーIDを入力"); | |
const password = prompt("インポート用に設定したパスワードを入力"); | |
if (!password) return; | |
Promise.all( | |
Object.entries(result).map(([songId, scores]) => | |
fetch(`${apiBaseUri}/${songId}/${userId}`, { | |
method: "post", | |
body: JSON.stringify(scores), | |
headers: { "Content-Type": "application/json" }, | |
mode: "cors", | |
}) | |
.then(() => | |
$("div#container").prepend( | |
`<div class="ddradar_added">「${scores[0].songName}」のインポートが完了しました。</div>` | |
) | |
) | |
.catch((e) => | |
$("div#container").prepend( | |
`<div class="ddradar_added" style="color:red;font-weight:bold;">「${scores[0].songName}」のインポートに失敗しました。(${e})</div>` | |
) | |
) | |
) | |
).then(() => { | |
alert("インポートが完了しました。"); | |
$(".ddradar_added").remove(); | |
}); | |
})($, location); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment