mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2024-12-26 06:40:09 +08:00
Added parsing of discussion data in a JS VM
This commit is contained in:
parent
7efc1f2fd0
commit
6144ee1909
0
classes/CDiscussionTopic.js
Normal file
0
classes/CDiscussionTopic.js
Normal file
61
components/discussions.js
Normal file
61
components/discussions.js
Normal file
@ -0,0 +1,61 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
var Cheerio = require('cheerio');
|
||||
var VM = require('vm');
|
||||
|
||||
SteamCommunity.prototype.getDiscussion = function(url, callback) {
|
||||
var self = this;
|
||||
|
||||
this.request.get({
|
||||
"uri": url,
|
||||
"followRedirect": false
|
||||
}, function(err, response, body) {
|
||||
if(self._checkHttpError(err, response, callback)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(self._checkCommunityError(body, callback)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.statusCode >= 300 && response.statusCode <= 399) {
|
||||
callback(new Error("Topic Not Found"));
|
||||
return
|
||||
}
|
||||
|
||||
var $ = Cheerio.load(body);
|
||||
var scripts = $('#group_tab_content_discussions').find('script');
|
||||
if(scripts.length < 2) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
|
||||
var context = VM.createContext({
|
||||
"ForumTopic": {},
|
||||
"CommentThread": {},
|
||||
"$J": function(input) {
|
||||
if(typeof input === 'function') {
|
||||
input();
|
||||
}
|
||||
},
|
||||
"InitializeForumTopic": function(board, boardUrl, topicID, topic) {
|
||||
context.ForumTopic.board = board;
|
||||
context.ForumTopic.topicID = topicID;
|
||||
context.ForumTopic.topic = topic;
|
||||
},
|
||||
"InitializeCommentThread": function(type, name, commentData, url, quoteBoxHeight) {
|
||||
context.CommentThread.type = type;
|
||||
context.CommentThread.name = name;
|
||||
context.CommentThread.commentData = commentData;
|
||||
context.CommentThread.url = url;
|
||||
context.CommentThread.quoteBoxHeight = quoteBoxHeight;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(context);
|
||||
|
||||
VM.runInContext($(scripts[0]).html(), context);
|
||||
VM.runInContext($(scripts[1]).html(), context);
|
||||
|
||||
console.log(context);
|
||||
});
|
||||
};
|
1
index.js
1
index.js
@ -396,6 +396,7 @@ require('./components/inventoryhistory.js');
|
||||
require('./components/webapi.js');
|
||||
require('./components/twofactor.js');
|
||||
require('./components/confirmations.js');
|
||||
require('./components/discussions.js');
|
||||
require('./classes/CMarketItem.js');
|
||||
require('./classes/CMarketSearchResult.js');
|
||||
require('./classes/CSteamGroup.js');
|
||||
|
Loading…
Reference in New Issue
Block a user