From 0e864d8c59c117fa43e3ac07bdec5298571cd35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Sun, 5 Apr 2020 16:01:21 +0200 Subject: [PATCH] Reformat with prettier 2.0 --- bandcamp_importer.user.js | 61 +++--- bandcamp_importer_helper.user.js | 2 +- batch-add-recording-relationships.user.js | 253 ++++++++-------------- beatport_classic_importer.user.js | 31 +-- beatport_importer.user.js | 18 +- cd1d_importer.user.js | 74 +++---- cdbaby_importer.user.js | 56 ++--- deezer_importer.user.js | 24 +- dgdecca_importer.user.js | 56 +++-- discogs_importer.user.js | 70 +++--- encyclopedisque_importer.user.js | 18 +- expand-collapse-release-groups.user.js | 24 +- fast-cancel-edits.user.js | 20 +- fma_importer.user.js | 112 +++++----- juno_download_importer.user.js | 60 ++--- lib/logger.js | 4 +- lib/mbimport.js | 28 +-- lib/mblinks.js | 54 ++--- loot_importer.user.js | 41 ++-- mb_1200px_caa.user.js | 2 +- mb_discids_detector.user.js | 65 +++--- mb_relationship_shortcuts.user.js | 58 ++--- mb_ui_enhancements.user.js | 81 +++---- metalarchives_importer.user.js | 43 ++-- qobuz_importer.user.js | 54 +++-- set-recording-comments.user.js | 55 ++--- takealot_importer.user.js | 56 ++--- 27 files changed, 597 insertions(+), 823 deletions(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index 62eac1f..ba4455a 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -20,13 +20,13 @@ this.$ = this.jQuery = jQuery.noConflict(true); if (!unsafeWindow) unsafeWindow = window; -String.prototype.fix_bandcamp_url = function() { +String.prototype.fix_bandcamp_url = function () { return this.replace('http://', 'https://'); }; var BandcampImport = { // Analyze Bandcamp data and return a release object - retrieveReleaseInfo: function() { + retrieveReleaseInfo: function () { let bandcampAlbumData = unsafeWindow.TralbumData; let bandcampEmbedData = unsafeWindow.EmbedData; @@ -48,7 +48,7 @@ var BandcampImport = { language: 'eng', script: 'Latn', urls: [], - url: bandcampAlbumData.url.fix_bandcamp_url() + url: bandcampAlbumData.url.fix_bandcamp_url(), }; // Grab release title @@ -83,7 +83,7 @@ var BandcampImport = { // Tracks let disc = { tracks: [], - format: release.format + format: release.format, }; release.discs.push(disc); @@ -107,7 +107,7 @@ var BandcampImport = { } let tracks_streamable = 0; - $.each(bandcampAlbumData.trackinfo, function(index, bctrack) { + $.each(bandcampAlbumData.trackinfo, function (index, bctrack) { let title = bctrack.title; let artist = []; if (various_artists) { @@ -121,7 +121,7 @@ var BandcampImport = { let track = { title: title, duration: Math.round(bctrack.duration * 1000), - artist_credit: MBImport.makeArtistCredits(artist) + artist_credit: MBImport.makeArtistCredits(artist), }; disc.tracks.push(track); }); @@ -147,7 +147,7 @@ var BandcampImport = { let track = { title: '[unknown]', duration: null, - artist_credit: [] + artist_credit: [], }; disc.tracks.push(track); } @@ -166,13 +166,13 @@ var BandcampImport = { ) { release.urls.push({ url: release.url, - link_type: link_type.download_for_free + link_type: link_type.download_for_free, }); } if (bandcampAlbumData.current.download_pref === 2) { release.urls.push({ url: release.url, - link_type: link_type.purchase_for_download + link_type: link_type.purchase_for_download, }); } } @@ -180,14 +180,14 @@ var BandcampImport = { if (bandcampAlbumData.hasAudio && !nostream && disc.tracks.length > 0 && disc.tracks.length == tracks_streamable) { release.urls.push({ url: release.url, - link_type: link_type.stream_for_free + link_type: link_type.stream_for_free, }); } // Check if release is Creative Commons licensed if ($('div#license a.cc-icons').length > 0) { release.urls.push({ url: $('div#license a.cc-icons').attr('href'), - link_type: link_type.license + link_type: link_type.license, }); } // Check if album has a back link to a label @@ -196,7 +196,7 @@ var BandcampImport = { release.labels.push({ name: label, mbid: '', - catno: 'none' + catno: 'none', }); } @@ -204,7 +204,7 @@ var BandcampImport = { }, // Insert links in page - insertLink: function(release) { + insertLink: function (release) { if (release.type == 'track') { // only import album or single, tracks belong to an album return false; @@ -223,31 +223,29 @@ var BandcampImport = { }, // helper to convert bandcamp date to MB date - convdate: function(date) { + convdate: function (date) { if (typeof date != 'undefined' && date !== '') { let d = new Date(date); return { year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, - day: d.getUTCDate() + day: d.getUTCDate(), }; } return false; }, // get label name from back link if possible - getlabelname: function() { - let label = $('a.back-to-label-link span.back-link-text') - .contents() - .get(2); + getlabelname: function () { + let label = $('a.back-to-label-link span.back-link-text').contents().get(2); if (typeof label == 'undefined') { return ''; } return label.textContent; - } + }, }; -$(document).ready(function() { +$(document).ready(function () { /* keep the following line as first, it is required to skip * pages which aren't actually a bandcamp page, since we support * bandcamp pages under third-party domains. @@ -265,13 +263,13 @@ $(document).ready(function() { // add MB artist link let root_url = release.url.match(/^(https?:\/\/[^\/]+)/)[1].split('?')[0]; let label_url = ''; - mblinks.searchAndDisplayMbLink(root_url, 'artist', function(link) { + mblinks.searchAndDisplayMbLink(root_url, 'artist', function (link) { $('div#name-section span[itemprop="byArtist"]').before(link); }); mblinks.searchAndDisplayMbLink( root_url, 'label', - function(link) { + function (link) { $('p#band-name-location span.title').append(link); }, `label:${root_url}` @@ -287,7 +285,7 @@ $(document).ready(function() { mblinks.searchAndDisplayMbLink( label_url, 'label', - function(link) { + function (link) { $('a.back-to-label-link span.back-link-text').append(link); }, `label:${label_url}` @@ -311,17 +309,14 @@ $(document).ready(function() { label_name = BandcampImport.getlabelname(); } else { label_mbid = mblinks.resolveMBID(`label:${root_url}`); - if (label_mbid) - label_name = $('p#band-name-location span.title') - .text() - .trim(); + if (label_mbid) label_name = $('p#band-name-location span.title').text().trim(); } if (label_mbid || label_name) { if (release.labels.length == 0) { release.labels.push({ name: '', mbid: '', - catno: 'none' + catno: 'none', }); } release.labels[0].name = label_name; @@ -333,12 +328,12 @@ $(document).ready(function() { if (release.type == 'track') { // add MB links to parent album - mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function(link) { + mblinks.searchAndDisplayMbLink(release.parent_album_url, 'release', function (link) { $('div#name-section span[itemprop="inAlbum"] a:first').before(link); }); } else { // add MB release links to album or single - mblinks.searchAndDisplayMbLink(release.url, 'release', function(link) { + mblinks.searchAndDisplayMbLink(release.url, 'release', function (link) { $('div#name-section span[itemprop="byArtist"]').after(link); }); } @@ -347,9 +342,7 @@ $(document).ready(function() { $('div.tralbum-tags a:not(:last-child).tag').after(', '); // append a link to the full size image - let fullsizeimageurl = $('div#tralbumArt a') - .attr('href') - .replace('_10', '_0'); + let fullsizeimageurl = $('div#tralbumArt a').attr('href').replace('_10', '_0'); $('div#tralbumArt').after( `` ); diff --git a/bandcamp_importer_helper.user.js b/bandcamp_importer_helper.user.js index a258936..e5e9892 100644 --- a/bandcamp_importer_helper.user.js +++ b/bandcamp_importer_helper.user.js @@ -19,7 +19,7 @@ this.$ = this.jQuery = jQuery.noConflict(true); if (!unsafeWindow) unsafeWindow = window; -$(document).ready(function() { +$(document).ready(function () { // Display a link to the correct album bandcamp url (ie. main page or releases page) let bandcampAlbumData = unsafeWindow.TralbumData; if (bandcampAlbumData && bandcampAlbumData.url) { diff --git a/batch-add-recording-relationships.user.js b/batch-add-recording-relationships.user.js index feaf217..5fe45b9 100644 --- a/batch-add-recording-relationships.user.js +++ b/batch-add-recording-relationships.user.js @@ -144,7 +144,7 @@ function batch_recording_rels() { return { year: parseIntegerOrNull(match[1]), month: parseIntegerOrNull(match[2]), - day: parseIntegerOrNull(match[3]) + day: parseIntegerOrNull(match[3]), }; } @@ -154,7 +154,7 @@ function batch_recording_rels() { let daysInMonth = { true: [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], - false: [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + false: [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], }; function isDateValid(y, m, d) { @@ -173,7 +173,7 @@ function batch_recording_rels() { // Request rate limiting let REQUEST_COUNT = 0; - setInterval(function() { + setInterval(function () { if (REQUEST_COUNT > 0) { REQUEST_COUNT -= 1; } @@ -188,7 +188,7 @@ function batch_recording_rels() { this.stopped = false; } - RequestManager.prototype.next = function() { + RequestManager.prototype.next = function () { if (this.stopped || !this.queue.length) { this.active = false; return; @@ -202,7 +202,7 @@ function batch_recording_rels() { let timeout = diff * 1000; setTimeout( - function(self) { + function (self) { self.next(); }, this.rate + timeout, @@ -210,7 +210,7 @@ function batch_recording_rels() { ); } else { setTimeout( - function(self) { + function (self) { self.next(); }, this.rate, @@ -219,34 +219,34 @@ function batch_recording_rels() { } }; - RequestManager.prototype.push_get = function(url, cb) { - this.push(function() { + RequestManager.prototype.push_get = function (url, cb) { + this.push(function () { $.get(url, cb); }); }; - RequestManager.prototype.unshift_get = function(url, cb) { - this.unshift(function() { + RequestManager.prototype.unshift_get = function (url, cb) { + this.unshift(function () { $.get(url, cb); }); }; - RequestManager.prototype.push = function(req) { + RequestManager.prototype.push = function (req) { this.queue.push(req); this.maybe_start_queue(); }; - RequestManager.prototype.unshift = function(req) { + RequestManager.prototype.unshift = function (req) { this.queue.unshift(req); this.maybe_start_queue(); }; - RequestManager.prototype.maybe_start_queue = function() { + RequestManager.prototype.maybe_start_queue = function () { if (!(this.active || this.stopped)) { this.start_queue(); } }; - RequestManager.prototype.start_queue = function() { + RequestManager.prototype.start_queue = function () { if (this.active) { return; } @@ -258,7 +258,7 @@ function batch_recording_rels() { } else { let timeout = this.rate - now + this.last; setTimeout( - function(self) { + function (self) { self.next(); }, timeout, @@ -298,13 +298,13 @@ function batch_recording_rels() { [/–/g, '-'], [/−/g, '-'], [/—/g, '-'], - [/―/g, '--'] + [/―/g, '--'], ]; function normalizeTitle(title) { title = title.toLowerCase().replace(/\s+/g, ''); - _.each(ASCII_PUNCTUATION, function(val) { + _.each(ASCII_PUNCTUATION, function (val) { title = title.replace(val[0], val[1]); }); @@ -312,7 +312,7 @@ function batch_recording_rels() { } let RECORDING_TITLES = _.chain($recordings) - .map(function(row) { + .map(function (row) { let $title = $(row).find(TITLE_SELECTOR), mbid = $title.attr('href').match(MBID_REGEX)[0], norm_title = normalizeTitle($title.text().match(WITHOUT_PAREN_CLAUSES_REGEX)[1]); @@ -323,7 +323,7 @@ function batch_recording_rels() { .value(); let $work_options = _.chain(['type', 'language']) - .map(function(kind) { + .map(function (kind) { return [kind, $(``)]; }) .fromPairs() @@ -368,9 +368,7 @@ function batch_recording_rels() { let hide_pending_edits = setting('hide_pending_edits') === 'true' ? true : false; function make_checkbox(func, default_val, lbl) { - let chkbox = $('') - .on('change', func) - .attr('checked', default_val); + let chkbox = $('').on('change', func).attr('checked', default_val); return label(chkbox, lbl); } @@ -389,32 +387,23 @@ function batch_recording_rels() { let $recordings_load_msg = $('Loading performance relationships…'); - $container - .find('table') - .find('td') - .css('width', 'auto'); - $container - .children('tbody') - .children('tr') - .children('td') - .css({ padding: '0.5em', 'vertical-align': 'top' }); + $container.find('table').find('td').css('width', 'auto'); + $container.children('tbody').children('tr').children('td').css({ padding: '0.5em', 'vertical-align': 'top' }); // Get actual work types/languages - ws_requests.unshift_get('/dialog?path=%2Fwork%2Fcreate', function(data) { + ws_requests.unshift_get('/dialog?path=%2Fwork%2Fcreate', function (data) { let nodes = $.parseHTML(data); function populate($obj, kind) { $obj.append($(`#id-edit-work\\.${kind}_id`, nodes).children()) .val(setting(`work_${kind}`) || 0) - .on('change', function() { + .on('change', function () { setting(`work_${kind}`, this.value); }); } _.each($work_options, populate); }); - $('') - .append(' ', $recordings_load_msg) - .insertBefore($relate_table); + $('').append(' ', $recordings_load_msg).insertBefore($relate_table); // Add additional column @@ -443,7 +432,7 @@ function batch_recording_rels() { ); $(document) - .on('input', 'input.bpr-date-input', function() { + .on('input', 'input.bpr-date-input', function () { let $input = $(this); $input.css('border-color', '#999'); @@ -466,13 +455,13 @@ function batch_recording_rels() { $input.css('color', '#ddd'); } }) - .on('click', 'span.bpr-attr', function() { + .on('click', 'span.bpr-attr', function () { let $this = $(this); let checked = !$this.data('checked'); $this.data('checked', checked).css({ background: checked ? 'blue' : 'inherit', - color: checked ? 'white' : 'black' + color: checked ? 'white' : 'black', }); }); @@ -484,7 +473,7 @@ function batch_recording_rels() { 'background-color': '#FFFFFF', border: '1px solid #D0D0D0', 'border-top': '1px solid #EAEAEA', - 'border-left': '1px solid #EAEAEA' + 'border-left': '1px solid #EAEAEA', }); } @@ -496,7 +485,7 @@ function batch_recording_rels() { $rows.find('input[name=add-to-merge]').attr('checked', false); } - $('.tbl > thead input[type=checkbox]').on('change', function() { + $('.tbl > thead input[type=checkbox]').on('change', function () { if (this.checked) { uncheckRows($recordings.filter(':hidden')); } @@ -523,11 +512,7 @@ function batch_recording_rels() { } let NAME_FILTER = $.trim($('#id-filter\\.name').val()); - let ARTIST_FILTER = $.trim( - $('#id-filter\\.artist_credit_id') - .find('option:selected') - .text() - ); + let ARTIST_FILTER = $.trim($('#id-filter\\.artist_credit_id').find('option:selected').text()); if (NAME_FILTER || ARTIST_FILTER) { get_filtered_page(0); @@ -540,7 +525,7 @@ function batch_recording_rels() { function request_recordings(url) { let attempts = 1; - $.get(url, function(data) { + $.get(url, function (data) { let recs = data.recordings; let cache = {}; @@ -550,10 +535,7 @@ function batch_recording_rels() { if (row === undefined) { for (let j = 0; j < $recordings.length; j++) { let row_ = $recordings[j]; - let row_id = $(row_) - .find(TITLE_SELECTOR) - .attr('href') - .match(MBID_REGEX)[0]; + let row_id = $(row_).find(TITLE_SELECTOR).attr('href').match(MBID_REGEX)[0]; if (node.id === row_id) { row = row_; @@ -581,12 +563,12 @@ function batch_recording_rels() { restripeRows(); } }) - .done(function() { + .done(function () { $recordings_load_msg.parent().remove(); $relate_table.show(); load_works_init(); }) - .fail(function() { + .fail(function () { $recordings_load_msg.text(`Error loading relationships. Retry #${attempts}...`).css('color', 'red'); attempts += 1; ws_requests.unshift(request_recordings); @@ -594,7 +576,7 @@ function batch_recording_rels() { } function queue_recordings_request(url) { - ws_requests.push(function() { + ws_requests.push(function () { request_recordings(url); }); } @@ -604,8 +586,8 @@ function batch_recording_rels() { ARTIST_FILTER ? `creditname:${encodeURIComponent(ARTIST_FILTER)}%20AND%20` : '' } arid:${ARTIST_MBID}&limit=100&offset=${page * 100}&fmt=json`; - ws_requests.push_get(url, function(data) { - _.each(data.recordings, function(r) { + ws_requests.push_get(url, function (data) { + _.each(data.recordings, function (r) { queue_recordings_request(`/ws/2/recording/${r.id}?inc=work-rels&fmt=json`); }); @@ -622,7 +604,7 @@ function batch_recording_rels() { $row.data('performances', []); $attrs.data('checked', false).css('color', 'black'); - _.each(node.relations, function(rel) { + _.each(node.relations, function (rel) { if (rel.type.match(/performance/)) { if (!performed) { $row.addClass('performed'); @@ -630,14 +612,11 @@ function batch_recording_rels() { } if (rel.begin) { - $attrs - .find('input.date') - .val(rel.begin) - .trigger('input'); + $attrs.find('input.date').val(rel.begin).trigger('input'); } let attrs = []; - _.each(rel.attributes, function(name) { + _.each(rel.attributes, function (name) { let cannonical_name = name.toLowerCase(); let $button = $attrs.find(`span.${cannonical_name}`); @@ -657,10 +636,7 @@ function batch_recording_rels() { let comment = node.disambiguation; let date = comment && comment.match && comment.match(/live(?: .+)?, ([0-9]{4}(?:-[0-9]{2}(?:-[0-9]{2})?)?)(?:\: .+)?$/); if (date) { - $attrs - .find('input.date') - .val(date[1]) - .trigger('input'); + $attrs.find('input.date').val(date[1]).trigger('input'); } if (!performed) { @@ -669,8 +645,8 @@ function batch_recording_rels() { } else { let url = `/ws/2/recording/${node.id}?inc=releases+release-groups&fmt=json`; - var request_rec = function() { - $.get(url, function(data) { + var request_rec = function () { + $.get(url, function (data) { let releases = data.releases; for (let i = 0; i < releases.length; i++) { @@ -679,7 +655,7 @@ function batch_recording_rels() { break; } } - }).fail(function() { + }).fail(function () { ws_requests.push(request_rec); }); }; @@ -734,7 +710,7 @@ function batch_recording_rels() { $msg = $(''); $button_cell.append( - style_buttons($('')).click(function() { + style_buttons($('')).click(function () { $table_row.remove(); remove_artist_works(mbid); }) @@ -742,7 +718,7 @@ function batch_recording_rels() { } let $reload = style_buttons($('')) - .click(function() { + .click(function () { $button_cell.css('display', 'none'); $msg.text(`Loading works for ${name}...`); load(); @@ -750,9 +726,7 @@ function batch_recording_rels() { .prependTo($button_cell); $msg.text(`Loading works for ${name}...`).css('color', 'green'), $table_row.append($msg, $button_cell); - $('tr#bpr-works-row') - .css('display', 'none') - .before($table_row); + $('tr#bpr-works-row').css('display', 'none').before($table_row); let works_date = localStorage.getItem(`bpr_works_date ${mbid}`); let result = []; @@ -781,7 +755,7 @@ function batch_recording_rels() { localStorage.setItem(`bpr_works_date ${mbid}`, works_date); result = []; - let callback = function(loaded, remaining) { + let callback = function (loaded, remaining) { result.push.apply(result, loaded); if (remaining > 0) { $msg.text(`Loading ${remaining.toString()} works for ${name}...`); @@ -792,7 +766,7 @@ function batch_recording_rels() { }; let works_url = `/ws/2/work?artist=${mbid}&inc=aliases&limit=100&fmt=json`; - ws_requests.unshift(function() { + ws_requests.unshift(function () { request_works(works_url, 0, -1, callback); }); } @@ -806,7 +780,7 @@ function batch_recording_rels() { let tmp_comments = []; let tmp_norm_titles = []; - _.each(result, function(parts) { + _.each(result, function (parts) { let mbid = parts.slice(0, 36); let rest = parts.slice(36).split('\u00a0'); @@ -820,7 +794,7 @@ function batch_recording_rels() { } function request_works(url, offset, count, callback) { - $.get(`${url}&offset=${offset}`, function(data, textStatus, jqXHR) { + $.get(`${url}&offset=${offset}`, function (data, textStatus, jqXHR) { if (count < 0) { count = data['work-count']; } @@ -828,7 +802,7 @@ function batch_recording_rels() { let works = data.works; let loaded = []; - _.each(works, function(work) { + _.each(works, function (work) { let comment = work.disambiguation; loaded.push(work.id + work.title + (comment ? `\u00a0${comment}` : '')); }); @@ -836,12 +810,12 @@ function batch_recording_rels() { callback(loaded, count - offset - works.length); if (works.length + offset < count) { - ws_requests.unshift(function() { + ws_requests.unshift(function () { request_works(url, offset + 100, count, callback); }); } - }).fail(function() { - ws_requests.unshift(function() { + }).fail(function () { + ws_requests.unshift(function () { request_works(url, offset, count, callback); }); }); @@ -865,7 +839,7 @@ function batch_recording_rels() { let matches = {}; - let to_recording = function($rec, rec_title) { + let to_recording = function ($rec, rec_title) { if (rec_title in matches) { let match = matches[rec_title]; suggested_work_link($rec, match[0], match[1], match[2]); @@ -883,7 +857,7 @@ function batch_recording_rels() { let context = { minScore: 0.250001, match: null }; let total = mbids.length; - let done = function() { + let done = function () { let match = context.match; if (match !== null) { matches[rec_title] = match; @@ -893,7 +867,7 @@ function batch_recording_rels() { } }; - var iid = setInterval(function() { + var iid = setInterval(function () { let j = current++; let norm_work_title = norm_titles[j]; let score = sim(rec_title, norm_work_title); @@ -920,10 +894,7 @@ function batch_recording_rels() { for (let i = 0; i < $not_performed.length; i++) { let $rec = $not_performed.eq(i); - let mbid = $rec - .find(TITLE_SELECTOR) - .attr('href') - .match(MBID_REGEX)[0]; + let mbid = $rec.find(TITLE_SELECTOR).attr('href').match(MBID_REGEX)[0]; to_recording($rec, RECORDING_TITLES[mbid]); } @@ -937,9 +908,7 @@ function batch_recording_rels() { .append( $('Suggested work:').css({ color: 'green', 'font-weight': 'bold' }), ' ', - $('') - .attr('href', `/work/${mbid}`) - .text(title), + $('').attr('href', `/work/${mbid}`).text(title), comment ? ' ' : null, comment ? $('').text(`(${comment})`) : null ) @@ -958,7 +927,7 @@ function batch_recording_rels() { let item_key = `bpr_artists ${ARTIST_MBID}`; localStorage.setItem( item_key, - _.filter(localStorage.getItem(item_key).split('\n'), function(artist) { + _.filter(localStorage.getItem(item_key).split('\n'), function (artist) { return artist.slice(0, 36) !== mbid; }).join('\n') ); @@ -1000,7 +969,7 @@ function batch_recording_rels() { let mbid = $input.data('mbid'); let name = $input.data('name'); - load_artist_works(mbid, name).done(function() { + load_artist_works(mbid, name).done(function () { let artists_string = localStorage.getItem(`bpr_artists ${ARTIST_MBID}`); if (artists_string) { artists_string += `\n${mbid}${name}`; @@ -1032,16 +1001,11 @@ function batch_recording_rels() { for (let i = 0; i < total; i++) { let $row = $rows.eq(i); - $row.children('td') - .not(':has(input)') - .first() - .css('color', 'LightSlateGray') - .find('a') - .css('color', 'LightSlateGray'); + $row.children('td').not(':has(input)').first().css('color', 'LightSlateGray').find('a').css('color', 'LightSlateGray'); let promise = relate_to_work($row, mbid, title, comment, false, false); if (i === total - 1) { - promise.done(function() { + promise.done(function () { deferred.resolve(); }); } @@ -1066,9 +1030,7 @@ function batch_recording_rels() { ws_requests.stopped = true; - let $button = $(this) - .attr('disabled', true) - .css('color', '#EAEAEA'); + let $button = $(this).attr('disabled', true).css('color', '#EAEAEA'); function callback() { ws_requests.stopped = false; @@ -1076,7 +1038,7 @@ function batch_recording_rels() { $button.attr('disabled', false).css('color', '#565656'); } - create_new_work(title, function(data) { + create_new_work(title, function (data) { let work = data.match(/\/work\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/); relate_all_to_work(work[1], title, '').done(callback); }); @@ -1113,26 +1075,21 @@ function batch_recording_rels() { ws_requests.stopped = true; - let $button = $(this) - .attr('disabled', true) - .css('color', '#EAEAEA'); + let $button = $(this).attr('disabled', true).css('color', '#EAEAEA'); - $.each($rows, function(i, row) { + $.each($rows, function (i, row) { let $row = $(row); let $title_cell = rowTitleCell($row); let title = $title_cell.find(TITLE_SELECTOR).text(); - $title_cell - .css('color', 'LightSlateGray') - .find('a') - .css('color', 'LightSlateGray'); + $title_cell.css('color', 'LightSlateGray').find('a').css('color', 'LightSlateGray'); - create_new_work(title, function(data) { + create_new_work(title, function (data) { let work = data.match(/\/work\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/); let promise = relate_to_work($row, work[1], title, '', true, true); if (--total_rows === 0) { - promise.done(function() { + promise.done(function () { flush_work_cache(); ws_requests.stopped = false; ws_requests.start_queue(); @@ -1146,13 +1103,13 @@ function batch_recording_rels() { function create_new_work(title, callback) { function post_edit() { let data = `edit-work.name=${title}`; - _.each($work_options, function($obj, kind) { + _.each($work_options, function ($obj, kind) { if ($obj.val()) { data += `&edit-work.${kind}_id=${$obj.val()}`; } }); - $.post('/work/create', data, callback).fail(function() { + $.post('/work/create', data, callback).fail(function () { edit_requests.unshift(post_edit); }); } @@ -1160,7 +1117,7 @@ function batch_recording_rels() { } function relate_to_suggested_works() { - let $rows = checked_recordings().filter(function() { + let $rows = checked_recordings().filter(function () { return $(this).data('suggested_work_mbid'); }); @@ -1169,9 +1126,7 @@ function batch_recording_rels() { return; } - let $button = $(this) - .attr('disabled', true) - .css('color', '#EAEAEA'); + let $button = $(this).attr('disabled', true).css('color', '#EAEAEA'); ws_requests.stopped = true; function callback() { @@ -1180,16 +1135,13 @@ function batch_recording_rels() { $button.attr('disabled', false).css('color', '#565656'); } - $.each($rows, function(i, row) { + $.each($rows, function (i, row) { let $row = $(row); let mbid = $row.data('suggested_work_mbid'); let title = $row.data('suggested_work_title'); let $title_cell = rowTitleCell($row); - $title_cell - .css('color', 'LightSlateGray') - .find('a') - .css('color', 'LightSlateGray'); + $title_cell.css('color', 'LightSlateGray').find('a').css('color', 'LightSlateGray'); let promise = relate_to_work($row, mbid, title, '', false, false); if (i === total - 1) { @@ -1207,9 +1159,7 @@ function batch_recording_rels() { .text(`${attrs.join(' ')} recording of `) .css({ 'font-size': '0.9em', padding: '0.3em', 'padding-left': '1em' }) .append( - $('') - .attr('href', `/work/${mbid}`) - .text(title), + $('').attr('href', `/work/${mbid}`).text(title), comment ? ' ' : null, comment ? $('').text(`(${comment})`) : null ) @@ -1231,10 +1181,7 @@ function batch_recording_rels() { $row.data('performances', [work_mbid]); } - let rec_mbid = $row - .find(TITLE_SELECTOR) - .attr('href') - .match(MBID_REGEX)[0]; + let rec_mbid = $row.find(TITLE_SELECTOR).attr('href').match(MBID_REGEX)[0]; let $title_cell = rowTitleCell($row); let title_link = $title_cell.children('a')[0]; let $attrs = $row.children('td.bpr_attrs'); @@ -1254,7 +1201,7 @@ function batch_recording_rels() { 'rel-editor.rels.0.entity.1.type': 'work', 'rel-editor.rels.0.entity.1.gid': work_mbid, 'rel-editor.rels.0.entity.0.type': 'recording', - 'rel-editor.rels.0.entity.0.gid': rec_mbid + 'rel-editor.rels.0.entity.0.gid': rec_mbid, }; let attrs = []; @@ -1263,7 +1210,7 @@ function batch_recording_rels() { if (selected('instrumental')) attrs.push('c031ed4f-c9bb-4394-8cf5-e8ce4db512ae'); if (selected('cover')) attrs.push('1e8536bd-6eda-3822-8e78-1c0f4d3d2113'); - _.each(attrs, function(attr, index) { + _.each(attrs, function (attr, index) { data[`rel-editor.rels.0.attributes.${index}.type.gid`] = attr; }); @@ -1280,7 +1227,7 @@ function batch_recording_rels() { function post_edit() { $(title_link).css('color', 'green'); - $.post('/relationship-editor', data, function() { + $.post('/relationship-editor', data, function () { add_work_link($row, work_mbid, work_title, work_comment, selectedAttrs); $(title_link).removeAttr('style'); @@ -1292,7 +1239,7 @@ function batch_recording_rels() { } deferred.resolve(); - }).fail(function() { + }).fail(function () { edit_requests.unshift(post_edit); }); } @@ -1316,10 +1263,7 @@ function batch_recording_rels() { for (let i = 0; i < $recordings.length; i++) { let $rec = $recordings.eq(i); - let title = $rec - .find(TITLE_SELECTOR) - .text() - .toLowerCase(); + let title = $rec.find(TITLE_SELECTOR).text().toLowerCase(); if (title.indexOf(string) !== -1) { $rec.data('filtered', false); @@ -1341,7 +1285,7 @@ function batch_recording_rels() { uncheckRows($performed.hide()); } else { $performed - .filter(function() { + .filter(function () { return !$(this).data('filtered'); }) .show(); @@ -1351,12 +1295,8 @@ function batch_recording_rels() { } function toggle_pending_edits(event, checked) { - let $pending = $recordings.filter(function() { - return $(this) - .find(TITLE_SELECTOR) - .parent() - .parent() - .is('span.mp'); + let $pending = $recordings.filter(function () { + return $(this).find(TITLE_SELECTOR).parent().parent().is('span.mp'); }); hide_pending_edits = checked !== undefined ? checked : this.checked; @@ -1364,7 +1304,7 @@ function batch_recording_rels() { uncheckRows($pending.hide()); } else { $pending - .filter(function() { + .filter(function () { return !$(this).data('filtered'); }) .show(); @@ -1375,7 +1315,7 @@ function batch_recording_rels() { toggle_pending_edits(null, hide_pending_edits); function checked_recordings() { - return $recordings.filter(':visible').filter(function() { + return $recordings.filter(':visible').filter(function () { return $(this).find('input[name=add-to-merge]:checked').length; }); } @@ -1383,13 +1323,13 @@ function batch_recording_rels() { function entity_lookup(id_suffix, entity) { let $input = $(``); $input - .on('input', function() { + .on('input', function () { let match = this.value.match(MBID_REGEX); $(this).data('selected', false); if (match) { let mbid = match[0]; ws_requests - .unshift_get(`/ws/2/${entity}/${mbid}?fmt=json`, function(data) { + .unshift_get(`/ws/2/${entity}/${mbid}?fmt=json`, function (data) { let value = data.title || data.name; let out_data = { selected: true, mbid: mbid, name: value }; @@ -1397,12 +1337,9 @@ function batch_recording_rels() { out_data.comment = data.disambiguation; } - $input - .val(value) - .data(out_data) - .css('background', '#bbffbb'); + $input.val(value).data(out_data).css('background', '#bbffbb'); }) - .fail(function() { + .fail(function () { $input.css('background', '#ffaaaa'); }); } else { @@ -1415,7 +1352,7 @@ function batch_recording_rels() { } function restripeRows() { - $recordings.filter(':visible').each(function(index, row) { + $recordings.filter(':visible').each(function (index, row) { let even = (index + 1) % 2 === 0; row.className = row.className.replace(even ? 'odd' : 'even', even ? 'even' : 'odd'); }); diff --git a/beatport_classic_importer.user.js b/beatport_classic_importer.user.js index c52add5..445a290 100644 --- a/beatport_classic_importer.user.js +++ b/beatport_classic_importer.user.js @@ -18,7 +18,7 @@ this.$ = this.jQuery = jQuery.noConflict(true); if (!unsafeWindow) unsafeWindow = window; -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, ''); @@ -29,7 +29,7 @@ $(document).ready(function() { function retrieveReleaseInfo(release_url) { function contains_or(selector, list) { selectors = []; - $.each(list, function(ind, value) { + $.each(list, function (ind, value) { selectors.push(`${selector}:contains("${value.replace('"', '\\"')}")`); }); return selectors.join(','); @@ -42,7 +42,7 @@ function retrieveReleaseInfo(release_url) { 'Data de lançamento', 'Releasedatum', 'Data di uscita', - 'リリース予定日' + 'リリース予定日', ]; let labels_strings = ['Labels', 'Sello', 'Gravadoras', 'Label', 'Etichetta', 'Editora', 'レーベル']; let catalog_strings = ['Catalog', 'Catálogo', 'Catalogue', 'Katalog', 'Catalogus', 'Catalogo', 'カタログ']; @@ -55,37 +55,30 @@ function retrieveReleaseInfo(release_url) { release.urls = []; release.urls.push({ url: release_url, - link_type: MBImport.URL_TYPES.purchase_for_download + link_type: MBImport.URL_TYPES.purchase_for_download, }); - let releaseDate = $(contains_or('td.meta-data-label', release_date_strings)) - .next() - .text() - .split('-'); + let releaseDate = $(contains_or('td.meta-data-label', release_date_strings)).next().text().split('-'); release.year = releaseDate[0]; release.month = releaseDate[1]; release.day = releaseDate[2]; release.labels = []; release.labels.push({ - name: $(contains_or('td.meta-data-label', labels_strings)) - .next() - .text(), - catno: $(contains_or('td.meta-data-label', catalog_strings)) - .next() - .text() + name: $(contains_or('td.meta-data-label', labels_strings)).next().text(), + catno: $(contains_or('td.meta-data-label', catalog_strings)).next().text(), }); let release_artists = []; // Tracks let tracks = []; - unsafeWindow.$('span[data-json]').each(function(index, tagSoup) { + unsafeWindow.$('span[data-json]').each(function (index, tagSoup) { let t = $.parseJSON($(tagSoup).attr('data-json')); release.title = t.release.name; let artists = []; - t.artists.forEach(function(artist) { + t.artists.forEach(function (artist) { artists.push(artist.name); release_artists.push(artist.name); }); @@ -96,12 +89,12 @@ function retrieveReleaseInfo(release_url) { tracks.push({ artist_credit: MBImport.makeArtistCredits(artists), title: title, - duration: t.lengthMs + duration: t.lengthMs, }); }); let unique_artists = []; - $.each(release_artists, function(i, el) { + $.each(release_artists, function (i, el) { if ($.inArray(el, unique_artists) === -1) { unique_artists.push(el); } @@ -115,7 +108,7 @@ function retrieveReleaseInfo(release_url) { release.discs = []; release.discs.push({ tracks: tracks, - format: 'Digital Media' + format: 'Digital Media', }); LOGGER.info('Parsed release: ', release); diff --git a/beatport_importer.user.js b/beatport_importer.user.js index cb657e7..6b811e4 100644 --- a/beatport_importer.user.js +++ b/beatport_importer.user.js @@ -21,7 +21,7 @@ this.$ = this.jQuery = jQuery.noConflict(true); if (!unsafeWindow) unsafeWindow = window; -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, ''); @@ -48,18 +48,18 @@ function retrieveReleaseInfo(release_url) { type: '', urls: [], labels: [], - discs: [] + discs: [], }; // URLs release.urls.push({ url: release_url, - link_type: MBImport.URL_TYPES.purchase_for_download + link_type: MBImport.URL_TYPES.purchase_for_download, }); release.labels.push({ name: ProductDetail.label.name, - catno: ProductDetail.catalog + catno: ProductDetail.catalog, }); // Reload Playables if empty @@ -73,7 +73,7 @@ function retrieveReleaseInfo(release_url) { let the_tracks = unsafeWindow.Playables.tracks; let seen_tracks = {}; // to shoot duplicates ... let release_artists = []; - $.each(the_tracks, function(idx, track) { + $.each(the_tracks, function (idx, track) { if (track.release.id !== ProductDetail.id) { return; } @@ -83,7 +83,7 @@ function retrieveReleaseInfo(release_url) { seen_tracks[track.id] = true; let artists = []; - $.each(track.artists, function(idx2, artist) { + $.each(track.artists, function (idx2, artist) { artists.push(artist.name); release_artists.push(artist.name); }); @@ -95,12 +95,12 @@ function retrieveReleaseInfo(release_url) { tracks.push({ artist_credit: MBImport.makeArtistCredits(artists), title: title, - duration: track.duration.minutes + duration: track.duration.minutes, }); }); let unique_artists = []; - $.each(release_artists, function(i, el) { + $.each(release_artists, function (i, el) { if ($.inArray(el, unique_artists) === -1) { unique_artists.push(el); } @@ -113,7 +113,7 @@ function retrieveReleaseInfo(release_url) { } release.discs.push({ tracks: tracks, - format: release.format + format: release.format, }); LOGGER.info('Parsed release: ', release); diff --git a/cd1d_importer.user.js b/cd1d_importer.user.js index 87c8401..35d9469 100644 --- a/cd1d_importer.user.js +++ b/cd1d_importer.user.js @@ -24,18 +24,12 @@ this.$ = this.jQuery = jQuery.noConflict(true); var CD1DImporter = { - getFormats: function() { + getFormats: function () { // get a list of existing formats, return id of the fragment and name - let formats = $('#container-1 ul li.ui-state-default').map(function() { + let formats = $('#container-1 ul li.ui-state-default').map(function () { return { - id: $(this) - .find('a:first') - .attr('href') - .split('#')[1] - .split('-'), - name: $(this) - .find('span:first') - .text() + id: $(this).find('a:first').attr('href').split('#')[1].split('-'), + name: $(this).find('span:first').text(), }; }); // remove "parent" formats : ie. digital when mp3 and flac are present @@ -58,31 +52,27 @@ var CD1DImporter = { if (!formats[i].toremove) { cleanformats.push({ id: formats[i].id.join('-'), - name: formats[i].name + name: formats[i].name, }); } } return cleanformats; }, - getTracks: function(id) { + getTracks: function (id) { // extract discs & tracks let tracklists = `div#${id} div.tracklist table.tracklist-content`; let discs = []; - $(tracklists).each(function() { + $(tracklists).each(function () { disc = $(this) .find('tbody tr') - .map(function() { + .map(function () { // $(this) is used more than once; cache it for performance. let row = $(this); // For each row that's "mapped", return an object that // describes the first and second in the row. - let duration = row - .find('td.tracklist-content-length') - .text() - .replace('"', '') - .replace("' ", ':'); + let duration = row.find('td.tracklist-content-length').text().replace('"', '').replace("' ", ':'); // drop track number prefix (A A2 C3 01 05 etc...) let title = row @@ -91,7 +81,7 @@ var CD1DImporter = { .replace(/^[0-9A-F][0-9]* /, ''); return { title: title, - duration: MBImport.hmsToMilliSeconds(duration) + duration: MBImport.hmsToMilliSeconds(duration), }; }) .get(); @@ -100,22 +90,22 @@ var CD1DImporter = { return discs; }, - getArtists: function() { + getArtists: function () { // get artists let artists = $('div.infos-releasegrp div.list-artist a') - .map(function() { + .map(function () { return $(this).text(); }) .get(); return MBImport.makeArtistCredits(artists); }, - getAlbum: function() { + getAlbum: function () { // get release title return $('h1').text(); }, - fromCurrentTime: function(offset_in_seconds) { + fromCurrentTime: function (offset_in_seconds) { let millis = Date.now(); if (!isNaN(offset_in_seconds)) { millis += offset_in_seconds * 1000; @@ -127,11 +117,11 @@ var CD1DImporter = { return { year: yyyy, month: mm, - day: dd + day: dd, }; }, - getReleaseDate: function() { + getReleaseDate: function () { // get release date and convert it to object let text = $('div.infos-releasegrp div.row-date').text(); if (text == 'yesterday' || text == 'hier') { @@ -169,15 +159,15 @@ var CD1DImporter = { return { year: parseInt(date[2], 10), month: parseInt(date[1], 10), - day: parseInt(date[0], 10) + day: parseInt(date[0], 10), }; }, - currentURL: function() { + currentURL: function () { return window.location.href.replace(/\/[a-z]{2}\/album\//i, '/album/').split('#')[0]; }, - retrieveReleaseInfo: function(format) { + retrieveReleaseInfo: function (format) { // Analyze CD1D data and return a release object let release = { artist_credit: this.getArtists(), @@ -189,7 +179,7 @@ var CD1DImporter = { script: 'latn', barcode: '', urls: [], - discs: [] + discs: [], }; // Grab release event information @@ -205,14 +195,14 @@ var CD1DImporter = { release.format = 'Vinyl'; release.urls.push({ url: this.currentURL(), - link_type: link_type.purchase_for_mail_order + link_type: link_type.purchase_for_mail_order, }); } else if (format.name.match(/cd/i)) { release.country = 'FR'; release.format = 'CD'; release.urls.push({ url: this.currentURL(), - link_type: link_type.purchase_for_mail_order + link_type: link_type.purchase_for_mail_order, }); } else if (format.name.match(/digital|mp3|flac|ogg|wav/i)) { release.country = 'XW'; @@ -220,32 +210,32 @@ var CD1DImporter = { release.format = 'Digital Media'; release.urls.push({ url: this.currentURL(), - link_type: link_type.purchase_for_download + link_type: link_type.purchase_for_download, }); } release.labels = $('div.infos-details div.row-structure') - .map(function() { + .map(function () { return { name: $(this).text(), mbid: '', - catno: 'none' + catno: 'none', }; }) .get(); // Tracks - $.each(this.getTracks(format.id), function(ndisc, disc) { + $.each(this.getTracks(format.id), function (ndisc, disc) { let thisdisc = { tracks: [], - format: release.format + format: release.format, }; release.discs.push(thisdisc); - $.each(this, function(ntrack, track) { + $.each(this, function (ntrack, track) { thisdisc.tracks.push({ title: track.title, duration: track.duration, - artist_credit: [] + artist_credit: [], }); }); }); @@ -254,7 +244,7 @@ var CD1DImporter = { return release; }, - insertLink: function(release, where, formatname) { + insertLink: function (release, where, formatname) { // Insert links in page // Form parameters @@ -267,10 +257,10 @@ var CD1DImporter = { $('#mb_buttons').css({ 'margin-top': '6px' }); $('form.musicbrainz_import').css({ display: 'inline-block', 'margin-right': '5px' }); mbUI.slideDown(); - } + }, }; -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); /* CD1D uses same page with hidden tabs for all formats */ let formats = CD1DImporter.getFormats(); diff --git a/cdbaby_importer.user.js b/cdbaby_importer.user.js index ae4d8f0..8c1324f 100644 --- a/cdbaby_importer.user.js +++ b/cdbaby_importer.user.js @@ -16,17 +16,15 @@ // prevent JQuery conflicts, see http://wiki.greasespot.net/@grant this.$ = this.jQuery = jQuery.noConflict(true); -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, ''); release_url = release_url.replace(/^(?:https?:\/\/)?(?:store\.)?(?:cdbaby\.com)\//, 'http://store.cdbaby.com/'); let release; let buttons = ''; - $('div.album-page-buy-button-container a').each(function() { - let format = $(this) - .attr('title') - .trim(); + $('div.album-page-buy-button-container a').each(function () { + let format = $(this).attr('title').trim(); release = retrieveReleaseInfo(release_url, format); buttons += getImportButton(release, release_url, format); }); @@ -40,9 +38,7 @@ function retrieveReleaseInfo(release_url, format) { // Release defaults let release = { artist_credit: '', - title: $("h1 span[itemprop='name']") - .text() - .trim(), + title: $("h1 span[itemprop='name']").text().trim(), year: 0, month: 0, day: 0, @@ -55,7 +51,7 @@ function retrieveReleaseInfo(release_url, format) { type: '', urls: [], labels: [], - discs: [] + discs: [], }; let link_type = MBImport.URL_TYPES; @@ -66,14 +62,14 @@ function retrieveReleaseInfo(release_url, format) { release.format = 'Vinyl'; release.urls.push({ url: release_url, - link_type: link_type.purchase_for_mail_order + link_type: link_type.purchase_for_mail_order, }); } else if (format.match(/^cd/i)) { release.country = 'US'; release.format = 'CD'; release.urls.push({ url: release_url, - link_type: link_type.purchase_for_mail_order + link_type: link_type.purchase_for_mail_order, }); } else if (format.match(/^download/i)) { release.country = 'XW'; @@ -81,14 +77,12 @@ function retrieveReleaseInfo(release_url, format) { release.format = 'Digital Media'; release.urls.push({ url: release_url, - link_type: link_type.purchase_for_download + link_type: link_type.purchase_for_download, }); } // Release artist - let artist = $("h2 span[itemprop='byArtist'] a") - .text() - .trim(); + let artist = $("h2 span[itemprop='byArtist'] a").text().trim(); let various_artists = artist == 'Various'; if (various_artists) { release.artist_credit = [MBImport.specialArtist('various_artists')]; @@ -96,41 +90,31 @@ function retrieveReleaseInfo(release_url, format) { release.artist_credit = MBImport.makeArtistCredits([artist]); } - release.year = $("span[itemprop='datePublished']") - .text() - .trim(); + release.year = $("span[itemprop='datePublished']").text().trim(); // Tracks let tracks = []; let trackcount = 0; - $("table.track-table tr[itemprop='track']").each(function() { + $("table.track-table tr[itemprop='track']").each(function () { let artists = []; let trackno = tracks.length + 1; if (trackno == 1 && tracks.length) { // multiple "discs" release.discs.push({ tracks: tracks, - format: release.format + format: release.format, }); tracks = []; } - let trackname = $(this) - .find("meta[itemprop='name']") - .attr('content') - .trim(); - let tracklength = $(this) - .find("meta[itemprop='duration']") - .attr('content') - .trim(); + let trackname = $(this).find("meta[itemprop='name']").attr('content').trim(); + let tracklength = $(this).find("meta[itemprop='duration']").attr('content').trim(); let track_artists = []; // FIXME various artists releases ... $(this) .find('div.track-artist') - .each(function() { - let artistname = $(this) - .text() - .trim(); + .each(function () { + let artistname = $(this).text().trim(); if (artistname) { track_artists.push(artistname); } @@ -139,7 +123,7 @@ function retrieveReleaseInfo(release_url, format) { let ac = { artist_credit: '', title: trackname, - duration: MBImport.ISO8601toMilliSeconds(tracklength) + duration: MBImport.ISO8601toMilliSeconds(tracklength), }; if (!track_artists.length && various_artists) { ac.artist_credit = [MBImport.specialArtist('unknown')]; @@ -151,7 +135,7 @@ function retrieveReleaseInfo(release_url, format) { release.discs.push({ tracks: tracks, - format: release.format + format: release.format, }); LOGGER.info('Parsed release: ', release); @@ -169,11 +153,11 @@ function insertImportLinks(release, buttons) { $('#mb_buttons').css({ 'margin-bottom': '5px', padding: '2%', - 'background-color': '#fff' + 'background-color': '#fff', }); $('form.musicbrainz_import').css({ - 'margin-bottom': '5px' + 'margin-bottom': '5px', }); $('#mb_buttons').slideDown(); diff --git a/deezer_importer.user.js b/deezer_importer.user.js index 28e8e0f..31b06c9 100644 --- a/deezer_importer.user.js +++ b/deezer_importer.user.js @@ -18,7 +18,7 @@ // prevent JQuery conflicts, see http://wiki.greasespot.net/@grant this.$ = this.jQuery = jQuery.noConflict(true); -$(document).ready(function() { +$(document).ready(function () { let gmXHR; if (typeof GM_xmlhttpRequest != 'undefined') { @@ -31,7 +31,7 @@ $(document).ready(function() { } // allow 1 second for Deezer SPA to initialize - window.setTimeout(function() { + window.setTimeout(function () { MBImportStyle(); let releaseUrl = window.location.href.replace(/\?.*$/, '').replace(/#.*$/, ''); let releaseId = releaseUrl.replace(/^https?:\/\/www\.deezer\.com\/[^/]+\/album\//i, ''); @@ -40,7 +40,7 @@ $(document).ready(function() { gmXHR({ method: 'GET', url: deezerApiUrl, - onload: function(resp) { + onload: function (resp) { try { let release = parseDeezerRelease(releaseUrl, JSON.parse(resp.responseText)); insertLink(release, releaseUrl); @@ -48,10 +48,10 @@ $(document).ready(function() { LOGGER.error('Failed to parse release: ', e); } }, - onerror: function(resp) { + onerror: function (resp) { LOGGER.error('AJAX status:', resp.status); LOGGER.error('AJAX response:', resp.responseText); - } + }, }); }, 1000); }); @@ -73,15 +73,15 @@ function parseDeezerRelease(releaseUrl, data) { type: '', urls: [], labels: [], - discs: [] + discs: [], }; - $.each(data.contributors, function(index, artist) { + $.each(data.contributors, function (index, artist) { if (artist.role != 'Main') return true; let ac = { artist_name: artist.name, - joinphrase: index == data.contributors.length - 1 ? '' : ', ' + joinphrase: index == data.contributors.length - 1 ? '' : ', ', }; if (artist.name == 'Various Artists') { @@ -94,15 +94,15 @@ function parseDeezerRelease(releaseUrl, data) { let disc = { format: 'Digital Media', title: '', - tracks: [] + tracks: [], }; - $.each(data.tracks.data, function(index, track) { + $.each(data.tracks.data, function (index, track) { let t = { number: index + 1, title: track.title_short, duration: track.duration * 1000, - artist_credit: [] + artist_credit: [], }; // ignore pointless "(Original Mix)" in title version @@ -119,7 +119,7 @@ function parseDeezerRelease(releaseUrl, data) { release.urls.push({ link_type: MBImport.URL_TYPES.stream_for_free, - url: releaseUrl + url: releaseUrl, }); release.labels.push({ name: data.label }); release.type = data.record_type; diff --git a/dgdecca_importer.user.js b/dgdecca_importer.user.js index 5ce7c4c..5363815 100644 --- a/dgdecca_importer.user.js +++ b/dgdecca_importer.user.js @@ -1,6 +1,6 @@ /* global $ MBImport */ 'use strict'; -var meta = function() { +var meta = function () { // ==UserScript== // @name Import DG/Decca releases to MusicBrainz // @namespace https://github.com/murdos/musicbrainz-userscripts @@ -38,19 +38,19 @@ var months = { 'Sep.': 9, 'Oct.': 10, 'Nov.': 11, - 'Dec.': 12 + 'Dec.': 12, }; var labels = { 'deutschegrammophon.com': { name: 'Deutsche Grammophon', mbid: '5a584032-dcef-41bb-9f8b-19540116fb1c', - catno: document.URL.split('/')[5] + catno: document.URL.split('/')[5], }, 'deccaclassics.com': { name: 'Decca Classics', mbid: '89a9993d-1dad-4445-a3d7-1d8df04f7e7b', - catno: document.URL.split('/')[5] - } + catno: document.URL.split('/')[5], + }, }; var editNote = `Imported from ${document.URL}\n —\nGM script: "${meta.name}" (${meta.version})\n\n`; @@ -97,12 +97,12 @@ function extract_release_data() { function _setReleasePerformers() { let list = $('div.artists')[0] .innerHTML.split('
') - .map(function(artist) { + .map(function (artist) { return { credited_name: artist, artist_name: artist, artist_mbid: '', - joinphrase: ', ' + joinphrase: ', ', }; }); list[list.length - 1]['joinphrase'] = ''; @@ -116,8 +116,8 @@ function extract_release_data() { credited_name: composer, artist_name: composer, artist_mbid: '', - joinphrase: '; ' - } + joinphrase: '; ', + }, ]; return list.concat(_setReleasePerformers()); } @@ -137,7 +137,7 @@ function extract_release_data() { let nodes = []; let tracklist_node = document.getElementById('tracklist'); - $('.item,.hier0,.hier1,.hier2,.hier3').each(function(idx, node) { + $('.item,.hier0,.hier1,.hier2,.hier3').each(function (idx, node) { var idx; let d = {}; if (node.classList.contains('hier0')) { @@ -166,7 +166,7 @@ function extract_release_data() { // complete track titles let header0, header1, header2, idx; - nodes.forEach(function(node, idx) { + nodes.forEach(function (node, idx) { let level = node['level'], type = node['type'], content = node['title']; @@ -194,7 +194,7 @@ function extract_release_data() { let discs = [], tracks = [], medium_title = ''; - nodes.forEach(function(item, idx) { + nodes.forEach(function (item, idx) { if (item.type === 'track') { let track = extract_track_data(item.node); track.title = _clean(item.title); @@ -205,7 +205,7 @@ function extract_release_data() { discs.push({ title: '', // medium_title, format: 'CD', - tracks: tracks + tracks: tracks, }); } medium_title = item.title; @@ -216,7 +216,7 @@ function extract_release_data() { discs.push({ title: '', // nodes[0].title, format: 'CD', - tracks: tracks + tracks: tracks, }); return { @@ -236,10 +236,10 @@ function extract_release_data() { urls: [ { link_type: 288, // 'discography' - url: document.URL - } + url: document.URL, + }, ], - discs: discs + discs: discs, }; } @@ -248,23 +248,23 @@ function extract_track_data(node) { console.log('artistString', artistString); let artists; if (artistString.includes(' | ')) { - artists = artistString.split(' | ').map(function(artist) { + artists = artistString.split(' | ').map(function (artist) { return { credited_name: artist.split(',')[0], artist_name: artist.split(',')[0], artist_mbid: '', - joinphrase: ', ' + joinphrase: ', ', }; }); } else { - artists = artistString.split(', ').map(function(artist, idx) { + artists = artistString.split(', ').map(function (artist, idx) { let mbid = ''; let url = `/ws/js/artist/?q=${artist}&fmt=json&limit=1`; return { credited_name: artist, artist_name: artist, artist_mbid: mbid, - joinphrase: ', ' + joinphrase: ', ', }; }); } @@ -282,14 +282,8 @@ function extract_track_data(node) { } else { console.log('no meta data on ', node); schema.name = node.querySelectorAll('div.track-text > a.fancy')[0].textContent; - schema.byArtist = $(node) - .parent() - .nextAll('div.container-container') - .children('.artists-container')[0].textContent; - let previousComposers = $(node) - .parent() - .prevAll('div.container-container') - .children('.first-composer-container'); + schema.byArtist = $(node).parent().nextAll('div.container-container').children('.artists-container')[0].textContent; + let previousComposers = $(node).parent().prevAll('div.container-container').children('.first-composer-container'); schema.creator = previousComposers[previousComposers.length - 1].textContent; } console.info('schema', schema); @@ -300,7 +294,7 @@ function extract_track_data(node) { artist_credit: _setTrackArtists(schema.byArtist), // CSG performer: schema.byArtist, composer: schema.creator, - url: node.querySelectorAll('div.track-text > a.fancy')[0].href + url: node.querySelectorAll('div.track-text > a.fancy')[0].href, }; } @@ -321,7 +315,7 @@ function insertMBSection(release) { $('#mb_buttons').css({ display: 'inline-block', - width: '100%' + width: '100%', }); $('form.musicbrainz_import').css({ width: '49%', display: 'inline-block' }); $('form.musicbrainz_import_search').css({ float: 'right' }); diff --git a/discogs_importer.user.js b/discogs_importer.user.js index 892dce7..da878e1 100644 --- a/discogs_importer.user.js +++ b/discogs_importer.user.js @@ -36,15 +36,12 @@ if (DEBUG) { var mblinks = new MBLinks('DISCOGS_MBLINKS_CACHE', '1'); -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); MBSearchItStyle(); let current_page_key = getDiscogsLinkKey( - window.location.href - .replace(/\?.*$/, '') - .replace(/#.*$/, '') - .replace('/master/view/', '/master/') + window.location.href.replace(/\?.*$/, '').replace(/#.*$/, '').replace('/master/view/', '/master/') ); if (!current_page_key) return; @@ -66,7 +63,7 @@ $(document).ready(function() { url: discogsWsUrl, dataType: 'json', crossDomain: true, - success: function(data, textStatus, jqXHR) { + success: function (data, textStatus, jqXHR) { LOGGER.debug('Discogs JSON Data from API:', data); try { let release = parseDiscogsRelease(data); @@ -86,10 +83,10 @@ $(document).ready(function() { throw e; } }, - error: function(jqXHR, textStatus, errorThrown) { + error: function (jqXHR, textStatus, errorThrown) { LOGGER.error('AJAX Status: ', textStatus); LOGGER.error('AJAX error thrown: ', errorThrown); - } + }, }); } }); @@ -102,7 +99,7 @@ $(document).ready(function() { function insertMBLinks(current_page_key) { function searchAndDisplayMbLinkInSection($tr, discogs_type, mb_type, nosearch) { if (!mb_type) mb_type = defaultMBtype(discogs_type); - $tr.find(`a[mlink^="${discogs_type}/"]`).each(function() { + $tr.find(`a[mlink^="${discogs_type}/"]`).each(function () { let $link = $(this); if ($link.attr('mlink_stop')) return; // for places let mlink = $link.attr('mlink'); @@ -115,7 +112,7 @@ function insertMBLinks(current_page_key) { $link.attr( 'mlink_done', done - .filter(function(e) { + .filter(function (e) { return e != ''; }) .join(',') @@ -134,7 +131,7 @@ function insertMBLinks(current_page_key) { release: { mark: 'R' }, 'release-group': { mark: 'G' }, place: { mark: 'P' }, - label: { mark: 'L' } + label: { mark: 'L' }, }; let mark = ''; let entity_name = 'entity'; @@ -151,15 +148,12 @@ function insertMBLinks(current_page_key) { )}">${mark}?` ); } - let insert_normal = function(link) { + let insert_normal = function (link) { $link.closest('span.mb_valign').before(`${link}`); - $link - .closest('span.mb_wrapper') - .find('.mb_searchit') - .remove(); + $link.closest('span.mb_wrapper').find('.mb_searchit').remove(); }; - let insert_stop = function(link) { + let insert_stop = function (link) { insert_normal(link); $link.attr('mlink_stop', true); }; @@ -188,7 +182,7 @@ function insertMBLinks(current_page_key) { '#B3FFC6', '#B3FFEC', '#B3ECFF', - '#7598FF' + '#7598FF', ]; if (DEBUG) { $(what).css('border', `2px dotted ${colors[n % colors.length]}`); @@ -213,7 +207,7 @@ function insertMBLinks(current_page_key) { // just one string types = [types]; } - $.each(types, function(idx, val) { + $.each(types, function (idx, val) { if (!$.isArray(val)) { types[idx] = [val, undefined]; } @@ -221,12 +215,12 @@ function insertMBLinks(current_page_key) { LOGGER.debug(`add_mblinks: ${selector} / ${JSON.stringify(types)}`); - _root.find(selector).each(function() { + _root.find(selector).each(function () { let node = $(this).get(0); magnifyLinks(node); debug_color(this, ++add_mblinks_counter, selector); let that = this; - $.each(types, function(idx, val) { + $.each(types, function (idx, val) { let discogs_type = val[0]; let mb_type = val[1]; searchAndDisplayMbLinkInSection($(that), discogs_type, mb_type, nosearch); @@ -235,7 +229,7 @@ function insertMBLinks(current_page_key) { } // Find MB link for the current page and display it next to page title - let mbLinkInsert = function(link) { + let mbLinkInsert = function (link) { let $h1 = $('h1'); let $titleSpan = $h1.children('span[itemprop="name"]'); if ($titleSpan.length > 0) { @@ -301,7 +295,7 @@ function getDiscogsLinkKey(url) { link_infos[key] = { type: m[1], id: m[2], - clean_url: `https://www.discogs.com/${m[1]}/${m[2]}` + clean_url: `https://www.discogs.com/${m[1]}/${m[2]}`, }; LOGGER.debug(`getDiscogsLinkKey:${url} --> ${key}`); } else { @@ -415,7 +409,7 @@ function insertMBSection(release, current_page_key) { $('#mb_buttons').css({ display: 'inline-block', - width: '100%' + width: '100%', }); $('form.musicbrainz_import').css({ width: '49%', display: 'inline-block' }); $('form.musicbrainz_import_search').css({ float: 'right' }); @@ -446,7 +440,7 @@ function artistNoNum(artist_name) { // Parse a US date string and set object properties year, month, day function parse_YYYY_MM_DD(date, obj) { if (!date) return; - let m = date.split(/\D+/, 3).map(function(e) { + let m = date.split(/\D+/, 3).map(function (e) { return parseInt(e, 10); }); if (m[0] !== undefined) { @@ -472,12 +466,12 @@ function parseDiscogsRelease(data) { // Release artist credit release.artist_credit = []; - $.each(discogsRelease.artists, function(index, artist) { + $.each(discogsRelease.artists, function (index, artist) { let ac = { artist_name: artistNoNum(artist.name), credited_name: artist.anv != '' ? artist.anv : artistNoNum(artist.name), joinphrase: decodeDiscogsJoinphrase(artist.join), - mbid: MBIDfromUrl(artist.resource_url, 'artist') + mbid: MBIDfromUrl(artist.resource_url, 'artist'), }; if (artist.id == 194) { // discogs place holder for various @@ -508,11 +502,11 @@ function parseDiscogsRelease(data) { // Release labels release.labels = []; if (discogsRelease.labels) { - $.each(discogsRelease.labels, function(index, label) { + $.each(discogsRelease.labels, function (index, label) { let labelinfo = { name: label.name, catno: label.catno == 'none' ? '[none]' : label.catno, - mbid: MBIDfromUrl(label.resource_url, 'label') + mbid: MBIDfromUrl(label.resource_url, 'label'), }; release.labels.push(labelinfo); }); @@ -535,7 +529,7 @@ function parseDiscogsRelease(data) { } if (discogsRelease.formats[i].descriptions) { - $.each(discogsRelease.formats[i].descriptions, function(index, desc) { + $.each(discogsRelease.formats[i].descriptions, function (index, desc) { if (!(discogs_format in ['Box Set'])) { // Release format: special handling of Vinyl and Shellac 7", 10" and 12" if (desc.match(/7"|10"|12"/) && discogs_format.concat(desc) in MediaTypes) @@ -579,7 +573,7 @@ function parseDiscogsRelease(data) { // Barcode if (discogsRelease.identifiers) { - $.each(discogsRelease.identifiers, function(index, identifier) { + $.each(discogsRelease.identifiers, function (index, identifier) { if (identifier.type == 'Barcode') { release.barcode = identifier.value.replace(/ /g, ''); return false; @@ -593,7 +587,7 @@ function parseDiscogsRelease(data) { let heading = ''; let releaseNumber = 1; let lastPosition = 0; - $.each(discogsRelease.tracklist, function(index, discogsTrack) { + $.each(discogsRelease.tracklist, function (index, discogsTrack) { if (discogsTrack.type_ == 'heading') { heading = discogsTrack.title; return; @@ -610,12 +604,12 @@ function parseDiscogsRelease(data) { // Track artist credit track.artist_credit = []; if (discogsTrack.artists) { - $.each(discogsTrack.artists, function(index, artist) { + $.each(discogsTrack.artists, function (index, artist) { let ac = { artist_name: artistNoNum(artist.name), credited_name: artist.anv != '' ? artist.anv : artistNoNum(artist.name), joinphrase: decodeDiscogsJoinphrase(artist.join), - mbid: MBIDfromUrl(artist.resource_url, 'artist') + mbid: MBIDfromUrl(artist.resource_url, 'artist'), }; track.artist_credit.push(ac); }); @@ -631,7 +625,7 @@ function parseDiscogsRelease(data) { // Append titles of sub-tracks to main track title let subtrack_titles = []; let subtrack_total_duration = 0; - $.each(discogsTrack.sub_tracks, function(subtrack_index, subtrack) { + $.each(discogsTrack.sub_tracks, function (subtrack_index, subtrack) { if (subtrack.type_ != 'track') { return; } @@ -712,7 +706,7 @@ function parseDiscogsRelease(data) { if (!release.discs[discindex]) { let newdisc = { tracks: [], - format: release_formats[discindex] + format: release_formats[discindex], }; if (heading) { newdisc.title = heading; @@ -811,7 +805,7 @@ var MediaTypes = { 'Vinyl7"': '7" Vinyl', 'Vinyl10"': '10" Vinyl', 'Vinyl12"': '12" Vinyl', - 'Lathe Cut': 'Phonograph record' + 'Lathe Cut': 'Phonograph record', }; var Countries = { @@ -1071,5 +1065,5 @@ var Countries = { 'Iran, Islamic Republic of': 'IR', 'Saint Pierre and Miquelon': 'PM', 'Saint Helena': 'SH', - 'Svalbard and Jan Mayen': 'SJ' + 'Svalbard and Jan Mayen': 'SJ', }; diff --git a/encyclopedisque_importer.user.js b/encyclopedisque_importer.user.js index b852701..d76af6b 100644 --- a/encyclopedisque_importer.user.js +++ b/encyclopedisque_importer.user.js @@ -17,7 +17,7 @@ var mblinks = new MBLinks('ENCYLOPEDISQUE_MBLINKS_CACHE'); -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); if (window.location.href.match(/encyclopedisque\.fr\/disque\/(\d+)/)) { @@ -47,31 +47,31 @@ function setupImportUI(release) { function insertMBLinks() { let current_url = window.location.href; if (current_url.match(/\/disque\//)) { - mblinks.searchAndDisplayMbLink(current_url, 'release', function(link) { + mblinks.searchAndDisplayMbLink(current_url, 'release', function (link) { $('h2 span').before(link); }); } else if (current_url.match(/\/artiste\//)) { - mblinks.searchAndDisplayMbLink(current_url, 'artist', function(link) { + mblinks.searchAndDisplayMbLink(current_url, 'artist', function (link) { $('h2').prepend(link); }); } $('div.v7P, div.v12P') .find('a[href*="/disque/"]') - .each(function() { + .each(function () { let $link = $(this); let external_url = window.location.origin + $link.attr('href'); - mblinks.searchAndDisplayMbLink(external_url, 'release', function(link) { + mblinks.searchAndDisplayMbLink(external_url, 'release', function (link) { $link.after(link).after('
'); }); }); $('h2, div.main') .find('a[href*="/artiste/"]') - .each(function() { + .each(function () { let $link = $(this); let external_url = window.location.origin + $link.attr('href'); - mblinks.searchAndDisplayMbLink(external_url, 'artist', function(link) { + mblinks.searchAndDisplayMbLink(external_url, 'artist', function (link) { $link.before(link); }); }); @@ -162,7 +162,7 @@ function parseEncyclopedisquePage() { release.labels = []; let labels = m[3]; if (labels != undefined) { - $.each(labels.split('/'), function(index, label) { + $.each(labels.split('/'), function (index, label) { release.labels.push({ name: label.trim(), catno: m[4] }); }); } else { @@ -213,7 +213,7 @@ function parseEncyclopedisquePage() { // Format => medium format, release-group type, release status var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim(); let values = infoValue.split(' / '); - values.forEach(function(value) { + values.forEach(function (value) { if (value.indexOf('45 tours') > -1) { disc.format = '7" Vinyl'; } diff --git a/expand-collapse-release-groups.user.js b/expand-collapse-release-groups.user.js index 6722c61..eb76759 100644 --- a/expand-collapse-release-groups.user.js +++ b/expand-collapse-release-groups.user.js @@ -58,14 +58,14 @@ function inject_release_group_button(parent) { let button = create_button( `/ws/2/release?release-group=${mbid}&limit=100&inc=media&fmt=json`, - function(toggled) { + function (toggled) { if (toggled) parent.appendChild(table); else parent.removeChild(table); }, - function(json) { + function (json) { parse_release_group(json, mbid, parent, table); }, - function(status) { + function (status) { table.innerHTML = `Error loading release group (HTTP status ${status})`; } ); @@ -83,14 +83,14 @@ function inject_release_button(parent, _table_parent, _table, _mbid) { let button = create_button( `/ws/2/release/${mbid}?inc=media+recordings+artist-credits&fmt=json`, - function(toggled) { + function (toggled) { if (toggled) parent.appendChild(table); else parent.removeChild(table); }, - function(json) { + function (json) { parse_release(json, table); }, - function(status) { + function (status) { table.innerHTML = `Error loading release (HTTP status ${status})`; } ); @@ -109,7 +109,7 @@ function create_button(url, dom_callback, success_callback, error_callback) { button.addEventListener( 'mousedown', - function() { + function () { toggled = !toggled; if (toggled) button.innerHTML = '▼'; else button.innerHTML = '▶'; @@ -120,12 +120,12 @@ function create_button(url, dom_callback, success_callback, error_callback) { button.addEventListener( 'mousedown', - function() { + function () { let this_event = arguments.callee; button.removeEventListener('mousedown', this_event, false); let req = new XMLHttpRequest(); - req.onreadystatechange = function() { + req.onreadystatechange = function () { if (req.readyState != 4) return; if (req.status == 200 && req.responseText) { @@ -133,7 +133,7 @@ function create_button(url, dom_callback, success_callback, error_callback) { } else { button.addEventListener( 'mousedown', - function() { + function () { button.removeEventListener('mousedown', arguments.callee, false); button.addEventListener('mousedown', this_event, false); }, @@ -187,14 +187,14 @@ function parse_release_group(json, mbid, parent, table) { release.formats = formats.join(' + '); } - releases.sort(function(a, b) { + releases.sort(function (a, b) { if (a.date < b.date) return -1; if (a.date > b.date) return 1; return 0; }); for (var i = 0; i < releases.length; i++) { - (function(release) { + (function (release) { let track_tr = document.createElement('tr'), track_td = document.createElement('td'), track_table = document.createElement('table'), diff --git a/fast-cancel-edits.user.js b/fast-cancel-edits.user.js index 7fee8cd..efac8ee 100644 --- a/fast-cancel-edits.user.js +++ b/fast-cancel-edits.user.js @@ -77,7 +77,7 @@ function fastCancelScript() { background: '#FFBA58', 'border-top': '1px #000 solid', 'border-left': '1px #000 solid', - padding: '0.5em' + padding: '0.5em', }) .appendTo('body') .hide(); @@ -90,7 +90,7 @@ function fastCancelScript() { } } - document.body.addEventListener('click', function(event) { + document.body.addEventListener('click', function (event) { if (event.target && event.target.tagName && event.target.tagName == 'A' && event.target.classList.contains('negative')) { event.stopPropagation(); event.preventDefault(); @@ -100,7 +100,7 @@ function fastCancelScript() { let $self = $(event.target), $edit = $self.parents('div.edit-list:eq(0)'); - pushRequest(function() { + pushRequest(function () { let editNote = $edit.find('div.add-edit-note textarea').val(); let data = { 'confirm.edit_note': editNote }; @@ -108,35 +108,35 @@ function fastCancelScript() { type: 'POST', url: $self.attr('href'), data: data, - error: function(request, status, error) { + error: function (request, status, error) { $self .css({ background: 'red', color: 'yellow', - cursor: 'help' + cursor: 'help', }) .attr('title', `Error cancelling this edit: “${error}”`); $edit.css({ border: '6px solid red' }).show(); }, - complete: function() { + complete: function () { $edit.remove(); totalCancels -= 1; updateStatus(); - } + }, }); }); $edit.hide(); } }); - $("div#edits > form[action$='/edit/enter_votes']").on('submit', function(event) { + $("div#edits > form[action$='/edit/enter_votes']").on('submit', function (event) { if (totalCancels > 0) { event.preventDefault(); alert(`Please wait, ${totalCancels > 1 ? `${totalCancels} edits are` : 'an edit is'} being cancelled in the background.`); } }); - var pushRequest = (function() { + var pushRequest = (function () { let queue = [], last = 0, active = false, @@ -152,7 +152,7 @@ function fastCancelScript() { } } - return function(req) { + return function (req) { queue.push(req); if (!active) { diff --git a/fma_importer.user.js b/fma_importer.user.js index aa606b5..bd08284 100644 --- a/fma_importer.user.js +++ b/fma_importer.user.js @@ -48,13 +48,13 @@ var release_attributes = {}; // albumid, total_pages, artist_name, label var album_api_array = []; // album information [0] var tracks_api_array = []; // track information [0,1,2,..] one element for each pagination in FMA tracks API -$(document).ready(function() { +$(document).ready(function () { // if we have something on local storage place that if (localStorage.getItem('FMA_API_KEY')) { FMA_API = localStorage.getItem('FMA_API_KEY'); // -> YOURAPIKEY } else { insertAPIKEYSection(); - $('#api_key_submit').click(function() { + $('#api_key_submit').click(function () { let myval = $('#apikey_input').val(); localStorage.setItem('FMA_API_KEY', myval); $('#musicbrainz_apikey').hide(); @@ -87,7 +87,7 @@ $(document).ready(function() { // Track detail $.when(retrieve_track_info) // ensure the track info is retrieved first (total_pages counter) - .then(function() { + .then(function () { // loop and deferred promise for multiple ajax calls updateAPISection.TrackAjaxStatus('busy'); let track_api_calls = []; @@ -95,25 +95,25 @@ $(document).ready(function() { track_api_calls.push(track_api(i)); } - $.when.apply(this, track_api_calls).done(function() { + $.when.apply(this, track_api_calls).done(function () { LOGGER.debug('Tracks loaded and done in DONE lets use it'); //console.log("total_pages " + release_attributes.total_pages); tracks_deferred.resolve(); }); }) - .done(function() { + .done(function () { LOGGER.debug('Deferred for: Track info > track detail > resolved'); }); $.when(retrieve_tracks_promise) - .done(function() { + .done(function () { updateAPISection.TrackAjaxStatus('completed'); }) - .fail(function() { + .fail(function () { updateAPISection.TrackAjaxStatus('fail'); }); - $.when(retrieve_track_info, retrieve_tracks_promise, retrieve_album_detail).done(function() { + $.when(retrieve_track_info, retrieve_tracks_promise, retrieve_album_detail).done(function () { LOGGER.info('All the AJAX API calls are done continue to build the release object ...'); // LOGGER.debug("ALBUM Object > " + album_api_array[0]); // LOGGER.debug("TRACK Object > " + tracks_api_array); @@ -123,17 +123,15 @@ $(document).ready(function() { let album_link = window.location.href; - let url = $(location) - .attr('href') - .split('/'); + let url = $(location).attr('href').split('/'); let artist_url = url[url.length - 3]; let base_url = 'http://freemusicarchive.org/music/'; let artist_link = `${base_url + artist_url}/`; - mblinks.searchAndDisplayMbLink(album_link, 'release', function(link) { + mblinks.searchAndDisplayMbLink(album_link, 'release', function (link) { $('.subh1').before(link); }); - mblinks.searchAndDisplayMbLink(artist_link, 'artist', function(link) { + mblinks.searchAndDisplayMbLink(artist_link, 'artist', function (link) { $('.subh1').after(link); }); }); @@ -169,7 +167,7 @@ function insertAPISection() { if (DEBUG) fmaUI.css({ - border: '1px dotted red' + border: '1px dotted red', }); let fmaStatusBlock = $( @@ -183,7 +181,7 @@ function insertAPISection() { display: 'inline-block', float: 'left', height: '120px', - width: '49%' + width: '49%', }); fmaUI.slideDown(); @@ -191,17 +189,17 @@ function insertAPISection() { // Update FreeMusicArchive API Status section on FMA page var updateAPISection = { - AlbumId: function(albumid) { + AlbumId: function (albumid) { this.albumid = albumid; $('#lbut-lt-fma-api-album-id').text(this.albumid); return 'complete'; }, - ApiKey: function(apikey) { + ApiKey: function (apikey) { this.apikey = apikey; $('#lbut-lt-fma-api-key-id').text(FMA_API); return 'complete'; }, - AlbumAjaxStatus: function(ajaxstatus) { + AlbumAjaxStatus: function (ajaxstatus) { if (ajaxstatus === null) { this.ajaxstatus = 'notcalled'; } else { @@ -212,24 +210,24 @@ var updateAPISection = { case 'completed': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-album').css({ - 'background-color': 'green' + 'background-color': 'green', }); break; case 'busy': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-album').css({ - 'background-color': 'orange' + 'background-color': 'orange', }); break; case 'fail': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-album').css({ - 'background-color': 'red' + 'background-color': 'red', }); break; } }, - TrackAjaxStatus: function(ajaxstatus) { + TrackAjaxStatus: function (ajaxstatus) { if (ajaxstatus === null) { this.ajaxstatus = 'notcalled'; } else { @@ -240,23 +238,23 @@ var updateAPISection = { case 'completed': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-tracks').css({ - 'background-color': 'green' + 'background-color': 'green', }); break; case 'busy': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-tracks').css({ - 'background-color': 'orange' + 'background-color': 'orange', }); break; case 'fail': // Definition is that api call was successfull hence busy retrieving data //test chaging status of album api to error retrieving data after 2 seconds $('#lbut-lt-fma-api-tracks').css({ - 'background-color': 'red' + 'background-color': 'red', }); break; } - } + }, }; // Insert MusicBrainz section on FMA page @@ -268,7 +266,7 @@ function insertMBSection(release) { ).hide(); if (DEBUG) mbUI.css({ - border: '1px dotted red' + border: '1px dotted red', }); let mbContentBlock = $('
'); @@ -279,7 +277,7 @@ function insertMBSection(release) { color: 'red', float: 'left', 'margin-top': '4px', - 'margin-bottom': '4px' + 'margin-bottom': '4px', }); mbContentBlock.prepend(warning_buggy); } @@ -300,25 +298,25 @@ function insertMBSection(release) { display: 'block', float: 'right', height: '120px', - width: '49%' + width: '49%', }); $('#mb_buttons').css({ display: 'inline-block', float: 'right', - height: '80px' + height: '80px', }); $('form.musicbrainz_import').css({ width: '49%', - display: 'inline-block' + display: 'inline-block', }); $('form.musicbrainz_import_search').css({ - float: 'right' + float: 'right', }); $('form.musicbrainz_import > button').css({ width: '63px', height: '80px', - 'box-sizing': 'border-box' + 'box-sizing': 'border-box', }); mbUI.slideDown(); @@ -333,7 +331,7 @@ function insertAPIKEYSection() { ).hide(); if (DEBUG) mbUI.css({ - border: '1px dotted red' + border: '1px dotted red', }); let mbContentBlock = $('
'); @@ -351,13 +349,13 @@ function insertAPIKEYSection() { display: 'block', float: 'right', height: '120px', - width: '49%' + width: '49%', }); $('#mb_buttons').css({ display: 'inline-block', float: 'right', - height: '80px' + height: '80px', }); mbUI.slideDown(); @@ -371,10 +369,10 @@ function insertAPIKEYSection() { function album_api() { let fmaWsUrl = `https://freemusicarchive.org/api/get/albums.json?api_key=${FMA_API}&album_id=${release_attributes.albumid}`; - var promise_variable = $.getJSON(fmaWsUrl, function() { + var promise_variable = $.getJSON(fmaWsUrl, function () { updateAPISection.AlbumAjaxStatus('busy'); LOGGER.debug(`promise_variable [state] in [getJSON] ${promise_variable.state()}`); - }).done(function(albumjson) { + }).done(function (albumjson) { LOGGER.debug(' >> Album > DONE'); updateAPISection.AlbumAjaxStatus('completed'); //LOGGER.debug(albumjson); @@ -389,9 +387,9 @@ function album_api() { function track_api_parameters() { let fmaWsUrl = `https://freemusicarchive.org/api/get/tracks.json?api_key=${FMA_API}&album_id=${release_attributes.albumid}&limit=20`; - var promise_track_api_params = $.getJSON(fmaWsUrl, function() { + var promise_track_api_params = $.getJSON(fmaWsUrl, function () { LOGGER.debug(`promise_track_api_params [state] in [getJSON] ${promise_track_api_params.state()}`); - }).done(function(trackinfojson) { + }).done(function (trackinfojson) { LOGGER.debug(' >> Track INFO > DONE'); release_attributes.total_pages = trackinfojson.total_pages; //LOGGER.debug(trackinfojson); @@ -406,9 +404,9 @@ function track_api(page) { release_attributes.albumid }&limit=20&page=${parseInt(page)}`; - var promise_track_api = $.getJSON(fmaWsUrl, function() { + var promise_track_api = $.getJSON(fmaWsUrl, function () { LOGGER.debug(`promise_track_api_params [state] in [getJSON] ${promise_track_api.state()}`); - }).done(function(tracksjson) { + }).done(function (tracksjson) { LOGGER.debug(` >> Track page ${page} > DONE `); LOGGER.debug(tracksjson); tracks_api_array.push(tracksjson.dataset); @@ -446,17 +444,11 @@ function parseFMApage() { } // Label parsed from webpage as it is not in API - $('div.sbar-stat span.lf105.stathd').each(function() { + $('div.sbar-stat span.lf105.stathd').each(function () { //var tester = $(this).eq(0).text().trim().toLowerCase(); // working - let taglist = $(this) - .eq(0) - .text() - .trim() - .toLowerCase(); + let taglist = $(this).eq(0).text().trim().toLowerCase(); if (taglist == 'label:') { - release_attributes.label = $(this) - .next() - .text(); + release_attributes.label = $(this).next().text(); // fmarelease.labels.push({ // name: FMAAlbumLabel // }); @@ -473,7 +465,7 @@ function parseFMApage() { // Parse the date string and set object properties day, month, year function parse_MM_DD_YYYY(date, obj) { if (!date) return; - let m = date.split(/\D+/, 3).map(function(e) { + let m = date.split(/\D+/, 3).map(function (e) { return parseInt(e, 10); }); if (m[0] !== undefined) { @@ -557,13 +549,13 @@ function Parsefmarelease(albumobject, trackobject) { // Release URL fmarelease.urls.push({ url: albumobject.album_url, - link_type: MBImport.URL_TYPES.download_for_free + link_type: MBImport.URL_TYPES.download_for_free, }); } else { // Release URL fmarelease.urls.push({ url: albumobject.album_url, - link_type: MBImport.URL_TYPES.other_databases + link_type: MBImport.URL_TYPES.other_databases, }); } @@ -572,7 +564,7 @@ function Parsefmarelease(albumobject, trackobject) { // Release URL fmarelease.urls.push({ url: albumobject.album_url, - link_type: MBImport.URL_TYPES.stream_for_free + link_type: MBImport.URL_TYPES.stream_for_free, }); } @@ -583,7 +575,7 @@ function Parsefmarelease(albumobject, trackobject) { // Label parsed from webpage as it is not in API fmarelease.labels.push({ - name: release_attributes.label + name: release_attributes.label, }); let discarray = []; @@ -612,7 +604,7 @@ function Parsefmarelease(albumobject, trackobject) { // Could not find a example where disc_number != 1 yet but started teh check so long let largest_disc = Math.max.apply( Math, - trackarray.map(function(o) { + trackarray.map(function (o) { return o.disc_number; }) ); @@ -620,14 +612,14 @@ function Parsefmarelease(albumobject, trackobject) { for (var disccount = 1; disccount <= largest_disc; disccount++) { // use this to map all the objects from trackarray with disc_number value of disccount to a new object - let tracklist_per_disc = $.map(trackarray, function(obj, index) { + let tracklist_per_disc = $.map(trackarray, function (obj, index) { if (obj.disc_number == disccount) { return obj; } }); // use this to sort the tracks per disc from low to high - tracklist_per_disc = tracklist_per_disc.sort(function(a, b) { + tracklist_per_disc = tracklist_per_disc.sort(function (a, b) { return parseInt(a.number) - parseInt(b.number); }); @@ -646,7 +638,7 @@ function Parsefmarelease(albumobject, trackobject) { let disc = { position: disccount, format: 'Digital Media', - tracks: tracklist_per_disc + tracks: tracklist_per_disc, }; fmarelease.discs.push(disc); } diff --git a/juno_download_importer.user.js b/juno_download_importer.user.js index 66ebaa0..547205e 100644 --- a/juno_download_importer.user.js +++ b/juno_download_importer.user.js @@ -17,7 +17,7 @@ // prevent JQuery conflicts, see http://wiki.greasespot.net/@grant this.$ = this.jQuery = jQuery.noConflict(true); -$(document).ready(function() { +$(document).ready(function () { MBImportStyle(); let releaseUrl = window.location.href.replace('/?.*$/', '').replace(/#.*$/, ''); let release = retrieveReleaseInfo(releaseUrl); @@ -37,7 +37,7 @@ function parseReleaseDate(rdate) { September: 9, October: 10, November: 11, - December: 12 + December: 12, }; let m = rdate.match(/(\d{1,2}) ([a-z]+), (\d{4})/i); @@ -45,7 +45,7 @@ function parseReleaseDate(rdate) { return { year: m[3], month: months[m[2]], - day: m[1] + day: m[1], }; } @@ -55,9 +55,7 @@ function parseReleaseDate(rdate) { function retrieveReleaseInfo(release_url) { let release = { artist_credit: [], - title: $('meta[itemProp="name"]') - .attr('content') - .trim(), + title: $('meta[itemProp="name"]').attr('content').trim(), year: 0, month: 0, day: 0, @@ -70,14 +68,10 @@ function retrieveReleaseInfo(release_url) { type: '', urls: [], labels: [], - discs: [] + discs: [], }; - let releaseDate = parseReleaseDate( - $('span[itemProp="datePublished"]') - .text() - .trim() - ); + let releaseDate = parseReleaseDate($('span[itemProp="datePublished"]').text().trim()); if (releaseDate) { release.year = releaseDate.year; @@ -87,54 +81,36 @@ function retrieveReleaseInfo(release_url) { release.urls.push({ url: release_url, - link_type: MBImport.URL_TYPES.purchase_for_download + link_type: MBImport.URL_TYPES.purchase_for_download, }); release.labels.push({ - name: $('meta[itemProp="author"]') - .attr('content') - .trim(), - catno: $('strong:contains("Cat:")') - .parent() - .contents() - .slice(2, 3) - .text() - .trim() + name: $('meta[itemProp="author"]').attr('content').trim(), + catno: $('strong:contains("Cat:")').parent().contents().slice(2, 3).text().trim(), }); let tracks = []; - $('.product-tracklist-track[itemprop="track"]').each(function() { + $('.product-tracklist-track[itemprop="track"]').each(function () { // element only present if VA release or track has multiple artists - let artist = $(this) - .find('meta[itemprop="byArtist"]') - .attr('content'); + let artist = $(this).find('meta[itemprop="byArtist"]').attr('content'); if (artist !== undefined) { artist = artist.trim(); } - let trackname = $(this) - .find('span[itemprop="name"]') - .text() - .trim(); - let tracklength = $(this) - .find('meta[itemprop="duration"]') - .parent() - .contents() - .slice(0, 1) - .text() - .trim(); + let trackname = $(this).find('span[itemprop="name"]').text().trim(); + let tracklength = $(this).find('meta[itemprop="duration"]').parent().contents().slice(0, 1).text().trim(); if (artist !== undefined && trackname.startsWith(`${artist} - `)) { trackname = trackname.replace(`${artist} - `, ''); } tracks.push({ artist_credit: MBImport.makeArtistCredits(artist === undefined ? [] : [artist]), title: trackname, - duration: tracklength + duration: tracklength, }); }); let releaseArtists = $('.product-artist') .contents() - .map(function() { + .map(function () { if (this.nodeType === Node.TEXT_NODE) { return this.nodeValue === ' / ' ? null : this.nodeValue; } else { @@ -151,7 +127,7 @@ function retrieveReleaseInfo(release_url) { release.discs.push({ tracks: tracks, - format: release.format + format: release.format, }); LOGGER.info('Parsed release: ', release); @@ -168,9 +144,7 @@ function insertLink(release, releaseUrl) { )}` ).hide(); - $('.product-share') - .parent() - .after(mbUI); + $('.product-share').parent().after(mbUI); $('#mb_buttons form').css({ display: 'inline', 'margin-right': '5px' }); mbUI.slideDown(); } diff --git a/lib/logger.js b/lib/logger.js index b3f4d5f..80411c1 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -2,7 +2,7 @@ // Logger /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var LOGGER = (function() { +var LOGGER = (function () { let LOG_LEVEL = 'info'; function fnDebug() { @@ -44,6 +44,6 @@ var LOGGER = (function() { debug: fnDebug, info: fnInfo, error: fnError, - setLevel: fnSetLevel + setLevel: fnSetLevel, }; })(); diff --git a/lib/mbimport.js b/lib/mbimport.js index 46399b2..ce0f60e 100644 --- a/lib/mbimport.js +++ b/lib/mbimport.js @@ -58,18 +58,18 @@ * */ -var MBImport = (function() { +var MBImport = (function () { // --------------------------------------- publics ----------------------------------------- // let special_artists = { various_artists: { name: 'Various Artists', - mbid: '89ad4ac3-39f7-470e-963a-56509c546377' + mbid: '89ad4ac3-39f7-470e-963a-56509c546377', }, unknown: { name: '[unknown]', - mbid: '125ec42a-7229-4250-afc5-e057484327fe' - } + mbid: '125ec42a-7229-4250-afc5-e057484327fe', + }, }; let url_types = { @@ -79,7 +79,7 @@ var MBImport = (function() { purchase_for_mail_order: 79, other_databases: 82, stream_for_free: 85, - license: 301 + license: 301, }; function fnSpecialArtist(key, ac) { @@ -92,7 +92,7 @@ var MBImport = (function() { artist_name: special_artists[key].name, credited_name: credited_name, joinphrase: joinphrase, - mbid: special_artists[key].mbid + mbid: special_artists[key].mbid, }; } @@ -100,7 +100,7 @@ var MBImport = (function() { function fnBuildSearchLink(release) { let parameters = searchParams(release); let url_params = []; - parameters.forEach(function(parameter) { + parameters.forEach(function (parameter) { let value = `${parameter.value}`; url_params.push(encodeURI(`${parameter.name}=${value}`)); }); @@ -111,7 +111,7 @@ var MBImport = (function() { function fnBuildSearchButton(release) { let parameters = searchParams(release); let html = `