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