mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-22 22:01:05 +08:00
32 lines
944 B
JavaScript
32 lines
944 B
JavaScript
var SteamCommunity = require('../index.js');
|
|
var Cheerio = require('cheerio');
|
|
|
|
/**
|
|
* Get a list of all apps on the market
|
|
* @param {function} callback - First argument is null|Error, second is an object of appid => name
|
|
*/
|
|
SteamCommunity.prototype.getMarketApps = function(callback) {
|
|
var self = this;
|
|
this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) {
|
|
if (err) {
|
|
callback(err);
|
|
return;
|
|
}
|
|
|
|
var $ = Cheerio.load(body);
|
|
if ($('.market_search_game_button_group')) {
|
|
let apps = {};
|
|
$('.market_search_game_button_group a.game_button').each(function (i, element) {
|
|
var e = Cheerio.load(element);
|
|
var name = e('.game_button_game_name').text().trim();
|
|
var url = element.attribs.href;
|
|
var appid = url.substr(url.indexOf('=') + 1);
|
|
apps[appid] = name;
|
|
});
|
|
callback(null, apps);
|
|
} else {
|
|
callback(new Error("Malformed response"));
|
|
}
|
|
}, "steamcommunity");
|
|
};
|