mnm777-fbcb
Version:
FB Commenter Bot allows you to add comments automatically to a post. The number of comments you may add varies on what you will set. Please see the readme.txt to learn how to use this commenter app.
166 lines (140 loc) • 6.07 kB
JavaScript
// Facebook Commenter Bot;
function CommenterBot(options) {
this.parentContainer = (function(){
if(typeof module === "object" && typeof module.exports === "object") {
return null;
} else if(typeof window !== "undefined" && typeof window.document !== "undefined") {
return window.document.querySelector("._uwt._45kb._3ioy");
}
}());
this.randomComments = options.randomComments;
this.targetNumberOfComments = options.targetNumberOfComments;
// current number of comments made
this.numberOfCommentsMade = 0;
this.numberOfCommentsPerSession = 0;
this.shuffledCommentCounter = 0;
this.setPreReq();
this.shuffle(this.randomComments);
}
CommenterBot.prototype.setPreReq = function() {
if(this.parentContainer) {
// element that triggers whether input is on focus;
this.composerDetector = this.parentContainer.querySelector("._5ru3._3tl8._2pid");
// parent container for the mentions input
this.mentionsDiv = this.parentContainer.querySelector(".mentions");
// place where the new comment has to be added into;
this.mentionsPlaceholder = this.mentionsDiv.querySelector(".mentions-placeholder");
this.textArea = this.mentionsDiv.querySelector("textarea.mentions-input");
this.mentionsHiddenInput = this.mentionsDiv.querySelector("input[name='comment_text']");
this.mentionsShadow = this.mentionsDiv.querySelector(".mentions-shadow");
this.mentionsMeasurer = this.mentionsDiv.querySelector(".mentions-measurer");
// submit button;
this.submitButton = this.parentContainer.querySelector("button[type='submit']");
} else {
return {
message : `This app needs a browser window to operate.`,
messageType : "Error",
};
}
}
CommenterBot.prototype.getCurrentTime = function() {
let date = new Date(),
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",];
return `${days[date.getDay()]} => ${date.getHours()} : ${date.getMinutes()} : ${date.getSeconds()}`;
}
CommenterBot.prototype.textAreaOnFocus = function() {
this.textArea.click();
this.textArea.focus();
}
CommenterBot.prototype.openComposer = function() {
this.composerDetector.classList.remove("composerClosed");
}
CommenterBot.prototype.hidePlaceHolder = function() {
this.mentionsPlaceholder.style.display = "none";
}
CommenterBot.prototype.selectRandomComment = function() {
let randomNum = Math.floor(Math.random() * this.randomComments.length),
selectedComment = this.randomComments[randomNum];
selectedComment = this.checkString(selectedComment);
return selectedComment;
}
CommenterBot.prototype.checkString = function(str) {
if(str.includes("@nth")) {
str = str.replace("@nth", this.numberOfCommentsMade);
}
return str;
}
CommenterBot.prototype.enableSubmitButton = function() {
this.submitButton.classList.add("_653w");
this.submitButton.classList.remove("_56bt");
this.submitButton.classList.add("_56bv");
this.submitButton.removeAttribute("disabled");
}
CommenterBot.prototype.shuffle = function(arr) {
for(let i = arr.length - 1; i >= 0; i--) {
let randomNum = Math.floor(Math.random() * i);
[arr[i], arr[randomNum]] = [arr[randomNum], arr[i]];
}
}
CommenterBot.prototype.shuffledCommentsResult = function() {
if(this.shuffledCommentCounter === this.randomComments.length) {
this.shuffle(this.randomComments);
this.shuffledCommentCounter = 0;
console.log("new set of shuffled comments")
}
let selectedComment = this.randomComments[this.shuffledCommentCounter];
selectedComment = this.checkString(selectedComment);
this.shuffledCommentCounter += 1;
return selectedComment;
}
CommenterBot.prototype.commentSubmitted = function() {
let interval = setInterval(() => {
if(this.composerDetector.classList.contains("composerClosed")) {
clearInterval(interval);
setTimeout(() => {
this.initialize();
}, 500);
}
}, 100);
}
CommenterBot.prototype.addComment = function() {
let comment = this.shuffledCommentsResult();
this.numberOfCommentsMade += 1;
this.numberOfCommentsPerSession += 1;
// let comment = this.selectRandomComment();
this.textArea.value = comment;
this.mentionsHiddenInput.value = comment;
this.mentionsShadow.innerText = comment;
this.mentionsMeasurer.innerText = comment;
this.enableSubmitButton();
this.submitButton.click();
this.commentSubmitted();
}
CommenterBot.prototype.initialize = function() {
if(this.numberOfCommentsMade === 0) {
console.log(`Session starts at : ${this.getCurrentTime()}`);
}
if(this.numberOfCommentsMade < this.targetNumberOfComments) {
if(this.numberOfCommentsPerSession >= 250) {
console.log(`Session ended at : ${this.getCurrentTime()}`);
setTimeout(()=>{
console.log(`Resuming session at : ${this.getCurrentTime()}`);
this.numberOfCommentsPerSession = 0;
this.textAreaOnFocus();
this.openComposer();
this.hidePlaceHolder();
this.addComment();
console.log(`current number of comments made : ${this.numberOfCommentsMade}`);
}, 3600000);
} else {
this.textAreaOnFocus();
this.openComposer();
this.hidePlaceHolder();
this.addComment();
console.log(`current number of comments made : ${this.numberOfCommentsMade}`);
}
} else {
console.log("we have reached the target number of comments");
}
}
module.exports.CommenterBot = CommenterBot;