108 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-04-02 07:34:16 +02:00
import AnimeNotifier from "../AnimeNotifier"
2018-03-09 14:48:00 +01:00
// newAnimeDiffIgnore
2019-04-22 15:02:51 +09:00
export async function newAnimeDiffIgnore(arn: AnimeNotifier, button: HTMLButtonElement) {
2018-03-09 14:48:00 +01:00
if(!confirm("Are you sure you want to permanently ignore this difference?")) {
return
}
2019-11-17 18:25:14 +09:00
const id = button.dataset.id
const hash = button.dataset.hash
2018-03-09 14:48:00 +01:00
2019-04-22 15:02:51 +09:00
try {
await arn.post(`/api/new/ignoreanimedifference`, {
id,
hash
})
2018-03-09 14:48:00 +01:00
arn.reloadContent()
2019-04-22 15:02:51 +09:00
} catch(err) {
arn.statusMessage.showError(err)
}
2018-03-10 10:15:05 +01:00
}
2018-03-18 21:41:13 +01:00
// Import Kitsu anime
export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
2018-04-17 12:27:54 +02:00
if(!confirm("Are you sure you want to import this anime?")) {
return
}
2019-11-17 18:25:14 +09:00
const newTab = window.open()
2019-04-22 15:02:51 +09:00
if(!newTab) {
arn.statusMessage.showError("Error opening new tab")
return
}
2019-11-17 18:25:14 +09:00
const animeId = button.dataset.id
const response = await fetch(`/api/import/kitsu/anime/${animeId}`, {
2018-03-18 21:41:13 +01:00
method: "POST",
credentials: "same-origin"
})
if(response.ok) {
newTab.location.href = `/kitsu/anime/${animeId}`
2018-03-18 21:41:13 +01:00
arn.reloadContent()
} else {
arn.statusMessage.showError(await response.text())
}
2018-04-17 00:02:24 +02:00
}
2018-04-17 12:27:54 +02:00
// Delete Kitsu anime
export async function deleteKitsuAnime(arn: AnimeNotifier, button: HTMLButtonElement) {
if(!confirm("Are you sure you want to delete this anime?")) {
return
}
2019-11-17 18:25:14 +09:00
const animeId = button.dataset.id
2018-04-17 12:27:54 +02:00
await arn.post(`/api/delete/kitsu/anime/${animeId}`)
arn.reloadContent()
}
2018-04-17 00:02:24 +02:00
// Multi-search anime
export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAreaElement) {
2019-11-17 18:25:14 +09:00
const results = document.getElementById("multi-search-anime") as HTMLDivElement
const animeTitles = textarea.value.split("\n")
2018-04-17 00:02:24 +02:00
results.innerHTML = ""
for(let i = 0; i < animeTitles.length; i++) {
console.log(animeTitles[i])
2019-11-17 18:25:14 +09:00
const response = await fetch("/_/anime-search/" + animeTitles[i])
const html = await response.text()
2018-04-17 00:02:24 +02:00
results.innerHTML += "<h3>" + animeTitles[i] + "</h3>" + html
}
results.classList.remove("hidden")
2018-11-05 21:33:06 +09:00
arn.onNewContent(results)
}
// Download soundtrack file
export async function downloadSoundTrackFile(arn: AnimeNotifier, button: HTMLButtonElement) {
2019-11-17 18:25:14 +09:00
const id = button.dataset.id
try {
await arn.post(`/api/soundtrack/${id}/download`)
arn.reloadContent()
} catch(err) {
arn.statusMessage.showError(err)
}
}
// Start background job
export async function startJob(arn: AnimeNotifier, button: HTMLButtonElement) {
2018-04-28 21:17:44 +02:00
if(button.dataset.running === "true") {
alert("Job is currently running!")
return
}
2019-11-17 18:25:14 +09:00
const jobName = button.dataset.job
if(!confirm(`Are you sure you want to start the "${jobName}" job?`)) {
return
}
await arn.post(`/api/job/${jobName}/start`)
arn.reloadContent()
}