Skip to content

Instantly share code, notes, and snippets.

@joar
Created November 23, 2010 09:42
Show Gist options
  • Save joar/711522 to your computer and use it in GitHub Desktop.
Save joar/711522 to your computer and use it in GitHub Desktop.
Tumblr Audio Download

Tumblr Audio Download

This is a script that can be loaded via e.g. a bookmarklet.

Bookmarklet example

<a href="javascript:var wbgTumblr=document.createElement('script');wbgTumblr.src='https://gist.github.com/raw/711522/wbg-tumblr-audio.js';document.getElementsByTagName('head')[0].appendChild(wbgTumblr);">Tumblr Audio Download</a>

Installation

  1. Copy the bookmarklet example HTML code
  2. Go to http://htmledit.squarefree.com and remove the existing code in the upper field
  3. Paste the bookmarklet example HTML code in the upper field
    The link should now appear in the lower field
  4. Drag and drop the link to your bookmarks bar

Usage

  1. Go to the post page for the audio post e.g. tovawellton.tumblr.com/post/1651712481/jj-let-them
  2. Click the bookmarklet in your bookmarks toolbar
  3. Right-click/Cmd-click the audio link and choose "Save as"
try {
if ('undefined' == typeof wbg ) {
var wbg = {};
}
wbg.tumblr = {
constants: {
audioTag: 'audio_player',
flashElement: 'embed'
},
close: function () {
document.body.removeChild( wbg.tumblr.display );
delete wbg.tumblr;
return false;
}
};
wbg.tumblr.audioSrc = document.getElementsByClassName( wbg.tumblr.constants.audioTag )[0];
if ('undefined' == typeof wbg.tumblr.audioSrc ) {
throw 'Could not find any audio element';
}
wbg.tumblr.audioSrc = wbg.tumblr.audioSrc.getElementsByTagName( wbg.tumblr.constants.flashElement )[0];
if ('undefined' == typeof wbg.tumblr.audioSrc ) {
throw 'Could not find flash element in audio element';
}
wbg.tumblr.audioSrc = wbg.tumblr.audioSrc.src.replace(/https?:\/\/[^?]+\?audio_file=(.*?)(&color=\w{3,6})/i, '$1');
//wbg.tumblr.audioTitle = document.getElementsByClassName( wbg.tumblr.constants.audioTag )[0]
wbg.tumblr.display = document.createElement('div');
wbg.tumblr.display.innerHTML = '<h2 style="margin-top: 0;">Tumblr Audio</h2>'
+ '<p>Found the following audio embedded in the page:</p>'
+ '<ul>'
+ '<li>'
+ '<a style="color: #000; font: normal italic 1em Georgia,serif;" target="_blank" href="' + decodeURIComponent( wbg.tumblr.audioSrc ) + '">' + decodeURIComponent( wbg.tumblr.audioSrc ) + '</a>'
+ '</li>'
+ '</ul>'
+ '<span style="position: absolute; top: 8px; right: 8px;"><em><a class="wbg-tumblr-close" style="color: #f00;" href="javascript:viod(0)">X</a></em></span>'
+ '<span class="author" style="font-size: 12px; color: #aaa;"><em>By; <a style="color: #777; font: normal italic 1em Georgia,serif;" target="_blank" href="http://wandborg.se">Joar Wandborg</a></em></span>';
wbg.tumblr.display.style.cssText = 'font: 14px Georgia,serif;'
+ 'background: #fff;'
+ 'color: #555;'
+ 'position: fixed;'
+ 'top: 10px;'
+ 'left: 10px;'
+ 'outline: thin solid #aaa;'
+ 'padding: 10px;'
+ 'z-index: 100;'
+ 'border-radius: 5px;';
document.body.appendChild( wbg.tumblr.display ).getElementsByClassName('wbg-tumblr-close')[0].addEventListener('click', wbg.tumblr.close );
/* javascript:var wbgTumblr=document.createElement('script');wbgTumblr.src='https://gist.github.com/raw/711522/wbg-tumblr-audio.js';document.getElementsByTagName('head')[0].appendChild(wbgTumblr); */
} catch ( e ) {
console.log( e );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment