mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-09-03 22:02:46 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcaa740b54 | ||
|
|
2674287b43 | ||
|
|
8b6bed5527 | ||
|
|
6def665b64 |
83
classes/CMarketSearchResult.js
Normal file
83
classes/CMarketSearchResult.js
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
var SteamCommunity = require('../index.js');
|
||||||
|
var Cheerio = require('cheerio');
|
||||||
|
|
||||||
|
SteamCommunity.prototype.marketSearch = function(options, callback) {
|
||||||
|
var qs = {};
|
||||||
|
|
||||||
|
if(typeof options === 'string') {
|
||||||
|
qs.query = options;
|
||||||
|
} else {
|
||||||
|
qs.query = options.query || '';
|
||||||
|
qs.appid = options.appid;
|
||||||
|
qs.search_descriptions = options.searchDescriptions ? 1 : 0;
|
||||||
|
|
||||||
|
if(qs.appid) {
|
||||||
|
for(var i in options) {
|
||||||
|
if(['query', 'appid', 'searchDescriptions'].indexOf(i) != -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a tag
|
||||||
|
qs['category_' + qs.appid + '_' + i + '[]'] = 'tag_' + options[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qs.start = 0;
|
||||||
|
qs.count = 100;
|
||||||
|
performSearch(this.request, qs, [], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
function performSearch(request, qs, results, callback) {
|
||||||
|
request({
|
||||||
|
"uri": "https://steamcommunity.com/market/search/render/",
|
||||||
|
"qs": qs,
|
||||||
|
"headers": {
|
||||||
|
"referer": "https://steamcommunity.com/market/search"
|
||||||
|
},
|
||||||
|
"json": true
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
callback(err ? err.message : "HTTP error " + response.statusCode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!body.success) {
|
||||||
|
callback("Success is not true");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!body.results_html) {
|
||||||
|
callback("No results_html in response");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $ = Cheerio.load(body.results_html);
|
||||||
|
if($('.market_listing_table_message').length > 0) {
|
||||||
|
callback($('.market_listing_table_message').text());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows = $('.market_listing_row_link');
|
||||||
|
for(var i = 0; i < rows.length; i++) {
|
||||||
|
results.push(new CMarketSearchResult($(rows[i])));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(body.start + body.pagesize >= body.total_count) {
|
||||||
|
callback(null, results);
|
||||||
|
} else {
|
||||||
|
qs.start += body.pagesize;
|
||||||
|
performSearch(request, qs, results, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function CMarketSearchResult(row) {
|
||||||
|
var match = row.attr('href').match(/\/market\/listings\/(\d+)\/(.+)/);
|
||||||
|
|
||||||
|
this.appid = parseInt(match[1], 10);
|
||||||
|
this.market_hash_name = decodeURIComponent(match[2]);
|
||||||
|
this.image = row.find('.market_listing_item_img').attr('src').match(/^https?:\/\/[^\/]+\/economy\/image\/[^\/]+\//)[0];
|
||||||
|
this.price = parseInt(row.find('.market_listing_their_price .market_table_value span').text().replace(/[^\d]+/g, ''), 10);
|
||||||
|
this.quantity = parseInt(row.find('.market_listing_num_listings_qty').text().replace(/[^\d]+/g, ''), 10);
|
||||||
|
}
|
||||||
4
index.js
4
index.js
@@ -13,6 +13,9 @@ function SteamCommunity() {
|
|||||||
this._jar = Request.jar();
|
this._jar = Request.jar();
|
||||||
this.request = Request.defaults({"jar": this._jar});
|
this.request = Request.defaults({"jar": this._jar});
|
||||||
this.chatState = SteamCommunity.ChatState.Offline;
|
this.chatState = SteamCommunity.ChatState.Offline;
|
||||||
|
|
||||||
|
// English
|
||||||
|
this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamCommunity.prototype.login = function(details, callback) {
|
SteamCommunity.prototype.login = function(details, callback) {
|
||||||
@@ -261,6 +264,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
require('./classes/CMarketItem.js');
|
require('./classes/CMarketItem.js');
|
||||||
|
require('./classes/CMarketSearchResult.js');
|
||||||
require('./classes/CSteamGroup.js');
|
require('./classes/CSteamGroup.js');
|
||||||
require('./classes/CSteamUser.js');
|
require('./classes/CSteamUser.js');
|
||||||
require('./components/chat.js');
|
require('./components/chat.js');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "steamcommunity",
|
"name": "steamcommunity",
|
||||||
"version": "2.4.0",
|
"version": "2.5.1",
|
||||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||||
"keywords": ["steam", "steam community"],
|
"keywords": ["steam", "steam community"],
|
||||||
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
||||||
|
|||||||
Reference in New Issue
Block a user