Skip to content

Instantly share code, notes, and snippets.

@willboudle
Last active May 4, 2020 16:25
Show Gist options
  • Save willboudle/9ce44292ee1a2e8a466a3e8bd9f132dc to your computer and use it in GitHub Desktop.
Save willboudle/9ce44292ee1a2e8a466a3e8bd9f132dc to your computer and use it in GitHub Desktop.
Turn Audible Library into a table
// How to use.
// Log on to Audible.com, and open up your library.
// It can be a good idea to increase the number of items per page
// and the time period you look back.
// Next, you want to run this entire file as a script on the page.
// Chrome, Firefox and Internet Explorer does this differently.
// For chrome, press F12 to open the Chrome Dev Tools, and click
// on the Console. Then paste in this whole file in the console
// window and press enter.
// This is the US version. The US site has less information on
// the page than the UK site, so less information is available
// for the script to extract. There is nothing that I can do
// about that. :-(
// Where we will store our extracted data
var headerRow = [
$(document.createTextNode('Title')),
$(document.createTextNode('Author')),
$(document.createTextNode('Rating')),
$(document.createTextNode('Description')),
$(document.createTextNode('URL')),
];
var tableArray = [headerRow];
// Let's fill in the tableArray!
jQuery('div[class*="adbl-library-content-row"]').each(function(index){
var row = $( this );
var title = $(document.createTextNode(row.find('.bc-list-item:nth-of-type(1)').text()));
var author = row.find('.bc-list-item.authorLabel a');
var rating = $(document.createTextNode(row.find('.bc-rating-stars').attr('data-star-count')));
var url = $(document.createTextNode("https://audible.com"+row.find('.bc-color-link').attr('href')));
var description = $(document.createTextNode(row.find('.merchandisingSummary p').text()));
var result = [title, author, rating, description,url];
tableArray.push(result);
});
// Function to create a table as a child of el.
// data must be an array of arrays (outer array is rows).
function tableCreate(el, data)
{
var tbl = document.createElement("table");
tbl.style.width = "70%";
tbl.border = "1";
for (var i = 0; i < data.length; ++i)
{
var tr = tbl.insertRow();
for(var j = 0; j < data[i].length; ++j)
{
var td = tr.insertCell();
data[i][j].each(function(){
$(this).clone().appendTo(td);
});
}
}
el.appendChild(tbl);
}
tableCreate($('body').empty()[0], tableArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment