0

My chrome extension reads an RSS feed that is updated quite often with new posts. What I want to do is assign every guid to an array that holds and then helps determine whether or not each post is new, and so ought to be passed on (as a notification to me).

    $.get('rss-feed', function(data) {
    var $xml = $(data);
    $xml.find("item").each(function() {
        var $this = $(this),
            item = {
                title: $this.find("title").text(),
                link: $this.find("link").text(),
                description: $this.find("description").text(),
                pubDate: $this.find("pubDate").text(),
                guid: $this.find("guid").text()
        }

The guid is then assigned to a variable:

    var latestID = item.guid.slice(-8);

This is where the problem takes place. The very same post keeps being posted as a new one. Is it because it has an undefined value?

    if (latestID == ids[0]) {

    } else if (latestID != ids[0]) {

        var firstNotification = {
            type: "basic",
            title: jobType[0] + ": " + jobWords[1] + " words",
            iconUrl: "icon48.png",
            message: jobPay[0] + "\nID: " + latestID + " Date: " + item.pubDate.slice(17,25),
            requireInteraction: true,
            buttons: [{
                    title: "Go to site!"
                }],
        };

        latestID = ids[0];
    }
Iván Nokonoko
  • 4,888
  • 2
  • 19
  • 27
user2359938
  • 31
  • 1
  • 6

1 Answers1

0

You can use local storage to save the value locally and check

window.localStorage.setItem("somename",item.guid.slice(-8));

Then you can retrieve wherever you want using,

var prevId = window.localStorage.getItem("somename");

You can compare now

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jeswin Rebil
  • 460
  • 1
  • 7
  • 19