-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowLogoOnLabelPage.user.js
68 lines (61 loc) · 2.88 KB
/
ShowLogoOnLabelPage.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ==UserScript==
// @author Brian Schweitzer
// @name Show logo image on label pages at MusicBrainz
// @description Show logo image on label pages at MusicBrainz, if the AR exists
// @version 2019.4.21.0
// @namespace https://github.com/brianfreud
// @downloadURL https://raw.githubusercontent.com/brianfreud/Userscripts/master/ShowLogoOnLabelPage.user.js
// @updateURL https://raw.githubusercontent.com/brianfreud/Userscripts/master/ShowLogoOnLabelPage.user.js
// @include http*://musicbrainz.org/label/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require https://raw.githubusercontent.com/brianfreud/Userscripts/master/getAverageRGB.js
/* global $, getAverageRGB */
/* eslint camelcase: off */
/* eslint capitalized-comments: off */
/* eslint dot-location: ["error", "property"] */
/* eslint-env es6, jquery */
/* eslint id-length: off */
/* eslint line-comment-position: off */
/* eslint max-len: off */
/* eslint multiline-comment-style: off */
/* eslint newline-per-chained-call: off */
/* eslint no-inline-comments: off */
/* eslint no-invalid-this: off */
/* eslint no-magic-numbers: off */
/* eslint no-whitespace-before-property: off */
/* eslint padded-blocks: off */
/* eslint prefer-destructuring: off */
/* eslint prefer-named-capture-group: off */
/* eslint quote-props: ["error", "as-needed"] */
/* eslint quotes: ["error", "backtick"] */
/* eslint sort-keys: off */
/* eslint sort-vars: off */
/* eslint spaced-comment: off */
/* eslint yoda: off */
// ==/UserScript==
{
const url = document.URL.split(`/`);
$.getJSON(`${url[0]}//musicbrainz.org/ws/2/label/${url[4]}?inc=url-rels&fmt=json`, (data) => {
'use strict';
const ar = data.relations.filter((rel) => rel.type === `logo`);
if (0 < ar.length) {
const imageURL = ar[0].url.resource,
img = new Image(),
src = `${imageURL}`;
$(`.commons-image`).css(`text-align`, `center`)
.append(`<img style="max-height: 150px;max-width: 215px;" src="${src}" class="LabelLogo"/>`);
// Solve the issue of all-white logos not being visible against the background
img.onload = function onload () {
const RGB = getAverageRGB(img),
rangeMin = 70,
rangeMax = 110,
rangeCheck = (val) => rangeMin <= val && rangeMax >= val;
if (rangeCheck(RGB.r) && rangeCheck(RGB.g) && rangeCheck(RGB.b)) {
$(`.LabelLogo`).css(`filter`, `invert(100%)`);
}
};
img.crossOrigin = ``;
img.src = src;
}
});
}