From b376cb0725c6b532ae4a5a38f706f34753682112 Mon Sep 17 00:00:00 2001 From: qsniyg Date: Sun, 17 Dec 2023 23:47:06 +0000 Subject: [PATCH] Fix #1243 --- src/userscript.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++-- userscript.user.js | 40 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/userscript.ts b/src/userscript.ts index a6f99334..1b71821e 100644 --- a/src/userscript.ts +++ b/src/userscript.ts @@ -19942,7 +19942,7 @@ var $$IMU_EXPORT$$; }; var get_image_size = function(url, cb) { - var image = new Image(url); + var image = new Image(); var timeout = null; var finalcb = function(e) { @@ -109775,6 +109775,13 @@ var $$IMU_EXPORT$$; return src.replace(/(\/products\/+ui\/+[^/.?#]+)_(?:large|extralarge)\./, "$1."); } + if (domain === "cdn.passes.com") { + // thanks to newuser999 on discord for reporting: + // https://cdn.passes.com/profile/media/61bbf5f7-871e-41ef-809d-9aff2391a1af/profile-thumbnail.jpeg + // https://cdn.passes.com/profile/media/61bbf5f7-871e-41ef-809d-9aff2391a1af/profile-image.jpeg + return src.replace(/(\/profile\/+media\/+[-0-9a-f]{10,}\/+profile)-thumbnail\./, "$1-image."); + } + @@ -117378,6 +117385,35 @@ var $$IMU_EXPORT$$; } } + var get_image_dims = function(image:HTMLImageElement) { + let dims = { + height: image.naturalHeight, + width: image.naturalWidth + }; + + if (!image.complete || (dims.height && dims.width)) { + return dims; + } + + // Firefox returns a width of 0 for SVGs (https://github.com/qsniyg/maxurl/issues/1243) + let newimg = new Image(); + set_el_all_initial(newimg); + newimg.style.margin = "0"; + newimg.style.padding = "0"; + newimg.style.visibility = "hidden"; + + newimg.src = image.src; + + document.documentElement.appendChild(newimg); + dims = { + width: newimg.offsetWidth, + height: newimg.offsetHeight + }; + document.documentElement.removeChild(newimg); + + return dims; + }; + var get_window_url = function() { return native_URL;// || window.URL || window.webkitURL; }; @@ -117561,7 +117597,8 @@ var $$IMU_EXPORT$$; img.onload = function () { end_cbs(); - if (img.naturalWidth === 0 || img.naturalHeight === 0) { + let dims = get_image_dims(img); + if (dims.width === 0 || dims.height === 0) { if (_nir_debug_) console_log("naturalWidth or naturalHeight == 0", img); @@ -120150,6 +120187,12 @@ var $$IMU_EXPORT$$; el.width.animVal.value, el.height.animVal.value ]; + } else if (el_tagname === "IMG") { + let dims = get_image_dims(el); + return [ + dims.width, + dims.height + ] } else if (el_tagname === "IMG" || el_tagname === "PICTURE") { return [ el.naturalWidth, diff --git a/userscript.user.js b/userscript.user.js index 6a0ddf94..a2b7cb6e 100644 --- a/userscript.user.js +++ b/userscript.user.js @@ -18669,7 +18669,7 @@ var $$IMU_EXPORT$$; return strip_whitespace_simple(normalize_whitespace(str)); }; var get_image_size = function(url, cb) { - var image = new Image(url); + var image = new Image(); var timeout = null; var finalcb = function(e) { image.onload = null; @@ -98498,6 +98498,12 @@ var $$IMU_EXPORT$$; // https://content-jp.umgi.net/products/ui/UICY-79658_MBe.jpg return src.replace(/(\/products\/+ui\/+[^/.?#]+)_(?:large|extralarge)\./, "$1."); } + if (domain === "cdn.passes.com") { + // thanks to newuser999 on discord for reporting: + // https://cdn.passes.com/profile/media/61bbf5f7-871e-41ef-809d-9aff2391a1af/profile-thumbnail.jpeg + // https://cdn.passes.com/profile/media/61bbf5f7-871e-41ef-809d-9aff2391a1af/profile-image.jpeg + return src.replace(/(\/profile\/+media\/+[-0-9a-f]{10,}\/+profile)-thumbnail\./, "$1-image."); + } // -- general rules -- if (src.match(/\/ImageGen\.ashx\?/)) { // http://www.lookalikes.info/umbraco/ImageGen.ashx?image=/media/97522/nick%20hewer%20-%20mark%20brown.jpeg&width=250&constrain=true @@ -104708,6 +104714,29 @@ var $$IMU_EXPORT$$; cb(el); } } + var get_image_dims = function(image) { + var dims = { + height: image.naturalHeight, + width: image.naturalWidth + }; + if (!image.complete || (dims.height && dims.width)) { + return dims; + } + // Firefox returns a width of 0 for SVGs (https://github.com/qsniyg/maxurl/issues/1243) + var newimg = new Image(); + set_el_all_initial(newimg); + newimg.style.margin = "0"; + newimg.style.padding = "0"; + newimg.style.visibility = "hidden"; + newimg.src = image.src; + document.documentElement.appendChild(newimg); + dims = { + width: newimg.offsetWidth, + height: newimg.offsetHeight + }; + document.documentElement.removeChild(newimg); + return dims; + }; var get_window_url = function() { return native_URL; // || window.URL || window.webkitURL; }; @@ -104852,7 +104881,8 @@ var $$IMU_EXPORT$$; }; img.onload = function() { end_cbs(); - if (img.naturalWidth === 0 || img.naturalHeight === 0) { + var dims = get_image_dims(img); + if (dims.width === 0 || dims.height === 0) { if (_nir_debug_) console_log("naturalWidth or naturalHeight == 0", img); return err_cb(); @@ -106986,6 +107016,12 @@ var $$IMU_EXPORT$$; el.width.animVal.value, el.height.animVal.value ]; + } else if (el_tagname === "IMG") { + var dims = get_image_dims(el); + return [ + dims.width, + dims.height + ]; } else if (el_tagname === "IMG" || el_tagname === "PICTURE") { return [ el.naturalWidth,