26/10/2011 Development / java script

Fiz esse scriptzinho só de exemplo para manipulação de feeds rss em javascript utilizando a api do google ajax. Até um tempo atrás isso não era possivel, devido ao crossDomain dos websites. Espero que sirva.

var RssItens = [
        {
            'Title' : 'Uol',
            'Url': 'http://rss.esporte.uol.com.br/ultimas/index.xml',
            'Selected' : false
        },
        {
            'Title': 'InfoMoney',
            'Url': 'http://www.infomoney.com.br/petr4/rss',
            'Selected': true
        },
        {
            'Title': 'Globo',
            'Url': 'http://oglobo.globo.com/rss/plantaotecnologia.xml',
            'Selected': false
        }];

        function Rss() {
            this.rss = RssItens;
            this.load();
        };
        Rss.prototype.load = function() {
            var div = "";
            for (var x = 0; x < RssItens.length; x++) {
                div = document.createElement("div");
                div.innerHTML = "<b>" + RssItens[x].Title + "</b>";
                if (RssItens[x].Selected) {
                    div.className = "selected";
                    this.oRss = RssItens[x];
                }
                $(div).click(function() { $Rss.setRss($(this)); });
                document.getElementById("tabs").appendChild(div);
            }
            this.loadRss();
        };

        Rss.prototype.loadRss = function() {
            var item = this.getRss().Url;
            var script = document.createElement("script");
            var url = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q='+ item +'&callback=processResults';
            script.src = url;
            document.body.appendChild(script);
        };

        Rss.prototype.setRss = function(oRss) {
            for (var x = 0; x < RssItens.length; x++) {
                if (RssItens[x].Title.toString() == oRss.text()) {
                    RssItens[x].Selected = true;
                    this.oRss = RssItens[x];
                } else {
                    RssItens[x].Selected = false;
                }
            }

            $("#tabs div").attr("class", "");
            oRss.attr("class", "selected");

            this.loadRss();
        };
        Rss.prototype.getRss = function() {
            return this.oRss;
        };

        function processResults(result) {
            document.getElementById('news').innerHTML = "";
            var len = result.responseData.feed.entries.length;
            var entries = [];
            for (var x = 0; x < len; x++) {
                entries.push(result.responseData.feed.entries[x].title + '<br>');
            };
            document.getElementById('news').innerHTML = entries.join("");
        };
        var $Rss = new Rss();

    <style>
    .selected { border:1px solid red; }
    div { width: 100px; float:left; border:1px solid blue; margin-right: 2px; padding: 3px; }
    .tabs { width: 100%;  }
    .both { clear: both; border: none}
    .news { width:100% }
    </style>
    <div id="tabs" class="tabs"></div>
    <div class="both"></div>
    <div id="news" class="news"></div>