<commit_before>var storage = chrome.storage;

var xhr = function(url, callback) {
    var oReq = new XMLHttpRequest();
    oReq.onload = function(e){
        callback(this.responseText, e);
    };
    oReq.open("get", url, true);
    oReq.send();
};

var ALARM_NAME = "feed_updater";

var feedContents;

chrome.alarms.create(ALARM_NAME, {
    periodInMinutes: 30/60
});

chrome.alarms.onAlarm.addListener(function(alarm) {
    console.log("onAlarm fired on " + alarm.name);
    if (alarm.name === ALARM_NAME) {
        feedContents = {};
        var feeds, updatedCount;

        function checkUpdatedCount() {
            if (updatedCount === feeds.length) {
                storage.local.set({ feedContents: feedContents }, function() {
                    console.log("done updating feeds and wrote to chrome.storage");
                });
            }
        }

        console.log("starting feeds update");
        storage.sync.get("feeds", function(r) {
            feeds = r.feeds || [];

            updatedCount = 0;

            feeds.forEach(function(feed) {
                console.log("starting update of feed '" + feed.title +  "'");
                xhr(feed.url, function(res) {
                    var xmlDoc = $.parseXML(res);
                    var $xml = $(xmlDoc);

                    var items = $xml.find("item");
                    console.log(items);

                    feedContents[feed.url] = { items: [] };
                    var feedContent = feedContents[feed.url];

                    [].slice.call(items).forEach(function(elem) {
                        feedContent.items.push({
                            title: elem.querySelector("title").textContent,
                            date: new Date(elem.querySelector("pubDate").textContent) || null,
                            url: elem.querySelector("enclosure[url]") ? elem.querySelector("enclosure[url]").getAttribute("url") : null
                        });
                    });

                    updatedCount += 1;
                    checkUpdatedCount();
                    console.log("done updating feed '" + feed.title +  "'");
                });
            });
        });
    }
});<commit_msg>Better podcast item url fetch<commit_after>var storage = chrome.storage;

var xhr = function(url, callback) {
    var oReq = new XMLHttpRequest();
    oReq.onload = function(e){
        callback(this.responseText, e);
    };
    oReq.open("get", url, true);
    oReq.send();
};

var ALARM_NAME = "feed_updater";

var feedContents;

chrome.alarms.create(ALARM_NAME, {
    periodInMinutes: 30/60
});

chrome.alarms.onAlarm.addListener(function(alarm) {
    console.log("onAlarm fired on " + alarm.name);
    if (alarm.name === ALARM_NAME) {
        feedContents = {};
        var feeds, updatedCount;

        function checkUpdatedCount() {
            if (updatedCount === feeds.length) {
                storage.local.set({ feedContents: feedContents }, function() {
                    console.log("done updating feeds and wrote to chrome.storage");
                });
            }
        }

        console.log("starting feeds update");
        storage.sync.get("feeds", function(r) {
            feeds = r.feeds || [];

            updatedCount = 0;

            feeds.forEach(function(feed) {
                console.log("starting update of feed '" + feed.title +  "'");
                xhr(feed.url, function(res) {
                    var xmlDoc = $.parseXML(res);
                    var $xml = $(xmlDoc);

                    var items = $xml.find("item");
                    console.log(items);

                    feedContents[feed.url] = { items: [] };
                    var feedContent = feedContents[feed.url];

                    [].slice.call(items).forEach(function(elem) {
                        var itemURL = null;
                        if (elem.querySelector("enclosure[url]")) {
                            itemURL = elem.querySelector("enclosure[url]").getAttribute("url");
                        } else if (elem.querySelector("link")) {
                            itemURL = elem.querySelector("link").textContent;
                        }
                        
                        feedContent.items.push({
                            title: elem.querySelector("title").textContent,
                            date: new Date(elem.querySelector("pubDate").textContent) || null,
                            url: itemURL
                        });
                    });

                    updatedCount += 1;
                    checkUpdatedCount();
                    console.log("done updating feed '" + feed.title +  "'");
                });
            });
        });
    }
});
{'fraction_non_alphanumeric': 0.1307838580181703, 'fraction_numerical': 0.002535389816184238, 'mean_word_length': 1.4915789473684211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '439297', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1199, 'n_words': 226}