From 0a705f21581dfcb672e4d1b58a0a332c8ea2f5e3 Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Tue, 11 Apr 2023 23:52:27 +0200 Subject: [PATCH] Show image resolution using the popups naturalHeight/Width fields This shows the resolution after the image has loaded in the element. --- src/popup/App.vue | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/popup/App.vue b/src/popup/App.vue index 45e1d27..37959cb 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -31,6 +31,7 @@ let cancelSource = ref(undefined); let autocompleteIndex = ref(-1); let selectedSiteId = ref(undefined); let isSearchingForSimilarPosts = ref(0); +let imgEl = ref(null); const selectedInstance = computed(() => { if (selectedSiteId.value) { @@ -384,6 +385,19 @@ function getUpdatedTagsText(count: number) { return `Updated ${count} tag${count > 1 ? "s" : ""}`; } +// Get image width and height from the element. +// This works because we load the full-resolution image in the element. +// This code might stop showing correct resolutions if/when we implement a progressive image loading. +function onloadImage(post: ScrapedPostDetails | undefined) { + // I guess post/selectedPost could have a race condition here? + // Seems very unlikely though, as the load event gets cancelled as soon as we change the :src attribute. + // A race condition might even be impossible then. + console.log("Setting resolution! " + imgEl.value?.naturalHeight); + if (post && !post.resolution && imgEl.value) { + post.resolution = [imgEl.value.naturalWidth, imgEl.value.naturalHeight]; + } +} + onMounted(async () => { config = await Config.load(); selectedSiteId.value = config.selectedSiteId; @@ -666,7 +680,12 @@ useDark();