Last active
February 27, 2022 07:20
-
-
Save Klaster1/2f01f54426753768311412520037f9bb to your computer and use it in GitHub Desktop.
Bandcamp (copy release data)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bandcamp (copy release data) | |
// @version 1.3 | |
// @author Klaster_1 | |
// @match https://*.bandcamp.com/album/* | |
// @grant unsafeWindow | |
// @icon https://s4.bcbits.com/img/favicon/favicon-32x32.png | |
// @downloadURL https://gist.github.com/Klaster1/2f01f54426753768311412520037f9bb/raw/bandcamp-copy-release-data.user.js | |
// @updateURL https://gist.github.com/Klaster1/2f01f54426753768311412520037f9bb/raw/bandcamp-copy-release-data.user.js | |
// ==/UserScript== | |
const getRelaseData = () => Array.from(document.querySelectorAll('#track_table .track_row_view')).map(row => { | |
const trackTitleText = row.querySelector('.track-title').textContent | |
return { | |
number: +row.querySelector('.track_number').textContent.replace('.', ''), | |
artists: trackTitleText.includes(' - ') ? trackTitleText.split(/ - /)[0]?.split(', ') : [], | |
title: trackTitleText.includes(' - ') ? trackTitleText.split(/ - /)[1] : trackTitleText, | |
time: row.querySelector('.time').textContent.trim().replace(/^0/, '') | |
} | |
}) | |
const addButton = () => { | |
const button = document.createElement('button') | |
button.textContent = 'Copy release as JSON' | |
button.onclick = () => navigator.clipboard.writeText(JSON.stringify(getRelaseData(), null, ' ')) | |
Object.assign(button.style, { | |
position: 'fixed', | |
right: '0px', | |
bottom: '0px', | |
margin: '20px' | |
}) | |
document.body.appendChild(button) | |
} | |
addButton() | |
const logData = () => { | |
const el = document.querySelector('[data-tralbum]') | |
if (!el) return | |
console.log('tralbum', JSON.parse(el.dataset.tralbum)) | |
console.log('embed', JSON.parse(el.dataset.embed)) | |
} | |
logData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment