|
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.7.27.2 |
| 4 | +// @version 2022.8.8 |
5 | 5 | // @author ROpdebee |
6 | 6 | // @license MIT; https://opensource.org/licenses/MIT |
7 | 7 | // @namespace https://github.com/ROpdebee/mb-userscripts |
8 | 8 | // @homepageURL https://github.com/ROpdebee/mb-userscripts |
9 | 9 | // @supportURL https://github.com/ROpdebee/mb-userscripts/issues |
10 | 10 | // @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.user.js |
11 | 11 | // @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.meta.js |
12 | | -// @match *://*.musicbrainz.org/release/* |
13 | | -// @match *://*.musicbrainz.org/release-group/* |
14 | | -// @match *://*.musicbrainz.org/edit/* |
15 | | -// @match *://*.musicbrainz.org/*/edits* |
16 | | -// @match *://*.musicbrainz.org/user/*/votes |
17 | | -// @match *://*.musicbrainz.org/*/open_edits |
18 | | -// @exclude *://*.musicbrainz.org/release/*/edit |
19 | | -// @exclude *://*.musicbrainz.org/release/*/edit-relationships |
20 | | -// @exclude *://*.musicbrainz.org/release-group/*/edit |
| 12 | +// @include /^https?://(\w+\.)?musicbrainz\.org/edit/\d+([?#]|$)/ |
| 13 | +// @include /^https?://(\w+\.)?musicbrainz\.org/edit/(open|subscribed(_editors)?)([?#]|$)/ |
| 14 | +// @include /^https?://(\w+\.)?musicbrainz\.org/(area|artist|collection|event|instrument|label|place|recording|release|release-group|series|work|url)/[a-f\d-]{36}/(open_)?edits([?#]|$)/ |
| 15 | +// @include /^https?://(\w+\.)?musicbrainz\.org/user/[^/]+/edits(/\w+)?([?#]|$)/ |
| 16 | +// @include /^https?://(\w+\.)?musicbrainz\.org/user/[^/]+/votes([?#]|$)/ |
| 17 | +// @include /^https?://(\w+\.)?musicbrainz\.org/search/edits\?.+?(#.+?)?$/ |
| 18 | +// @include /^https?://(\w+\.)?musicbrainz\.org/release(-group)?/[a-f\d-]{36}(/.+?)?([?#]|$)/ |
| 19 | +// @exclude /^https?://(\w+\.)?musicbrainz\.org/release(-group)?/[a-f\d-]{36}/edit([?#]|$)/ |
| 20 | +// @exclude /^https?://(\w+\.)?musicbrainz\.org/release-group/[a-f\d-]{36}/edit-relationships([?#]|$)/ |
21 | 21 | // @run-at document-start |
22 | 22 | // @grant none |
23 | 23 | // ==/UserScript== |
|
535 | 535 | })(); |
536 | 536 |
|
537 | 537 | function setupExports(cachePromise) { |
538 | | - const loadImageDimensions = _async(function (imgUrl) { |
539 | | - return _await(getCAAImageInfo(imgUrl), function (imageInfo) { |
540 | | - var _imageInfo$dimensions; |
541 | | - |
542 | | - return _objectSpread2(_objectSpread2({ |
543 | | - url: imgUrl |
544 | | - }, (_imageInfo$dimensions = imageInfo.dimensions) !== null && _imageInfo$dimensions !== void 0 ? _imageInfo$dimensions : { |
545 | | - width: 0, |
546 | | - height: 0 |
547 | | - }), {}, { |
548 | | - size: imageInfo.size, |
549 | | - format: imageInfo.fileType |
550 | | - }); |
| 538 | + const getImageDimensions = function getImageDimensions(imgUrl) { |
| 539 | + return _await(cachePromise, function (cache) { |
| 540 | + const image = new CAAImage(imgUrl, cache); |
| 541 | + return image.getDimensions(); |
551 | 542 | }); |
552 | | - }); |
553 | | - |
554 | | - const getCAAImageInfo = _async(function (imgUrl) { |
555 | | - if (new URL(imgUrl).hostname !== 'archive.org') { |
556 | | - throw new Error('Unsupported URL: Need direct image URL'); |
557 | | - } |
| 543 | + }; |
558 | 544 |
|
| 545 | + const getCAAImageInfo = function getCAAImageInfo(imgUrl) { |
559 | 546 | return _await(cachePromise, function (cache) { |
560 | 547 | const image = new CAAImage(imgUrl, cache); |
561 | 548 | return image.getImageInfo(); |
562 | 549 | }); |
563 | | - }); |
| 550 | + }; |
564 | 551 |
|
565 | 552 | function getDimensionsWhenInView(imgElement) { |
566 | 553 | logFailure(cachePromise.then(cache => { |
|
570 | 557 | } |
571 | 558 |
|
572 | 559 | window.ROpdebee_getDimensionsWhenInView = getDimensionsWhenInView; |
573 | | - window.ROpdebee_loadImageDimensions = loadImageDimensions; |
| 560 | + window.ROpdebee_getImageDimensions = getImageDimensions; |
574 | 561 | window.ROpdebee_getCAAImageInfo = getCAAImageInfo; |
575 | 562 | } |
576 | 563 |
|
|
0 commit comments