mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-14 12:22:26 +00:00
expand-rg: Prefer for-of loops over index loops
The IIFE from the previous lines 197 to 225 is no longer necessary as we are using scoped variables now (keyword let instead of var).
This commit is contained in:
parent
b9ae32964f
commit
4232ee8fc0
1 changed files with 40 additions and 42 deletions
|
@ -40,13 +40,13 @@
|
||||||
const MBID_REGEX = /[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/;
|
const MBID_REGEX = /[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/;
|
||||||
|
|
||||||
const releasesOrReleaseGroups = document.querySelectorAll("#content table.tbl > tbody > tr > td a[href^='/release']");
|
const releasesOrReleaseGroups = document.querySelectorAll("#content table.tbl > tbody > tr > td a[href^='/release']");
|
||||||
for (let r = 0; r < releasesOrReleaseGroups.length; r++) {
|
for (const entity of releasesOrReleaseGroups) {
|
||||||
let entityLink = releasesOrReleaseGroups[r].getAttribute('href');
|
const entityLink = entity.getAttribute('href');
|
||||||
if (entityLink.match(/\/release-group\//)) {
|
if (entityLink.match(/\/release-group\//)) {
|
||||||
inject_release_group_button(releasesOrReleaseGroups[r].parentNode);
|
inject_release_group_button(entity.parentNode);
|
||||||
} else if (!entityLink.match(/\/cover-art/)) {
|
} else if (!entityLink.match(/\/cover-art/)) {
|
||||||
// avoid injecting a second button for a release's cover art link
|
// avoid injecting a second button for a release's cover art link
|
||||||
inject_release_button(releasesOrReleaseGroups[r].parentNode);
|
inject_release_button(entity.parentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,17 +163,17 @@ function parse_release_group(json, mbid, parent, table) {
|
||||||
let releases = json.releases;
|
let releases = json.releases;
|
||||||
table.innerHTML = '';
|
table.innerHTML = '';
|
||||||
|
|
||||||
for (let i = 0; i < releases.length; i++) {
|
for (const release of releases) {
|
||||||
let release = releases[i],
|
let media = {},
|
||||||
media = {},
|
|
||||||
tracks = [],
|
tracks = [],
|
||||||
formats = [];
|
formats = [];
|
||||||
|
|
||||||
for (let j = 0; j < release.media.length; j++) {
|
for (const medium of release.media) {
|
||||||
let medium = release.media[j],
|
let format = medium.format,
|
||||||
format = medium.format,
|
|
||||||
count = medium['track-count'];
|
count = medium['track-count'];
|
||||||
if (format) format in media ? (media[format] += 1) : (media[format] = 1);
|
if (format) {
|
||||||
|
format in media ? (media[format] += 1) : (media[format] = 1);
|
||||||
|
}
|
||||||
tracks.push(count);
|
tracks.push(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +193,7 @@ function parse_release_group(json, mbid, parent, table) {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < releases.length; i++) {
|
for (const release of releases) {
|
||||||
(function (release) {
|
|
||||||
let track_tr = document.createElement('tr'),
|
let track_tr = document.createElement('tr'),
|
||||||
track_td = document.createElement('td'),
|
track_td = document.createElement('td'),
|
||||||
track_table = document.createElement('table'),
|
track_table = document.createElement('table'),
|
||||||
|
@ -217,12 +216,12 @@ function parse_release_group(json, mbid, parent, table) {
|
||||||
tr.appendChild(format_td);
|
tr.appendChild(format_td);
|
||||||
|
|
||||||
let columns = [release.tracks, release.date || '', release.country || '', release.status || ''];
|
let columns = [release.tracks, release.date || '', release.country || '', release.status || ''];
|
||||||
|
for (const column of columns) {
|
||||||
for (let i = 0; i < columns.length; i++) tr.appendChild(createElement('td', columns[i]));
|
tr.appendChild(createElement('td', column));
|
||||||
|
}
|
||||||
|
|
||||||
table.appendChild(tr);
|
table.appendChild(tr);
|
||||||
table.appendChild(track_tr);
|
table.appendChild(track_tr);
|
||||||
})(releases[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bottom_tr = document.createElement('tr'),
|
let bottom_tr = document.createElement('tr'),
|
||||||
|
@ -288,12 +287,11 @@ function parse_release(json, table) {
|
||||||
table.appendChild(bottom_tr);
|
table.appendChild(bottom_tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAC(obj) {
|
function createAC(artist_credit_array) {
|
||||||
let span = document.createElement('span');
|
let span = document.createElement('span');
|
||||||
|
|
||||||
for (let i = 0; i < obj.length; i++) {
|
for (const credit of artist_credit_array) {
|
||||||
let credit = obj[i],
|
let artist = credit.artist,
|
||||||
artist = credit.artist,
|
|
||||||
link = createLink(`/artist/${artist.id}`, credit.name || artist.name);
|
link = createLink(`/artist/${artist.id}`, credit.name || artist.name);
|
||||||
|
|
||||||
link.setAttribute('title', artist['sort-name']);
|
link.setAttribute('title', artist['sort-name']);
|
||||||
|
|
Loading…
Reference in a new issue