11// ==UserScript==
22// @name Import Bandcamp releases to MusicBrainz
33// @description Add a button on Bandcamp's album pages to open MusicBrainz release editor with pre-filled data for the selected release
4- // @version 2025.12.22 .1
4+ // @version 2025.12.23 .1
55// @namespace http://userscripts.org/users/22504
66// @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js
77// @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/bandcamp_importer.user.js
@@ -323,14 +323,29 @@ $(document).ready(function () {
323323 /***/
324324 let mblinks = new MBLinks ( 'BCI_MBLINKS_CACHE' ) ;
325325 const hasBandData = unsafeWindow . BandData && ! ! unsafeWindow . BandData . id ;
326- const hasAlbumData = unsafeWindow . TralbumData && Object . entries ( unsafeWindow . TralbumData ) . length > 0 ; // Sometimes TralbumData is an empty object, see issue #676
327- const isDiscographyPage = unsafeWindow . TralbumData . url && ! ! unsafeWindow . TralbumData . url . match ( / \/ m u s i c \/ ? $ / ) ;
326+ const hasAlbumData = unsafeWindow . TralbumData && 'current' in unsafeWindow . TralbumData ; // Sometimes TralbumData is an empty object, see issue #676
327+ const isDiscographyPage =
328+ unsafeWindow . TralbumData . url &&
329+ ( ! ! unsafeWindow . TralbumData . url . match ( / \/ m u s i c \/ ? $ / ) || ! ! unsafeWindow . TralbumData . url . match ( / \/ i n d e x p a g e \/ ? $ / ) ) ;
328330
329331 if ( isDiscographyPage ) {
330- const hostname = unsafeWindow . TralbumData . url . replace ( '/music' , '' ) ;
332+ /**
333+ * Discography pages can be in two formats:
334+ * - music: /music/ (default)
335+ * - indexpage: /indexpage/ (new format) e.g. https://arbee.bandcamp.com
336+ */
337+ const discographyFormat = unsafeWindow . TralbumData . url . match ( / \/ m u s i c \/ ? $ / )
338+ ? 'music'
339+ : unsafeWindow . TralbumData . url . match ( / \/ i n d e x p a g e \/ ? $ / )
340+ ? 'indexpage'
341+ : null ;
342+ const hostname = unsafeWindow . TralbumData . url . replace ( '/music' , '' ) . replace ( '/indexpage' , '' ) ;
331343 const urls_data = [ ] ;
332344
333- $ ( 'ol#music-grid > li > a' ) . each ( function ( ) {
345+ const releaseLinksMatcher = discographyFormat === 'music' ? 'ol#music-grid > li > a' : 'span.indexpage_list div.ipCellLabel1 a' ;
346+ const insertionLocationMatcher = discographyFormat === 'music' ? 'p.title' : undefined ;
347+
348+ $ ( releaseLinksMatcher ) . each ( function ( ) {
334349 const $link = $ ( this ) ;
335350 const bandcampReleaseUrl = $link . attr ( 'href' ) ;
336351 const pathName = getPathName ( bandcampReleaseUrl ) ;
@@ -344,7 +359,11 @@ $(document).ready(function () {
344359 url : full_url ,
345360 mb_type : 'release' ,
346361 insert_func : function ( link ) {
347- $ ( 'p.title' , $link ) . prepend ( link ) ;
362+ if ( insertionLocationMatcher ) {
363+ $ ( insertionLocationMatcher , $link ) . prepend ( link ) ;
364+ } else {
365+ $link . prepend ( link ) ;
366+ }
348367 } ,
349368 key : `release:${ full_url } ` ,
350369 } ) ;
0 commit comments