|
1 | 1 | // ==UserScript== |
2 | 2 | // @name MB: Display CAA image dimensions |
3 | 3 | // @description Displays the dimensions and size of images in the cover art archive. |
4 | | -// @version 2022.6.16 |
| 4 | +// @version 2022.6.17 |
5 | 5 | // @author ROpdebee |
6 | 6 | // @license MIT; https://opensource.org/licenses/MIT |
7 | 7 | // @namespace https://github.com/ROpdebee/mb-userscripts |
|
480 | 480 | })(); |
481 | 481 |
|
482 | 482 | function setupExports(cachePromise) { |
483 | | - const loadImageDimensions = _async(function (imgUrl) { |
484 | | - return _await(getCAAImageInfo(imgUrl), function (imageInfo) { |
485 | | - var _imageInfo$dimensions; |
486 | | - |
487 | | - return _objectSpread2(_objectSpread2({ |
488 | | - url: imgUrl |
489 | | - }, (_imageInfo$dimensions = imageInfo.dimensions) !== null && _imageInfo$dimensions !== void 0 ? _imageInfo$dimensions : { |
490 | | - width: 0, |
491 | | - height: 0 |
492 | | - }), {}, { |
493 | | - size: imageInfo.size, |
494 | | - format: imageInfo.fileType |
495 | | - }); |
| 483 | + const getImageDimensions = function getImageDimensions(imgUrl) { |
| 484 | + return _await(cachePromise, function (cache) { |
| 485 | + const image = new CAAImage(imgUrl, cache); |
| 486 | + return image.getDimensions(); |
496 | 487 | }); |
497 | | - }); |
498 | | - |
499 | | - const getCAAImageInfo = _async(function (imgUrl) { |
500 | | - if (new URL(imgUrl).hostname !== 'archive.org') { |
501 | | - throw new Error('Unsupported URL: Need direct image URL'); |
502 | | - } |
| 488 | + }; |
503 | 489 |
|
| 490 | + const getCAAImageInfo = function getCAAImageInfo(imgUrl) { |
504 | 491 | return _await(cachePromise, function (cache) { |
505 | 492 | const image = new CAAImage(imgUrl, cache); |
506 | 493 | return image.getImageInfo(); |
507 | 494 | }); |
508 | | - }); |
| 495 | + }; |
509 | 496 |
|
510 | 497 | function getDimensionsWhenInView(imgElement) { |
511 | 498 | logFailure(cachePromise.then(cache => { |
|
515 | 502 | } |
516 | 503 |
|
517 | 504 | window.ROpdebee_getDimensionsWhenInView = getDimensionsWhenInView; |
518 | | - window.ROpdebee_loadImageDimensions = loadImageDimensions; |
| 505 | + window.ROpdebee_getImageDimensions = getImageDimensions; |
519 | 506 | window.ROpdebee_getCAAImageInfo = getCAAImageInfo; |
520 | 507 | } |
521 | 508 |
|
|
0 commit comments