Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
Last active March 30, 2020 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritwickdey/d8b8a218ca2bf48c94db109186b5a4a3 to your computer and use it in GitHub Desktop.
Save ritwickdey/d8b8a218ca2bf48c94db109186b5a4a3 to your computer and use it in GitHub Desktop.
/***
*
* @author Ritwick Dey (https://github.com/ritwickdey)
* @license MIT
*
* What is the hell?
* - This is a automated script to do n numbers of facebook comments.
*
* Perpose of the hell?
* You may seen such kind of post
* - If you do 2K or 10K comments, your facebook friend will do xyz... (may be he/she will be naked🤣).. I don't know..!🤔
*
* Okay, Steps for the hell?
* 1. Select the HTML comment Node via browser selector (where `contentEditable = true`)
* `2. paste the code
* 3. run following codes
* a = AutoComment(); //Optionally it accepts the comment node as first argument, you can skip if you've selected the html input node by selection tool.
* a.startComment(); // startComment() takes 2 optional parameters. first arg for noOfComments (Default 100) and 2nd arg for interval (default 1500ms). If you set interval less, Facebook may block your account. Keep interval large
* 4. That's all.
*
* 5. If you want to stop the comment in middle of the process just call `a.stopComment()
*
*
* Video link: https://youtu.be/MD9OXJdj0-4
*
*
* Oh man, this is not user friendly, have to do lot of stuff...
* --- I don't care 😑. normal user don't open console or developer tool. If normal user needs this type of script, browser extension is the possible solution
*
*/
function AutoComment(htmlNode = null) {
const targetNode = htmlNode || window.$0;
assert(targetNode.contentEditable === "true", "Not valid comment node");
const fbReactNode = getReactEvents(targetNode);
const pasteEvent = new ClipboardEvent("paste", {
clipboardData: new DataTransfer()
});
const enterEvent = new KeyboardEvent("keydown", {
code: "Enter",
key: "Enter",
keyCode: 13,
view: window
});
Object.defineProperty(enterEvent, "persist", {
value: () => {},
configurable: true
});
let commentCount = 0;
let _t;
function assert(condition, msg) {
if (!condition) {
console.error(msg);
throw new Error(msg);
}
}
function getReactEvents(targetNode) {
const keyName = Object.keys(targetNode).find(key =>
key.startsWith("__reactEvents")
);
console.log("React Key", keyName);
assert(keyName, "Unable to find react key");
return targetNode[keyName];
}
function generateNewText() {
return "Hello " + commentCount;
}
function doComment() {
const nextComment = generateNewText();
console.log(`[${commentCount}] Commenting: `, nextComment);
pasteEvent.clipboardData.setData("text/plain", nextComment);
fbReactNode.onPaste(pasteEvent);
fbReactNode.onKeyDown(enterEvent);
}
function startComment(capping = 10, interval = 1500) {
console.log(
`[AutoComment Started]. Target ${capping} comment(s), Comment interval: ${interval}ms`
);
_t = setInterval(() => {
commentCount = commentCount + 1;
doComment();
if (commentCount >= capping) {
stopComment();
}
}, interval);
}
function stopComment() {
console.log(`[AutoComment Stopped]. ${commentCount} comment(s) done!`);
clearTimeout(_t);
}
return {
startComment,
stopComment
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment