Created
October 9, 2017 18:38
-
-
Save cold-logic/098ffd81f66f66931377df2a08495a05 to your computer and use it in GitHub Desktop.
Discogs Tracklist Batch Import
This file contains 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
/************************************************** | |
* Discogs Tracklist Batch Import | |
************************************************** | |
* Takes a tab separated list of values | |
* from Excel or Pages and feeds them into | |
* the discogs tracklist page | |
**************************************************/ | |
function fill(a) { | |
// Get a list of table rows from the tracklist | |
let $rows = $('#subform > div.subform_tracklist > table > tbody') | |
// Loop over each row and column | |
for (let [rowi,row] of a.entries()) { | |
for (let [coli, col] of row.entries()) { | |
// Find the text input fields | |
let comp = $rows.eq(rowi).find("input[type=\"text\"]").eq(coli)[0] | |
// Log the text fields for our sanity | |
console.log(comp) | |
// Find the react component instance | |
comp = comp._reactInternalComponent._currentElement._owner._instance | |
// Set the component's value | |
if (comp.state.data) { | |
comp.setInState(['value'], col) | |
} else { | |
comp.update(col) | |
} | |
} | |
} | |
} | |
// MAIN takes the TSV string as input | |
(a => { | |
let c = [] | |
// Loop over each line | |
for (let b of a.split('\n')) { | |
// Split the tab separated values and add them to the result array | |
c.push(b.split('\t')) | |
} | |
// Send the result array to fill() | |
fill(c) | |
})(`TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP | |
TRACKNUM ARTIST TITLE TIMESTAMP`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment