On Reddit, How Do Scripts Get The Number Of Upvotes And Downvotes For A Comment?
On Reddit, people can post comments that get upvotes and downvotes. This information is not readily accessible on the page itself, so it seems that something like an API is used to
Solution 1:
Each comment has data
attributes:
<div class="thing id-t1_c4upmtm odd comment " onclick="click_thing(this)" data-fullname="t1_c4upmtm" data-ups="646" data-downs="83">
Reddit's HTML structure is really hard to follow so figure out a way to get from the comment ID to the element which contains this stuff.
Solution 2:
That script uses GM_xmlhttpRequest()
to fetch the JSON data for the given: comments or user page.
The data returned by GM_xmlhttpRequest()
, is accessed in the line:
var jsonText = response.responseText,data;
and then parsed with the script's processTree()
function. There is not really one line; much of the script is required for this functionality.
On the comments pages, it seems that using the API is the only way to get up-votes and down-votes separately.
Post a Comment for "On Reddit, How Do Scripts Get The Number Of Upvotes And Downvotes For A Comment?"