mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-13 20:02:27 +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 releasesOrReleaseGroups = document.querySelectorAll("#content table.tbl > tbody > tr > td a[href^='/release']");
|
||||
for (let r = 0; r < releasesOrReleaseGroups.length; r++) {
|
||||
let entityLink = releasesOrReleaseGroups[r].getAttribute('href');
|
||||
for (const entity of releasesOrReleaseGroups) {
|
||||
const entityLink = entity.getAttribute('href');
|
||||
if (entityLink.match(/\/release-group\//)) {
|
||||
inject_release_group_button(releasesOrReleaseGroups[r].parentNode);
|
||||
inject_release_group_button(entity.parentNode);
|
||||
} else if (!entityLink.match(/\/cover-art/)) {
|
||||
// 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;
|
||||
table.innerHTML = '';
|
||||
|
||||
for (let i = 0; i < releases.length; i++) {
|
||||
let release = releases[i],
|
||||
media = {},
|
||||
for (const release of releases) {
|
||||
let media = {},
|
||||
tracks = [],
|
||||
formats = [];
|
||||
|
||||
for (let j = 0; j < release.media.length; j++) {
|
||||
let medium = release.media[j],
|
||||
format = medium.format,
|
||||
for (const medium of release.media) {
|
||||
let format = medium.format,
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -193,8 +193,7 @@ function parse_release_group(json, mbid, parent, table) {
|
|||
return 0;
|
||||
});
|
||||
|
||||
for (let i = 0; i < releases.length; i++) {
|
||||
(function (release) {
|
||||
for (const release of releases) {
|
||||
let track_tr = document.createElement('tr'),
|
||||
track_td = document.createElement('td'),
|
||||
track_table = document.createElement('table'),
|
||||
|
@ -217,12 +216,12 @@ function parse_release_group(json, mbid, parent, table) {
|
|||
tr.appendChild(format_td);
|
||||
|
||||
let columns = [release.tracks, release.date || '', release.country || '', release.status || ''];
|
||||
|
||||
for (let i = 0; i < columns.length; i++) tr.appendChild(createElement('td', columns[i]));
|
||||
for (const column of columns) {
|
||||
tr.appendChild(createElement('td', column));
|
||||
}
|
||||
|
||||
table.appendChild(tr);
|
||||
table.appendChild(track_tr);
|
||||
})(releases[i]);
|
||||
}
|
||||
|
||||
let bottom_tr = document.createElement('tr'),
|
||||
|
@ -288,12 +287,11 @@ function parse_release(json, table) {
|
|||
table.appendChild(bottom_tr);
|
||||
}
|
||||
|
||||
function createAC(obj) {
|
||||
function createAC(artist_credit_array) {
|
||||
let span = document.createElement('span');
|
||||
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
let credit = obj[i],
|
||||
artist = credit.artist,
|
||||
for (const credit of artist_credit_array) {
|
||||
let artist = credit.artist,
|
||||
link = createLink(`/artist/${artist.id}`, credit.name || artist.name);
|
||||
|
||||
link.setAttribute('title', artist['sort-name']);
|
||||
|
|
Loading…
Reference in a new issue