Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6086627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:46:39+00:00 2026-05-23T11:46:39+00:00

Everytime the extension refreshes it duplicates the entire feed.json . How do I prevent

  • 0

Everytime the extension refreshes it duplicates the entire feed.json. How do I prevent this and only add new items from feed.json (when that is updated) on top of the old ones? Also how do I only set the badgeText when new items have been added?

Here’s what I got so far:

background.html

<html>
  <head>
    <script type="text/javascript">
      var fetchFreq = 30000; // how often we fetch new items (30s)
      var req; // request object
      var unreadCount = 0; // how many unread items we have
      var items; // all currently fetched items

      getItems();
      setInterval(getItems, fetchFreq);

      function getItems() {
        req = new XMLHttpRequest();
        req.open('GET', 'http://siteurl.com/feed.json');
        req.onload = processItems;
        req.send();
      }

      function processItems() {
        var res = JSON.parse(req.responseText);
        unreadCount += res.length;

        if (unreadCount > 0) {
          chrome.browserAction.setBadgeBackgroundColor({
            color: [255, 0, 0, 255]
          });
          chrome.browserAction.setBadgeText({text: '' + unreadCount});
        }

        items = res.concat(items);
      }
    </script>
  </head>
</html>

popup.html

<html>
  <head>
    <link rel="stylesheet" href="popup.css" />
    <script src="util.js"></script>
    <script>
      var bg; // background page

      // timeline attributes
      var timeline;
      var template;
      var link;
      var image;
      var author;
      var content;

      onload = setTimeout(init, 0); // workaround for http://crbug.com/24467

      // initialize timeline template
      function init() {
        chrome.browserAction.setBadgeText({text: ''});
        bg = chrome.extension.getBackgroundPage();
        bg.unreadCount = 0;

        timeline = document.getElementById('timeline');
        template = xpath('//ol[@id="template"]/li', document);
        link = xpath('//div[@class="thumbnail"]/a', template);
        image = xpath('img', link);
        author = xpath('//div[@class="text"]/a', template);
        content = xpath('//div[@class="text"]/span', template);

        update();
      }

      // update display
      function update() {
        var user;
        var item;

        for (var i in bg.items) {
          user = bg.items[i];

          // thumbnail
          link.title = user.name;
          link.href = openInNewTab(profileurl);
          image.src = user.thumbnail;
          image.alt = user.name;

          // text
          author.href = openInNewTab(profileurl);
          author.innerHTML = user.name;
          content.innerHTML = linkify(bg.items[i].profileurl);

          // copy node and update
          item = template.cloneNode(true);
          timeline.appendChild(item);
        }
      }
    </script>
  </head>
  <body>
    <div id="body">
      <div id="title">
        <h2>Chrome Extension</h2>
      </div>
      <ol id="timeline" />
    </div>
    <ol id="template">
      <li>
        <div class="thumbnail">
          <a>
            <img />
          </a>
        </div>
        <div class="text">
          <a></a>
          <span></span>
        </div>
        <div class="clear"></div>
      </li>
    </ol>
  </body>
</html>

feed.json

{
"name":"John Doe",
"about":"I am me",
"thumbnail":"http://thumbnail.jpg",
"profileurl":"http://siteurl.com/profileurl.php"
}

Thanks in advance. The extension’s purpose is to fetch new items from feed.json and show in the popup.html. Think of it like a feed reader for new twitter tweets.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:46:39+00:00Added an answer on May 23, 2026 at 11:46 am

    I know it seems fine now, but having a single global req object is probably not as safe as having one for each request.

    You don’t seem to ever be clearing the items. Your popup and background should communicate. The background should hold the new and old feeds separately and when the popup shows them, should release them.

    Consider, for example, holding the old items in an array, and the new ones in a separate array. And then when the popup shows the new feeds to the user it can call bg.clearItems() which will copy the new ones into the array of the old ones, and then on the next request the new items are put into the now-empty new items array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I took a method from this post (accepted answer code) that serializes object so
I wrote this extension that basically changes the look of a website using CSS
I am developing an extension for Google Chrome. My background script, everytime, authorizes on
This is in an extension of TextView. getTextSize() and setTextSize() are not overridden, I
Everytime I start a project I have to think carefully about which files to
I'm hosting IronPython in a c#-based WebService to be able to provide custom extension
I'm running with the src version of Dojo 1.4.2, in Firefox/Firebug. Everytime I load
I was under the impression that the content_scripts were executed right on the page,
I use stored procedures in Entity Framework. Let's say that I have that procedure:
This has probably been asked before but I can't find it anywhere. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.