SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get data item.description rss

    Friends, I need to get the link of the src <iframe> which lies within the <description>. How do I?

    My xml:

    Code:
    <description><![CDATA[<img src='http://parafernalha.s3.amazonaws.com/images/logo_parafernalha.png' /><br /><br /><h2>MAIS UMA COISA #2 Crítica de Batman - The Dark Knight Rises</h2><iframe width='640' height='390' src='http://www.youtube.com/embed/Yq7luhnbl2w' frameborder='0' allowfullscreen='true'></iframe>]]></description>
    I'm doing well, but does not work.

    item.description.iframe["src"]

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Can we see what you have coded so far?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's an app for Chrome.

    background:

    HTML Code:
    var feedUrl = 'http://feeds.feedburner.com/parafernalhavideos';
    var reset 	= function(){
    	console.log('reset');
    	localStorage.clear();
    	setLocalStorage();
    	lidoFeed();
    }
    
    var setLocalStorage = function(){
    	if(typeof localStorage.items == 'undefined'){
    		console.log('set localStorage');
    		localStorage.items	= '';
    		localStorage.lido	= '[]';
    	}
    }
    
    var setLido = function(lidoId){
    	console.log('lido ' + lidoId);
    	var lido	= JSON.parse(localStorage.lido);
    	var items	= JSON.parse(localStorage.items);
    	var newItems= 0;
    	lido.push(lidoId.toString());
    	
    	$.each(items, function(lauf, item){
    		if(item.id == lidoId){
    			console.log('ok');
    			item.naolido = 0;
    		}
    		console.log(item);
    		if(item.naolido == 1){
    			newItems++;
    		}
    	});
    	
    	if(lido.length > 10){
    		lido.shift();
    	}
    	setBadgeText(newItems);
    	console.log(lido);
    	localStorage.lido = JSON.stringify(lido);
    	localStorage.items = JSON.stringify(items);
    }
    
    var lidoAll = function(){
    	var items	= JSON.parse(localStorage.items);
    	
    	$.each(items, function(lauf, item){
    		setLido(item.id);
    	});
    }
    
    var getFeed = function(){
    	var items	= JSON.parse(localStorage.items);
    	return items;
    }
    
    var setBadgeText = function(count){
    	if(count > 0){
    		chrome.browserAction.setBadgeText({'text': count.toString()});
    	}else{
    		chrome.browserAction.setBadgeText({'text': ''});
    	}
    }
    
    var lidoFeed = function(){
    	console.log('inicia lidoFeed');
    	$.getFeed({
    		url: feedUrl,
    		success: function(feed) {
    			console.log('compute Feed: ' + feed.title);
    			var items	= new Array();
    			var lido	= JSON.parse(localStorage.lido);
    			var newItems= 0;
    			$.each(feed.items, function(lauf, item){
    				if($.inArray(item.id, lido) > -1){
    					naolido = 0;
    					console.log('lido');
    				} else {
    					naolido = 1;
    					console.log('naolido');
    					newItems++;
    				}
    				items.push({'id': item.id, 'title': item.title, 'link': item.link, 'description': item.description, 'naolido': naolido});
    				console.log(item.title + ' ' + item.id);
    			});
    			console.log(items);
    			console.log(newItems);
    			localStorage.items = JSON.stringify(items);
    			setBadgeText(newItems);
    			setTimeout(lidoFeed, 900000);
    		}
    	});
    }
    
    $(function(){
    	console.log('start script');
    	setLocalStorage();
    	lidoFeed();
    });
    popup:

    HTML Code:
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	$('#feed').append('<li>'+item.description.iframe["src"]+'<a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    });

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is that possible?

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Code for grabbing the URL of the iframe
    Code JavaScript:
    function GrabIFrameURL(feedDescription)
    {
    	var regex = new RegExp("iframe(?:.*?)src='(.*?)'", 'g');
    	var matches = regex.exec(feedDescription);
    	var url = '';
    	if (matches.length == 2)
    	{
    		url = matches[1];
    	}
     
    	return url;
    }

    Implementation:
    Code:
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	$('#feed').append('<li>'+GrabIFrameURL(item.description)+'<a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    });

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worked, but now have another problem, I'm using a class to generate thumbnail of videos from youtube. The problem is that the thumbnails are showing everyone in the first div. See:

    HTML Code:
    <li>
    <a id="thumbs" href="http://www.parafernalha.com.br/video/Nostalgia---Digimon"><img src="http://img.youtube.com/vi/eXVNBnDozjk/default.jpg"><img src="http://img.youtube.com/vi/PX0GQasWIOE/default.jpg"><img src="http://img.youtube.com/vi/JO1jU8m0BLA/default.jpg"><img src="http://img.youtube.com/vi/Yq7luhnbl2w/default.jpg"><img src="http://img.youtube.com/vi/C8WwKwKPAqo/default.jpg"><img src="http://img.youtube.com/vi/Bqc2AUvfl0s/default.jpg"><img src="http://img.youtube.com/vi/Vu3xk-olBDA/default.jpg"><img src="http://img.youtube.com/vi/xf0ClPEPWPI/default.jpg"><img src="http://img.youtube.com/vi/Nqctbfzm5Uc/default.jpg"></a><a id="http://www.parafernalha.com.br/video/Nostalgia---Digimon" href="http://www.parafernalha.com.br/video/Nostalgia---Digimon" class="naolido">Nostalgia - Digimon</a>
    </li>
    class:

    HTML Code:
    (function($){
    	$.extend({
    		jYoutube: function( url, size ){
    			if(url === null){ return ""; }
    
    			size = (size === null) ? "big" : size;
    			var vid;
    			var results;
    
    			results = url.match("[\\?&]v=([^&#]*)");
    
    			vid = ( results === null ) ? url : results[1];
    
    			if(size == "small"){
    				return "http://img.youtube.com/vi/"+vid+"/default.jpg";
    			}else {
    				return "http://img.youtube.com/vi/"+vid+"/0.jpg";
    			}
    		}
    	})
    })(jQuery);

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Can you show me the code that calls "jYoutube" passing in the url and size?

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	var thumb = GrabIFrameURL(item.description);
    	$('#thumbs').append($('<img src="'+$.jYoutube(thumb, 'small')+'" />'));
    	$('#feed').append('<li><a id="thumbs" href="'+ item.link +'"></a><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    });

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Ah, okay, because your output HTML is invalid.

    Try this
    Code:
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	var thumb = GrabIFrameURL(item.description);
    	$('#feed').append('<li><a id="thumbs' + item.id + '" href="'+ item.link +'"></a><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    	$('#thumbs' + item.id).append($('<img src="'+$.jYoutube(thumb, 'small')+'" />'));
    });

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2012
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do not return any error but did not work.

    HTML Code:
    <li><a id="thumbshttp://www.parafernalha.com.br/video/Nostalgia---Digimon" href="http://www.parafernalha.com.br/video/Nostalgia---Digimon"></a><a id="http://www.parafernalha.com.br/video/Nostalgia---Digimon" href="http://www.parafernalha.com.br/video/Nostalgia---Digimon" class="naolido">Nostalgia - Digimon</a></li>

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Okay, my bad, didn't realize that item.id was a url.

    Try this
    Code:
    var itemId = 0;
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	var thumb = GrabIFrameURL(item.description);
    	$('#feed').append('<li><a id="thumbs' + itemId + '" href="'+ item.link +'"></a><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    	$('#thumbs' + itemId).append($('<img src="'+$.jYoutube(thumb, 'small')+'" />'));
    	itemId++;
    });

  12. #12
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Not sure why I didn't think of this sooner, but why do a second append, when you can avoid it all together.

    This code should also work:
    Code:
    jQuery.each(bkg.getFeed(), function(id, item){
    	if(item.naolido == '1') lidoClass = 'naolido';
    	else lidoClass = 'lido';
    	var thumb = GrabIFrameURL(item.description);
    	$('#feed').append('<li><a href="'+ item.link +'"><img src="'+$.jYoutube(thumb, 'small')+'" /></a><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '">' + item.title + '</a></li>');
    });


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •