From 73fac72d7b8b266dc300678e077a5dba093b77fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Tue, 20 Nov 2018 23:23:38 +0100 Subject: [PATCH 1/4] Use template literals for css blocks --- lib/mbimportstyle.js | 126 +++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/lib/mbimportstyle.js b/lib/mbimportstyle.js index 99bd1b5..ad31cb9 100644 --- a/lib/mbimportstyle.js +++ b/lib/mbimportstyle.js @@ -3,73 +3,71 @@ function _add_css(css) { } function MBImportStyle() { - let css_import_button = - ' \ - .musicbrainz_import button { \ - -moz-border-radius:5px; \ - -webkit-border-radius:5px; \ - border-radius:5px; \ - display:inline-block; \ - cursor:pointer; \ - font-family:Arial; \ - font-size:12px !important; \ - padding:3px 6px; \ - text-decoration:none; \ - border: 1px solid rgba(180,180,180,0.8) !important; \ - background-color: rgba(240,240,240,0.8) !important; \ - color: #334 !important; \ - height: 26px ;\ - } \ - .musicbrainz_import button:hover { \ - background-color: rgba(250,250,250,0.9) !important; \ - } \ - .musicbrainz_import button:active { \ - background-color: rgba(170,170,170,0.8) !important; \ - } \ - .musicbrainz_import button img { \ - vertical-align: middle !important; \ - margin-right: 4px !important; \ - height: 16px; \ - } \ - .musicbrainz_import button span { \ - min-height: 16px; \ - display: inline-block; \ - } \ - '; + let css_import_button = ` + .musicbrainz_import button { + -moz-border-radius:5px; + -webkit-border-radius:5px; + border-radius:5px; + display:inline-block; + cursor:pointer; + font-family:Arial; + font-size:12px !important; + padding:3px 6px; + text-decoration:none; + border: 1px solid rgba(180,180,180,0.8) !important; + background-color: rgba(240,240,240,0.8) !important; + color: #334 !important; + height: 26px ; + } + .musicbrainz_import button:hover { + background-color: rgba(250,250,250,0.9) !important; + } + .musicbrainz_import button:active { + background-color: rgba(170,170,170,0.8) !important; + } + .musicbrainz_import button img { + vertical-align: middle !important; + margin-right: 4px !important; + height: 16px; + } + .musicbrainz_import button span { + min-height: 16px; + display: inline-block; + } + `; _add_css(css_import_button); } function MBSearchItStyle() { - let css_search_it = - ' \ - .mb_valign { \ - display: inline-block; \ - vertical-align: top; \ - } \ - .mb_searchit { \ - width: 16px; \ - height: 16px; \ - margin: 0; \ - padding: 0; \ - background-color: #FFF7BE; \ - border: 0px; \ - vertical-align: top; \ - font-size: 11px; \ - text-align: center; \ - } \ - a.mb_search_link { \ - color: #888; \ - text-decoration: none; \ - } \ - a.mb_search_link small { \ - font-size: 8px; \ - } \ - .mb_searchit a.mb_search_link:hover { \ - color: darkblue; \ - } \ - .mb_wrapper { \ - display: inline-block; \ - } \ - '; + let css_search_it = ` + .mb_valign { + display: inline-block; + vertical-align: top; + } + .mb_searchit { + width: 16px; + height: 16px; + margin: 0; + padding: 0; + background-color: #FFF7BE; + border: 0px; + vertical-align: top; + font-size: 11px; + text-align: center; + } + a.mb_search_link { + color: #888; + text-decoration: none; + } + a.mb_search_link small { + font-size: 8px; + } + .mb_searchit a.mb_search_link:hover { + color: darkblue; + } + .mb_wrapper { + display: inline-block; + } + `; _add_css(css_search_it); } From 14d9606e2e5e2f9aa8a7fb78a3bf67132fd557ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Tue, 20 Nov 2018 23:28:53 +0100 Subject: [PATCH 2/4] Fix "no-empty" eslint rule --- .eslintrc.json | 1 - batch-add-recording-relationships.user.js | 7 ++++--- lib/logger.js | 4 +++- mb_discids_detector.user.js | 2 -- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3a0ad10..0a8abb5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,7 +10,6 @@ "prettier/prettier": "error", "prefer-template": "error", "no-console": "off", - "no-empty": "warn", "no-inner-declarations": "warn", "no-global-assign": "warn", "no-redeclare": "warn", diff --git a/batch-add-recording-relationships.user.js b/batch-add-recording-relationships.user.js index 5fd6b41..9244e14 100644 --- a/batch-add-recording-relationships.user.js +++ b/batch-add-recording-relationships.user.js @@ -453,10 +453,11 @@ function batch_recording_rels() { let parsedDate = parseDate(this.value); if ( - (parsedDate.year || parsedDate.month || parsedDate.day) && - isDateValid(parsedDate.year, parsedDate.month, parsedDate.day) + !( + (parsedDate.year || parsedDate.month || parsedDate.day) && + isDateValid(parsedDate.year, parsedDate.month, parsedDate.day) + ) ) { - } else { $input.css('border-color', '#f00'); parsedDate = null; } diff --git a/lib/logger.js b/lib/logger.js index f911374..35609e3 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -37,7 +37,9 @@ var LOGGER = (function() { if (console && console.log && console.log.apply) { try { console.log.apply(this, args); - } catch (e) {} + } catch (e) { + // do nothing + } } } diff --git a/mb_discids_detector.user.js b/mb_discids_detector.user.js index ba036cd..afe2c9f 100644 --- a/mb_discids_detector.user.js +++ b/mb_discids_detector.user.js @@ -377,12 +377,10 @@ var MBDiscid = (function() { while (input.length < totalChars) { input = padWith + input; } - } else { } if (input.length > totalChars) { //if padWith was a multiple character string and num was overpadded input = input.substring(input.length - totalChars, totalChars); - } else { } return input; From 785b7908876bceac0034a3166ba5c9d1f6447f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Tue, 20 Nov 2018 23:37:47 +0100 Subject: [PATCH 3/4] Fix "use-isnan" eslint rule --- .eslintrc.json | 3 +-- lib/mbimport.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0a8abb5..0228d30 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,7 +18,6 @@ "no-useless-concat": "warn", "no-useless-escape": "warn", "no-unused-vars": "warn", - "no-var": "warn", - "use-isnan": "warn" + "no-var": "warn" } } diff --git a/lib/mbimport.js b/lib/mbimport.js index ec06227..44b6555 100644 --- a/lib/mbimport.js +++ b/lib/mbimport.js @@ -318,7 +318,7 @@ var MBImport = (function() { // convert HH:MM:SS or MM:SS to milliseconds function hmsToMilliSeconds(str) { - if (typeof str == 'undefined' || str === null || str === NaN || str === '') return NaN; + if (typeof str == 'undefined' || str === null || isNaN(str) || str === '') return NaN; if (typeof str == 'number') return str; let t = str.split(':'); let s = 0; From a7376b5336c51dea5122854cffe2d458dc2c5c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Tue, 20 Nov 2018 23:45:38 +0100 Subject: [PATCH 4/4] Fix a few "no-useless-concat" warnings --- batch-add-recording-relationships.user.js | 9 ++++----- dgdecca_importer.user.js | 2 +- mb_discids_detector.user.js | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/batch-add-recording-relationships.user.js b/batch-add-recording-relationships.user.js index 9244e14..feaf217 100644 --- a/batch-add-recording-relationships.user.js +++ b/batch-add-recording-relationships.user.js @@ -533,7 +533,7 @@ function batch_recording_rels() { get_filtered_page(0); } else { queue_recordings_request( - `/ws/2/recording?artist=${ARTIST_MBID}&inc=work-rels` + `&limit=100` + `&offset=${(CURRENT_PAGE - 1) * 100}&fmt=json` + `/ws/2/recording?artist=${ARTIST_MBID}&inc=work-rels&limit=100&offset=${(CURRENT_PAGE - 1) * 100}&fmt=json` ); } @@ -600,10 +600,9 @@ function batch_recording_rels() { } function get_filtered_page(page) { - let url = - `/ws/2/recording?query=${NAME_FILTER ? `${encodeURIComponent(NAME_FILTER)}%20AND%20` : ''}${ - ARTIST_FILTER ? `creditname:${encodeURIComponent(ARTIST_FILTER)}%20AND%20` : '' - } arid:${ARTIST_MBID}&limit=100` + `&offset=${page * 100}&fmt=json`; + let url = `/ws/2/recording?query=${NAME_FILTER ? `${encodeURIComponent(NAME_FILTER)}%20AND%20` : ''}${ + 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) { diff --git a/dgdecca_importer.user.js b/dgdecca_importer.user.js index 75b5b2e..5ce7c4c 100644 --- a/dgdecca_importer.user.js +++ b/dgdecca_importer.user.js @@ -53,7 +53,7 @@ var labels = { } }; -var editNote = `Imported from ${document.URL}\n —\n` + `GM script: "${meta.name}" (${meta.version})\n\n`; +var editNote = `Imported from ${document.URL}\n —\nGM script: "${meta.name}" (${meta.version})\n\n`; function _clean(s) { return s diff --git a/mb_discids_detector.user.js b/mb_discids_detector.user.js index afe2c9f..b503d9e 100644 --- a/mb_discids_detector.user.js +++ b/mb_discids_detector.user.js @@ -190,7 +190,7 @@ function gazellePageHandler() { // Common functions function computeAttachURL(mb_toc_numbers, artistName, releaseName) { - let url = `${'http://musicbrainz.org/cdtoc/attach' + '?toc='}${mb_toc_numbers.join('%20')}&artist-name=${encodeURIComponent( + let url = `${'http://musicbrainz.org/cdtoc/attach?toc='}${mb_toc_numbers.join('%20')}&artist-name=${encodeURIComponent( artistName )}&release-name=${encodeURIComponent(releaseName)}`; return url;