mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-13 10:40:20 +00:00
better episode autocomplete
This commit is contained in:
parent
e7922bb8b3
commit
e1e4eb6a8b
2 changed files with 36 additions and 16 deletions
|
|
@ -234,8 +234,7 @@ async function alRequest(searchName, method) {
|
|||
name,
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
}`
|
||||
} else if (method == "UserLists") {
|
||||
variables.id = searchName
|
||||
query = `
|
||||
|
|
@ -249,8 +248,18 @@ async function alRequest(searchName, method) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
}`
|
||||
} else if (method == "SearchIDStatus") {
|
||||
variables.id = alID
|
||||
variables.mediaId = searchName
|
||||
query = `
|
||||
query ($id: Int, $mediaId: Int){
|
||||
MediaList(userId: $id, mediaId: $mediaId) {
|
||||
status
|
||||
progress
|
||||
repeat
|
||||
}
|
||||
}`
|
||||
}
|
||||
options.body = JSON.stringify({
|
||||
query: query,
|
||||
|
|
@ -261,22 +270,32 @@ async function alRequest(searchName, method) {
|
|||
json = await res.json();
|
||||
return json
|
||||
}
|
||||
function alEntry() {
|
||||
async function alEntry() {
|
||||
if (playerData.nowPlaying && playerData.nowPlaying[0] && localStorage.getItem("ALtoken")) {
|
||||
let query = `
|
||||
mutation ($id: Int, $status: MediaListStatus, $episode: Int) {
|
||||
SaveMediaListEntry (mediaId: $id, status: $status, progress: $episode) {
|
||||
let res = await alRequest(playerData.nowPlaying[0].id, "SearchIDStatus")
|
||||
if (res.data.MediaList.progress <= parseInt(playerData.nowPlaying[1])) {
|
||||
let query = `
|
||||
mutation ($id: Int, $status: MediaListStatus, $episode: Int, $repeat: Int) {
|
||||
SaveMediaListEntry (mediaId: $id, status: $status, progress: $episode, repeat: $repeat) {
|
||||
id
|
||||
status
|
||||
progress
|
||||
repeat
|
||||
}
|
||||
}`,
|
||||
variables = {
|
||||
id: playerData.nowPlaying[0].id,
|
||||
status: "CURRENT",
|
||||
episode: parseInt(playerData.nowPlaying[1])
|
||||
},
|
||||
options = {
|
||||
variables = {
|
||||
repeat: 0,
|
||||
id: playerData.nowPlaying[0].id,
|
||||
status: "CURRENT",
|
||||
episode: parseInt(playerData.nowPlaying[1])
|
||||
}
|
||||
if (parseInt(playerData.nowPlaying[1]) == playerData.nowPlaying[0].episodes) {
|
||||
variables.status = "COMPLETED"
|
||||
if (res.data.MediaList.status == "COMPLETED") {
|
||||
variables.repeat = res.data.MediaList.repeat + 1
|
||||
}
|
||||
}
|
||||
let options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + localStorage.getItem("ALtoken"),
|
||||
|
|
@ -288,7 +307,8 @@ mutation ($id: Int, $status: MediaListStatus, $episode: Int) {
|
|||
variables: variables
|
||||
})
|
||||
}
|
||||
fetch("https://graphql.anilist.co", options)
|
||||
fetch("https://graphql.anilist.co", options).catch((error) => console.error(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
let alResponse
|
||||
|
|
|
|||
|
|
@ -722,7 +722,7 @@ if ('mediaSession' in navigator) {
|
|||
|
||||
//AL entry auto add
|
||||
function checkCompletion() {
|
||||
if (!playerData.watched && typeof video !== 'undefined' && video.duration - 180 < video.currentTime && playerData.nowPlaying && playerData.nowPlaying[0]) {
|
||||
if (!playerData.watched && typeof video !== 'undefined' && video.duration - 180 < video.currentTime && playerData.nowPlaying && playerData.nowPlaying[0] && playerData.nowPlaying[0].episodes <= parseInt(playerData.nowPlaying[1])) {
|
||||
if (settings.other2) {
|
||||
alEntry()
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue