extension/content.js
// Populate audio element and attach to the userbar
Populate audio element and attach to the userbar
Populate audio element and attach to the userbar
function PopulatePodcastPlayer(podcastUrl, podcastTitle, podcastDate)
{	
    var result = (/sbfc-[0-9]*/i).exec(podcastUrl);
	if(result !== null && result.length === 1)
	{	 
		var podcastFilename = result[0].replace('-','');
		var playerBestGuessLocation = superBestFriendCastBaseURL + podcastFilename + ".mp3";
		$("#socialelements a:last-child").after($('<div id="sbfc-audio-container"><audio id="sbfc-audio" src="' + playerBestGuessLocation + '" controls></audio><span id="sbfc-audio-notwatched">!</span><div id="sbfc-audio-data"><div id="sbfc-audio-data-triangle"></div><h2>' + podcastTitle + '</h2><h3>' + podcastDate + '</h3></div></div>'));		
		var player = $('#sbfc-audio');			
		chrome.storage.sync.get("sbf:podcast:" + playerBestGuessLocation, function(positionObject){					
			var keys = Object.keys(positionObject);
			if(keys.length > 0){
				var key = keys[0];					
				var position = positionObject[key];
				player.bind('canplay', function(){
					this.currentTime = position.position;
				});
			}
			else
			{
				$('#sbfc-audio-notwatched').addClass('unwatched');				
			}
		});
		player.bind('timeupdate', function(event){			
			var currentDate = new Date();
			if(podcastSaveLocked === false && (podcastLastSaved === null || 
				Math.abs((currentDate.getTime() - podcastLastSaved.getTime()) / 1000) > 5))
			{
				podcastLastSaved = currentDate;
				podcastSaveLocked = true;
				var dataSaveValue = {};
				dataSaveValue["sbf:podcast:" + this.src] = {'position': this.currentTime, 'duration': this.duration};
				chrome.storage.sync.set(dataSaveValue);				
				podcastSaveLocked = false;
			}
		});
	}	
}
function PopulatePodcastPlayer ( podcastUrl , podcastTitle , podcastDate ) { var result = ( / sbfc-[0-9]* / i ) . exec ( podcastUrl ) ; if ( result !== null && result . length === 1 ) { var podcastFilename = result [ 0 ] . replace ( '-' , '' ) ; var playerBestGuessLocation = superBestFriendCastBaseURL + podcastFilename + ".mp3" ; $ ( "#socialelements a:last-child" ) . after ( $ ( '<div id="sbfc-audio-container"><audio id="sbfc-audio" src="' + playerBestGuessLocation + '" controls></audio><span id="sbfc-audio-notwatched">!</span><div id="sbfc-audio-data"><div id="sbfc-audio-data-triangle"></div><h2>' + podcastTitle + '</h2><h3>' + podcastDate + '</h3></div></div>' ) ) ; var player = $ ( '#sbfc-audio' ) ; chrome . storage . sync . get ( "sbf:podcast:" + playerBestGuessLocation , function ( positionObject ) { var keys = Object . keys ( positionObject ) ; if ( keys . length > 0 ) { var key = keys [ 0 ] ; var position = positionObject [ key ] ; player . bind ( 'canplay' , function ( ) { this . currentTime = position . position ; } ) ; } else { $ ( '#sbfc-audio-notwatched' ) . addClass ( 'unwatched' ) ; } } ) ; player . bind ( 'timeupdate' , function ( event ) { var currentDate = new Date ( ) ; if ( podcastSaveLocked === false && ( podcastLastSaved === null || Math . abs ( ( currentDate . getTime ( ) - podcastLastSaved . getTime ( ) ) / 1000 ) > 5 ) ) { podcastLastSaved = currentDate ; podcastSaveLocked = true ; var dataSaveValue = { } ; dataSaveValue [ "sbf:podcast:" + this . src ] = { 'position' : this . currentTime , 'duration' : this . duration } ; chrome . storage . sync . set ( dataSaveValue ) ; podcastSaveLocked = false ; } } ) ; } }
Populate audio element and attach to the userbar
Populate audio element and attach to the userbar
// find podcast code from URL // Save another request, and use standard naming convention for mp3 file // Apend audio element to the end of the userbar		 //new, add ! beside player to indicate unwatched // Setup listener to update current position to sync storage.