From d771b6529fbfe620d36cc3fba924f20bb468978a Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Tue, 7 Jun 2022 12:18:03 -0500 Subject: [PATCH] Add button to erase all discovered timestamps --- .../Configuration/configPage.html | 34 +++++++++++++++++-- .../Controllers/SkipIntroController.cs | 14 ++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index 8d5a3a2..7bd971e 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -35,7 +35,7 @@
- +
Seconds after the introduction starts to hide the skip prompt at.
@@ -45,6 +45,16 @@ +
+ + + +

+ Erasing introduction timestamps is only necessary after upgrading the plugin if specifically + requested to do so in the plugin's changelog. +

@@ -129,6 +139,7 @@ var selectEpisode2 = document.querySelector("select#troubleshooterEpisode2"); var txtOffset = document.querySelector("input#offset"); var timeContainer = document.querySelector("span#timestampContainer"); + var btnEraseTimestamps = document.querySelector("button#btnEraseTimestamps"); var windowHashInterval = 0; // config page loaded, populate show names @@ -226,10 +237,11 @@ } // make an authenticated GET to the server and parse the response as JSON - async function getJson(url) { + async function getJson(url, method = "GET") { url = ApiClient.serverAddress() + "/" + url; const reqInit = { + method: method, headers: { "Authorization": "MediaBrowser Token=" + ApiClient.accessToken() } @@ -370,7 +382,8 @@ // check that the user is still on the configuration page function checkWindowHash() { - if (location.hash === "#!/configurationpage?name=Intro%20Skipper") { + const h = location.hash; + if (h === "#!/configurationpage?name=Intro%20Skipper" || h.includes("#!/dialog")) { return; } @@ -420,6 +433,21 @@ selectSeason.addEventListener("change", seasonChanged); selectEpisode1.addEventListener("change", episodeChanged); selectEpisode2.addEventListener("change", episodeChanged); + btnEraseTimestamps.addEventListener("click", (e) => { + Dashboard.confirm( + "Are you sure you want to erase all previously discovered introduction timestamps?", + "Confirm timestamp erasure", + (result) => { + if (!result) { + return; + } + + // reset all intro timestamps on the server so a new fingerprint comparison algorithm can be tested + getJson("Intros/EraseTimestamps", "POST"); + }); + + e.preventDefault(); + }); document.addEventListener("keydown", keyDown); windowHashInterval = setInterval(checkWindowHash, 2500); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs index 343641a..d2bf61a 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs @@ -50,4 +50,18 @@ public class SkipIntroController : ControllerBase return intro; } + + /// + /// Erases all previously discovered introduction timestamps. + /// + /// Operation successful. + /// No content. + [Authorize(Policy = "RequiresElevation")] + [HttpPost("Intros/EraseTimestamps")] + public ActionResult ResetIntroTimestamps() + { + Plugin.Instance!.Intros.Clear(); + Plugin.Instance!.SaveTimestamps(); + return NoContent(); + } }