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 8982719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:39:03+00:00 2026-06-15T20:39:03+00:00

This is my main.js: var data = require(self).data; var window = require(window-utils).activeBrowserWindow; var tabs

  • 0

This is my main.js:

var data = require("self").data;
var window = require("window-utils").activeBrowserWindow;
var tabs = require("tabs");
var Request = require("request").Request;

var team = require("page-mod").PageMod({
include: ["http://www.example.com/team/*"],
contentScriptFile: [data.url("jquery.js"), data.url("item.js")],
contentScriptWhen: 'ready',
onAttach: function(worker) {

        worker.port.on('got-id', function(id) {
        var requesturl = "http://www.othersite.com/item/" + id;   

        Request({
            url: requesturl,
            onComplete: function(response) {
                worker.port.emit('got-request', response.text);
            }
        }).get();

    });
}
});

and my item.js:

// Getting number of total items in the page
var totalitems = document.getElementById("NumberOfItems").textContent;
totalitems = parseInt(totalitems);
// Creating array for items position
positions = [];
for ( z = 0; z <= totalplayers-1 ; z++ ) { positions.push(z < 10 ? ("0" + z.toString()) : z.toString()); }
$.each( positions, function(players, position) {
// Getting item id for the request
var player_id = $("#item-position" + position).attr("href").match(RegExp('items/([^/]+)/details.aspx$'))[1];
self.port.emit('got-player-id-team', player_id);

self.port.on('got-request-team', function(data) {
var columns = $('div.columns',data);
replacediv = $("div#itembox").eq(position).find('td').eq(3);
replacediv.append(columns);
});
});

Its seems that is working fine, BUT all the divs get appended by every item!
How i can mod it to place every item’s fetch data only in this items and not in every item?

What i am doing wrong? I thinks its running twice! Its like runs = totalitems*2.

If i force it to run for the first item only, everything is good!

Sorry for my bad english!
I know that is hard to understand it so i am waiting your comments

  • 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-06-15T20:39:04+00:00Added an answer on June 15, 2026 at 8:39 pm

    as far as I can see, the problem in your code is here:

    $.each( positions, function(players, position) {
        // ...
        self.port.on('got-request-team', function(data) {
            var columns = $('div.columns',data);
            replacediv = $("div#itembox").eq(position).find('td').eq(3);
            replacediv.append(columns);
        });
    });
    

    Basically for each cycle of the loop, you’re adding a new listener to the ‘got-request-team’ event. Let’s say you have only one item in positions: then, you associate to this event only one function, and when you emit the ‘got-request-team’, only that function is executed. But, if you have, let’s say, 20 items in the positions array, you associate 20 different function to the same event, so when ‘got-request-team’ is emitted, all of them are executed.

    Also, because you created a closure, the variable position inside the event listener will always have the last value set, and I believe it’s not that your intention. It’s a common mistake, and you can find additional details here, for example: Closure needed for binding event handlers within a loop?

    There are also some other small things (for example, I don’t see replacediv declared anywhere), but they’re not related to your issue.

    Hope it helps!

    Update: about your comment, it’s hard to answer without could test the code, but I believe your error is still in the piece above: first, more than positions, it’s position that you have to “bind”. Because you’re in content script, you can use let, therefore you can try something like that:

    $.each(positions, function(players, position) {
        // ...
    
        let pos = position; // let is block scope
        self.port.on('got-request-team', function(data) {
            var columns = $('div.columns',data);
            replacediv = $("div#itembox").eq(pos).find('td').eq(3); // use pos here
            replacediv.append(columns);
        });
    });
    

    Note that here you still have the problem of adding new listener to the same event for each item of positions (that you said you have fixed), I just reuse this code to showing the usage of let in this context.

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

Sidebar

Related Questions

First look at this code: class Program { static void Main(string[] args) { var
My program is like this ( main.c ): #include <stdlib.h> #include <stdio.h> void main(){
In the below shown html i have this main div as cxfeeditem feeditem and
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer
I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and
I have 2 radio button with 2 group. The structure is like this Main
Code first: '''this is main structure of my program''' from twisted.web import http from
I have this TreeView: Main Node Header=Main Sub Node Header=Sub1 Final Node Header=Item1 Final
I'm using this CSS: #main{ border-radius: 50px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; -webkit-border-radius: 50px; -webkit-border-bottom-right-radius:

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.