Last active
January 8, 2023 02:33
-
-
Save KatieFrogs/fb831031f47cf6a4ccb33aa38a59b358 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
// ==UserScript== | |
// @name Taiko Web Admin Helper | |
// @namespace taikoweb-adminhelper | |
// @version 2023.1.8 | |
// @author Katie Frogs | |
// @description Drag and drop tja files on the Admin New song page to automatically fill the values | |
// @match http://localhost/admin/songs/new | |
// @grant none | |
// ==/UserScript== |
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
// ==UserScript== | |
// @name Taiko Web Admin Helper | |
// @namespace taikoweb-adminhelper | |
// @version 2023.1.8 | |
// @author Katie Frogs | |
// @description Drag and drop tja files on the Admin New song page to automatically fill the values | |
// @match http://localhost/admin/songs/new | |
// @grant none | |
// ==/UserScript== | |
window.strings = {note: {}} | |
var languageList = ["ja", "en", "cn", "tw", "ko"] | |
var id = document.getElementById.bind(document) | |
var script = document.createElement("script") | |
script.src = "../../src/js/parsetja.js" | |
document.head.appendChild(script) | |
var dragTarget = null | |
document.addEventListener("dragenter", event => { | |
event.preventDefault() | |
dragTarget = event.target | |
}) | |
document.addEventListener("dragover", event => { | |
event.preventDefault() | |
event.dataTransfer.dropEffect = "copy" | |
}) | |
document.addEventListener("dragleave", event => { | |
if(dragTarget === event.target){ | |
event.preventDefault() | |
} | |
}) | |
document.addEventListener("drop", async event => { | |
event.preventDefault() | |
var item = event.dataTransfer.items[0] | |
var entry = item.webkitGetAsEntry() | |
if(entry && entry.isFile){ | |
var file = await new Promise((resolve, reject) => entry.file(file => resolve(new File([file], file.name)), reject)) | |
var reader = new FileReader() | |
var dataRaw = await new Promise((resolve, reject) => { | |
reader.onload = event => resolve(event.target.result) | |
reader.onerror = reject | |
return reader.readAsText(file, "sjis") | |
}) | |
var data = dataRaw ? dataRaw.replace(/\0/g, "").split("\n") : [] | |
var tja = new ParseTja(data, "oni", 0, 0, true) | |
for(var diff in tja.metadata){ | |
var meta = tja.metadata[diff] | |
id("title").value = meta.title || "" | |
var subtitle = meta.subtitle || "" | |
if(subtitle.startsWith("--") || subtitle.startsWith("++")){ | |
subtitle = subtitle.slice(2) | |
} | |
id("subtitle").value = subtitle | |
id("preview").value = meta.demostart || "" | |
id("lyrics").checked = meta.lyrics || "" | |
languageList.forEach(lang => { | |
id("title_" + lang).value = meta["title" + lang] || "" | |
id("subtitle_" + lang).value = meta["subtitle" + lang] || "" | |
}) | |
id("music_type").value = meta.wave.endsWith(".mp3") ? "mp3" : "ogg" | |
if(meta.maker){ | |
var makers = [...document.querySelectorAll("#maker_id>option")] | |
id("maker_id").value = makers.find(maker => maker.innerText.toLowerCase() === meta.maker.toLowerCase())?.value || "0" | |
}else{ | |
id("maker_id").value = "0" | |
} | |
break | |
} | |
for(var diff in tja.metadata){ | |
var meta = tja.metadata[diff] | |
id("course_" + diff).value = meta.level || "" | |
id("branch_" + diff).checked = meta.branch | |
} | |
id("offset").value = "0" | |
id("type").value = "tja" | |
id("gen_hash").checked = true | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment