From 7fc39fe703b81422fcc2c18c2c2f7f8d3caca7df Mon Sep 17 00:00:00 2001 From: ThaUnknown Date: Tue, 27 Oct 2020 00:15:05 +0100 Subject: [PATCH] anilist sync, ui scaling --- app/index.html | 23 +++++++++++++++++++++-- app/js/animeHandler.js | 30 ++++++++++++++++++++++++++++++ app/js/playerHandler.js | 10 ++++++++++ app/js/settingsHandler.js | 18 +++++++++++++++--- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/app/index.html b/app/index.html index dcc0154..f3c75e0 100644 --- a/app/index.html +++ b/app/index.html @@ -11,8 +11,7 @@ - - + Miru @@ -349,6 +348,26 @@ + +

+ Other +

+
+
+ UI Scale +
+ +
+ % +
+
+
+ + +
+ + +

Restart may be required for some settings to take effect. diff --git a/app/js/animeHandler.js b/app/js/animeHandler.js index 5dc5058..1ce2b94 100644 --- a/app/js/animeHandler.js +++ b/app/js/animeHandler.js @@ -128,6 +128,36 @@ async function alRequest(a, b) { json = await res.json(); return json } +function alEntry() { + if (store[playerData.nowPlaying[0]]) { + let query = ` +mutation ($id: Int, $status: MediaListStatus, $episode: Int) { + SaveMediaListEntry (mediaId: $id, status: $status, progress: $episode) { + id + status + progress + } +}`, + variables = { + id: parseInt(store[playerData.nowPlaying[0]].id), + status: "CURRENT", + episode: parseInt(playerData.nowPlaying[1]) + }, + options = { + method: 'POST', + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem("ALtoken"), + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + body: JSON.stringify({ + query: query, + variables: variables + }) + } + fetch("https://graphql.anilist.co", options) + } +} let alResponse async function searchAnime(a) { let frag = document.createDocumentFragment(), diff --git a/app/js/playerHandler.js b/app/js/playerHandler.js index 6bd2cb3..4e5d2f8 100644 --- a/app/js/playerHandler.js +++ b/app/js/playerHandler.js @@ -37,6 +37,7 @@ function resetVideo() { fonts: [], nowPlaying: undefined, selected: undefined, + completed: undefined, thumbnails: [] } video.pause() @@ -67,6 +68,7 @@ function resetVideo() { video.addEventListener("waiting", isBuffering); video.addEventListener("timeupdate", updateDisplay); video.addEventListener("timeupdate", updatePositionState); + video.addEventListener("timeupdate", checkCompletion); player.prepend(video) } // progress bar and display @@ -498,4 +500,12 @@ if ('mediaSession' in navigator) { navigator.mediaSession.setActionHandler('nexttrack', btnnext); } +//AL entry auto add +function checkCompletion(){ + if(settings.other2 && video.duration - 120 < video.currentTime && !playerData.completed){ + playerData.completed = true + alEntry() + } +} + resetVideo() \ No newline at end of file diff --git a/app/js/settingsHandler.js b/app/js/settingsHandler.js index b438349..ef56cc1 100644 --- a/app/js/settingsHandler.js +++ b/app/js/settingsHandler.js @@ -13,7 +13,9 @@ const settingsElements = { torrent1: torrent1, torrent2: torrent2, torrent3: torrent3, - torrent4: torrent4 + torrent4: torrent4, + other1: other1, + other2: other2 } let settings function restoreDefaults() { @@ -33,7 +35,9 @@ function restoreDefaults() { torrent1: "1080", torrent2: false, torrent3: true, - torrent4: "https://subsplease.org/rss/?r=" + torrent4: "https://subsplease.org/rss/?r=", + other1: 100, + other2: true } localStorage.setItem("settings", JSON.stringify(settings)) renderSettings() @@ -69,4 +73,12 @@ if (!localStorage.getItem("settings")) { settings = JSON.parse(localStorage.getItem("settings")) renderSettings() setRes.addEventListener("click", restoreDefaults) -settingsTab.addEventListener("click", applySettings) \ No newline at end of file +settingsTab.addEventListener("click", applySettings) + +let searchParams = new URLSearchParams(location.href) +if (searchParams.get("access_token")) { + localStorage.setItem("ALtoken", searchParams.get("access_token")) + window.location = "/app/#settingsTab" +} + +document.body.style.zoom = settings.other1 + "%" \ No newline at end of file