async function _extractWeaponData($, weapons, colourOfInterest, knivesData = false) {
  let knivesUrl;

  // Find all result boxes with a h3 inside of them
  $('div .result-box')
    .not((i, result) => !$(result).children('h3').length)
    .each((i, result) => {
      // Weapon name
      const name = $(result).find('h3').text();

      // Skip knives and gloves but note the URL if needed
      if (!knivesData && (name.includes('Knives') || name.includes('Gloves'))) {
        knivesUrl = $(result).children('h3').children('a').attr('href');
        return;
      }

      // Rarity
      const rarityLinks = $(result).find('a[class=nounderline]');
      const rarityParent = rarityLinks.length ? rarityLinks : result;
      const rarity = $(rarityParent)
        .children('div .quality')
        .attr('class')
        .replace('quality color-', '');

      // Colour (based on rarity)
      const colourMap = {
        rare: 'yellow',
        covert: 'red',
        classified: 'pink',
        restricted: 'purple',
        milspec: 'blue',
        industrial: 'lightBlue',
        consumer: 'white',
      };
      const colour = knivesData ? 'yellow' : colourMap[rarity];

      // Image URL
      const imageUrl = $(result).find('a').children('img').attr('src');

      // Weapon URL
      const url = $(result).find('a > img').parent().attr('href');

      weapons[colour].push({
        name: name,
        image: imageUrl,
        url: url,
      });
    });

  // Get knives/gloves data mentioned on page if needed
  if (colourOfInterest === 'yellow' && !knivesData && knivesUrl) {
    const knives = await _scrapeKnivesPage(knivesUrl);
    weapons.yellow.push(...knives.yellow);
  }
}
/**
 * Extract all weapons at the provided URL.
 * Knife/glove data will only be fetched if the provided colour is yellow.
 * @param {import('cheerio').CheerioAPI} $ - Cheerio object of HTML to extract elements from
 * @param {import('../typedefs/container').ContainerData|import('../typedefs/container').ContainerKnifeData} weapons - existing weapons data to update
 * @param {string} colourOfInterest - colour of weapon we are interested in
 * @param {boolean} [knivesData=false] - if true, the data to be extracted is knives
 * @returns {Promise<void>} weapons in container
 */
Extract all weapons at the provided URL.
Knife/glove data will only be fetched if the provided colour is yellow.
Extract all weapons at the provided URL . Knife / glove data will only be fetched if the provided colour is yellow .
async function _extractWeaponData($, weapons, colourOfInterest, knivesData = false) {
  let knivesUrl;
  $('div .result-box')
    .not((i, result) => !$(result).children('h3').length)
    .each((i, result) => {
      const name = $(result).find('h3').text();
      if (!knivesData && (name.includes('Knives') || name.includes('Gloves'))) {
        knivesUrl = $(result).children('h3').children('a').attr('href');
        return;
      }
      const rarityLinks = $(result).find('a[class=nounderline]');
      const rarityParent = rarityLinks.length ? rarityLinks : result;
      const rarity = $(rarityParent)
        .children('div .quality')
        .attr('class')
        .replace('quality color-', '');
      const colourMap = {
        rare: 'yellow',
        covert: 'red',
        classified: 'pink',
        restricted: 'purple',
        milspec: 'blue',
        industrial: 'lightBlue',
        consumer: 'white',
      };
      const colour = knivesData ? 'yellow' : colourMap[rarity];
      const imageUrl = $(result).find('a').children('img').attr('src');
      const url = $(result).find('a > img').parent().attr('href');
      weapons[colour].push({
        name: name,
        image: imageUrl,
        url: url,
      });
    });
  if (colourOfInterest === 'yellow' && !knivesData && knivesUrl) {
    const knives = await _scrapeKnivesPage(knivesUrl);
    weapons.yellow.push(...knives.yellow);
  }
}
async function _extractWeaponData ( $ , weapons , colourOfInterest , knivesData = false ) { let knivesUrl ; $ ( 'div .result-box' ) . not ( ( i , result ) => ! $ ( result ) . children ( 'h3' ) . length ) . each ( ( i , result ) => { const name = $ ( result ) . find ( 'h3' ) . text ( ) ; if ( ! knivesData && ( name . includes ( 'Knives' ) || name . includes ( 'Gloves' ) ) ) { knivesUrl = $ ( result ) . children ( 'h3' ) . children ( 'a' ) . attr ( 'href' ) ; return ; } const rarityLinks = $ ( result ) . find ( 'a[class=nounderline]' ) ; const rarityParent = rarityLinks . length ? rarityLinks : result ; const rarity = $ ( rarityParent ) . children ( 'div .quality' ) . attr ( 'class' ) . replace ( 'quality color-' , '' ) ; const colourMap = { rare : 'yellow' , covert : 'red' , classified : 'pink' , restricted : 'purple' , milspec : 'blue' , industrial : 'lightBlue' , consumer : 'white' , } ; const colour = knivesData ? 'yellow' : colourMap [ rarity ] ; const imageUrl = $ ( result ) . find ( 'a' ) . children ( 'img' ) . attr ( 'src' ) ; const url = $ ( result ) . find ( 'a > img' ) . parent ( ) . attr ( 'href' ) ; weapons [ colour ] . push ( { name : name , image : imageUrl , url : url , } ) ; } ) ; if ( colourOfInterest === 'yellow' && ! knivesData && knivesUrl ) { const knives = await _scrapeKnivesPage ( knivesUrl ) ; weapons . yellow . push ( ... knives . yellow ) ; } }
Extract all weapons at the provided URL.
Extract all weapons at the provided URL .
// Find all result boxes with a h3 inside of them // Weapon name // Skip knives and gloves but note the URL if needed // Rarity // Colour (based on rarity) // Image URL // Weapon URL // Get knives/gloves data mentioned on page if needed