Skip to content

Instantly share code, notes, and snippets.

@monokaijs
Created December 22, 2018 09:48
Show Gist options
  • Save monokaijs/bebf5c56c8a95410fc621275573afd63 to your computer and use it in GitHub Desktop.
Save monokaijs/bebf5c56c8a95410fc621275573afd63 to your computer and use it in GitHub Desktop.
Auto give reactions to comment.
(function () {
/*
** Written by MonokaiCSS
*/
var postID = '358615471616349';
var reactions = ['HAHA', 'WOW', 'SAD', 'LIKE', 'ANGRY', 'LOVE'];
var auto_react_comments = (token) => {
get_list_comments(token, postID, (comments_data) => {
var comments = JSON.parse(comments_data).data;
comments.forEach((comment) => {
// Each comment will be reacted with random reaction;
let reaction = reactions[Math.floor(Math.random(reactions.length)*(reactions.length)+1) - 1];
react (token, postID, reaction); //reacted;
});
});
}
var get_list_comments = (token, postID, callback) => {
var rq = new XMLHttpRequest;
rq.onreadystatechange = () => {
if (rq.readyState == 4) {
if (rq.status == 200) {
callback(rq.responseText);
} else {
console.log('Failed to react ' + object_id);
}
}
}
rq.open('GET', 'https://graph.facebook.com/'+postID+'/comments?fields=id&access_token=' + token);
rq.send();
}
var react = (token, object_id, reaction) => {
var rq = new XMLHttpRequest;
rq.onreadystatechange = () => {
if (rq.readyState == 4) {
if (rq.status == 200) {
console.log('Reacted ' + object_id + ' with ' + reaction);
} else {
console.log('Failed to react ' + object_id);
}
}
}
rq.open('GET', 'https://graph.facebook.com/' + object_id + '/reactions?method=POST&type=' + reaction + '&access_token=' + token);
rq.send();
}
var get_token = (callback) => {
var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value;
var http = new XMLHttpRequest;
var data = new FormData();
data.append('fb_dtsg', fb_dtsg);
data.append('app_id', '165907476854626');
data.append('redirect_uri', 'fbconnect://success');
data.append('display', 'popup');
data.append('ref', 'Default');
data.append('return_format', 'access_token');
data.append('sso_device', 'ios');
data.append('__CONFIRM__', '1');
http.open('POST', 'https://www.facebook.com/v1.0/dialog/oauth/confirm');
http.send(data);
http.onreadystatechange = function(){
if(http.readyState == 4 && http.status == 200){
var http2 = new XMLHttpRequest;
http2.open('GET', 'https://b-api.facebook.com/restserver.php?method=auth.getSessionForApp&format=json&access_token='+http.responseText.match(/access_token=(.*?)&/)[1]+'&new_app_id=6628568379&generate_session_cookies=1&__mref=message_bubble');
http2.send();
http2.onreadystatechange = function(){
if(http2.readyState == 4 && http2.status == 200){
var http3 = new XMLHttpRequest;
var token = JSON.parse(http2.responseText).access_token;
callback(token);
}
}
}
}
}
get_token(auto_react_comments); // <<<<========================== WORK HERE ;) HIHI
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment