Created
July 13, 2022 20:35
-
-
Save duplaja/aafdf019b80c264b94f50f76249e8689 to your computer and use it in GitHub Desktop.
RYM Recs to Text Export
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
function generateTextDownload(filename, text, type='text/plain;charset=utf-8') { | |
// Create an invisible A element | |
const a = document.createElement('a'); | |
a.style.display = 'none'; | |
document.body.appendChild(a); | |
var BOM = new Uint8Array([0xEF,0xBB,0xBF]); | |
// Set the HREF to a Blob representation of the data to be downloaded | |
a.href = window.URL.createObjectURL( | |
new Blob([BOM, text], { type }) | |
); | |
// Use download attribute to set set desired file name | |
a.setAttribute('download', filename); | |
// Trigger the download by simulating click | |
a.click(); | |
// Cleanup | |
window.URL.revokeObjectURL(a.href); | |
document.body.removeChild(a); | |
} | |
function startTextDownload() { | |
var list = document.getElementById('page_recommendations_list_main'); | |
var items = list.getElementsByClassName("component_discography_item_info_inner"); | |
let origTitle = 'RYM Recs Export'; | |
let today = new Date().toISOString().replace(/T.*/,''); | |
let lowerTitle = origTitle.toLowerCase(); | |
let title = lowerTitle.replace(/[^a-z0-9]/gi, '')+'-'+today+'.txt'; | |
var fullList = ''; | |
for (i = 0; i < items.length; i++) { | |
item_details = items[i].getElementsByClassName('component_discography_item_details')[0]; | |
title_item = items[i].getElementsByClassName('component_discography_item_link')[0]; | |
href = title_item.href.replaceAll('\n',''); | |
albumtitle = title_item.innerText.replaceAll('\n',''); | |
artist_string = ''; | |
artist_list = items[i].getElementsByClassName("artist"); | |
for (j = 0; j < artist_list.length; j++) { | |
artist_string = artist_string + artist_list[j].innerText.replaceAll('\n','') | |
} | |
artist = artist_string.replaceAll(' /',', ') | |
content = artist +' - '+ albumtitle +' '+href | |
fullList = fullList+content.trim(); | |
if(i != parseInt(items.length) - 1) { | |
fullList=fullList+'\r\n'; | |
} | |
} | |
generateTextDownload(title, fullList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment