From 858aec971907af597c8c2b8b40bb4eee478d0bb2 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 20 Mar 2018 21:22:16 +0100 Subject: [PATCH] Improved average color usage --- mixins/AnimeGrid.pixy | 2 +- pages/profile/profile.pixy | 2 +- .../refresh-anime-average-color.go | 30 +------------------ scripts/AnimeNotifier.ts | 4 +++ 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/mixins/AnimeGrid.pixy b/mixins/AnimeGrid.pixy index 031e93f8..f9939b51 100644 --- a/mixins/AnimeGrid.pixy +++ b/mixins/AnimeGrid.pixy @@ -3,7 +3,7 @@ component AnimeGrid(animeList []*arn.Anime, user *arn.User) each anime in animeList .anime-grid-cell(data-added=(user != nil && user.AnimeList().Contains(anime.ID))) a.ajax(href="/anime/" + toString(anime.ID)) - img.anime-grid-image.lazy(data-src=anime.ImageLink("medium"), data-webp="true", alt=anime.Title.Romaji) + img.anime-grid-image.lazy(data-src=anime.ImageLink("medium"), data-webp="true", data-color=anime.Image.AverageColor, alt=anime.Title.Romaji) .anime-grid-title .anime-grid-title-text= anime.Title.ByUser(user) diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index ea8c660d..726f6d62 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -8,7 +8,7 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, each item in animeList.Items if item.Status == arn.AnimeListStatusWatching || item.Status == arn.AnimeListStatusCompleted a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.ByUser(user) + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")") - img.profile-watching-list-item-image.lazy(data-src=item.Anime().ImageLink("small"), data-webp="true", alt=item.Anime().Title.ByUser(user)) + img.profile-watching-list-item-image.lazy(data-src=item.Anime().ImageLink("small"), data-webp="true", data-color=item.Anime().Image.AverageColor, alt=item.Anime().Title.ByUser(user)) .footer .buttons diff --git a/patches/refresh-anime-average-color/refresh-anime-average-color.go b/patches/refresh-anime-average-color/refresh-anime-average-color.go index 24b5c593..f2eeecc6 100644 --- a/patches/refresh-anime-average-color/refresh-anime-average-color.go +++ b/patches/refresh-anime-average-color/refresh-anime-average-color.go @@ -73,34 +73,6 @@ func update(anime *arn.Anime, filePath string) { return } - width := img.Bounds().Dx() - height := img.Bounds().Dy() - - totalR := uint64(0) - totalG := uint64(0) - totalB := uint64(0) - - for x := 0; x < width; x++ { - for y := 0; y < height; y++ { - r, g, b, _ := img.At(x, y).RGBA() - totalR += uint64(r) - totalG += uint64(g) - totalB += uint64(b) - } - } - - pixels := uint64(width * height) - - const max = float64(65535) - averageR := float64(totalR/pixels) / max - averageG := float64(totalG/pixels) / max - averageB := float64(totalB/pixels) / max - - h, s, l := arn.RGBToHSL(averageR, averageG, averageB) - - anime.Image.AverageColor.Hue = h - anime.Image.AverageColor.Saturation = s - anime.Image.AverageColor.Lightness = l - + anime.Image.AverageColor = arn.GetAverageColor(img) anime.Save() } diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 07e8b824..c8f75164 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -574,6 +574,10 @@ export class AnimeNotifier { } element.onerror = () => { + if(element.classList.contains("element-found")) { + return + } + this.elementNotFound.queue(element) } } else {