Last active
May 12, 2017 19:13
-
-
Save bodinsamuel/377b8004e21995d4c3669429a935b854 to your computer and use it in GitHub Desktop.
AgoraPulse automatic interaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code will automatically like or comment instagram post in agorapulse interface | |
* Instead of recode a fullbot, I decided to use the free version of agorapulse and try to code a little script to automate interactions | |
* This is just a try, the code is dirty and it's likely to fail in the future. | |
* | |
* | |
* How to use, after you logedin agorapulse | |
* go to your instagram account > tab monitoring (assuming you are monitoring some hashtag) | |
* then > | |
* | |
* 1- Copy this code in the dev console | |
* 2- type: "APA.run();" | |
* 3- filter console message "[AUTO]" | |
*/ | |
(function() { | |
/** | |
* Very Basic Sentences generator | |
* - It will pick a random templates (which cover 90% of instagram comments) | |
* - Then pick random emoji/word | |
* | |
* It can generate thousand of different combinaisons without too much code | |
* | |
**/ | |
function SentenceMaker() { | |
var _this = this; | |
var templates = [ | |
'{{word}} {{emoji}}', | |
'{{emoji}} {{word}}', | |
'{{emoji}} {{word}} {{emoji}}', | |
'{{emoji}}', | |
'{{word}}' | |
]; | |
var emojis = [ | |
'😍', ':)', '😊', '<3', '✌', '👌', ':o', | |
'👍', '🔥', '😚', '😲', '😏', '💪', '👏', | |
'🙏', '🙌', '👍', '💙', '❤' | |
]; | |
var words = [ | |
'wow', 'lovely', 'So niiice', 'I like it so much', 'incredible', | |
'wow, I need to get here', 'cool shot', 'perfect', 'amazing picture', | |
'Cute', 'That is dope, really great work', 'Wooow sooo pretty', | |
'Pretty', 'damn', 'amazing', 'So coooool', 'Great', 'I love this', | |
'Stunning', 'Love this one', 'Beautiful', 'brilliant pic', | |
'need to do the same pic', 'Sweet', 'Nice shot', 'Dope', | |
'Stunning', 'Wah', 'YES', 'So beautiful', 'Awesome', 'Oustanding', | |
'So great, keep it up', 'OMG', 'Awesome post', 'You\'r the best', | |
'OK wow', 'Super', 'Fabulous', 'Fantastique', 'Spectacular', 'Superbe', | |
'bravo' | |
]; | |
_this.emoji = function() { | |
var em = emojis[Math.floor(Math.random() * emojis.length)]; | |
return em.repeat(Math.round(Math.random() * 3)); | |
}; | |
_this.word = function() { | |
var wo = words[Math.floor(Math.random() * words.length)]; | |
var modifier = Math.random(); | |
console.log(modifier, wo); | |
if (modifier > 0.8) | |
wo = capitalizeFirstLetter(wo); | |
else if (modifier > 0.7) | |
wo = capitalizeAllFirstLetter(wo); | |
else if (modifier > 0.6) | |
wo = lowerAll(wo); | |
else if (modifier < 0.1) | |
wo = upperAll(wo); | |
var punc = (Math.random() * 10) > 9 ? '!'.repeat(Math.round(Math.random() * 3)) : ''; | |
return wo + punc; | |
}; | |
function capitalizeAllFirstLetter(string) { | |
return string.toLowerCase().split(' ').map(function(word) { | |
return capitalizeFirstLetter(word); | |
}).join(' '); | |
}; | |
function capitalizeFirstLetter(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
}; | |
function upperAll(string) { | |
return string.toUpperCase(); | |
}; | |
function lowerAll(string) { | |
return string.toLowerCase(); | |
}; | |
function run() { | |
var template = templates[Math.floor(Math.random() * templates.length)]; | |
var sentence = template; | |
var occurrences = template.match(/\{\{(.+?)\}\}/g); | |
if (!occurrences || !occurrences.length) | |
return sentence; | |
for (var i = 0; i < occurrences.length; i++) { | |
var action = occurrences[i].replace('{{', '').replace('}}', '').trim(); | |
var result = ''; | |
if (action.match(/\((.+?)\)/)) { | |
try { | |
result = eval(action); | |
} catch (e) {} | |
} else { | |
if (_this[action]) { | |
result = _this[action](); | |
} else { | |
result = '{{ ' + action + ' }}'; | |
} | |
} | |
sentence = sentence.replace(occurrences[i], result); | |
} | |
return sentence; | |
}; | |
return { | |
run: run | |
}; | |
}; | |
// ***************************************** MAIN Script | |
function Automatic() { | |
var _this = this; | |
var action = ['like', 'comment']; | |
_this.run = run; | |
_this.restart = restart; | |
_this.sentenceMaker = new SentenceMaker(); | |
return _this; | |
/** | |
* Launch main script | |
*/ | |
function run() { | |
var t = $('.table.background-white.table-hover tr.ng-scope > td:not(.approved) .list-item-wrapper'); | |
if (t.length <= 0) { | |
console.warn('[AUTO] nothing to do'); | |
return; | |
} | |
var $item = $(t.get(0)); | |
var action_rand = action[Math.floor(Math.random() * action.length)]; | |
// when liking we do not append comment | |
// but we mark it as reviewed | |
if (action_rand === 'like') { | |
like($item); | |
} else if (action_rand === 'comment') { | |
comment($item); | |
} | |
}; | |
/** | |
* Restart randomly to be less "bot" | |
*/ | |
function restart($item) { | |
// auto restart script* | |
var timeout = Math.round(Math.random() * 10000 * 4); | |
console.info('[AUTO] will restart in', timeout, 'ms'); | |
setTimeout(function() { | |
console.warn('[AUTO] RESTARTING', $item, _this); | |
// remove item, just to be sure | |
$item.parents('tr').remove(); | |
closePanel(); | |
Math.random() > 0.5 && clearReviewed(); | |
_this.run(); | |
}, timeout); | |
}; | |
/** | |
* Like a picture | |
*/ | |
function like($item) { | |
console.info('[AUTO]', 'Liking'); | |
var $like = $item.find('footer span[data-ng-controller="InstagramItemViewLikeController"] > a'); | |
$like.get(0).click(); | |
review($item); | |
restart($item); | |
}; | |
function openPanel($item) { | |
$item.click(); | |
}; | |
function closePanel() { | |
$('#mainFixedNav > a').get(0).click(); | |
}; | |
function review($item) { | |
var $review = $item.find('.btn-toolbar .btn.btn-small.item-action.ng-binding'); | |
$review.click(); | |
}; | |
function clearReviewed() { | |
$('.table.background-white.table-hover tr.ng-scope > td.approved').remove(); | |
}; | |
/** | |
* Comment a picture | |
*/ | |
function comment($item) { | |
openPanel($item); | |
var sentence = _this.sentenceMaker.run(); | |
console.info('[AUTO]', 'Writing "', sentence, '"'); | |
// Dirty way to wait for dom to be ready | |
setTimeout(function() { | |
var $text = $('#mainDetailWrapper form[name="replyForm"] textarea'); | |
$text.get(0).value = sentence; | |
setTimeout(function() { | |
var event = $.Event('input'); | |
$text.trigger(event); | |
setTimeout(function() { | |
var $button = $('#mainDetailWrapper .footer .pull-right .btn.btn-small'); | |
console.info('[AUTO]', 'submit'); | |
$button.get(0).click(); | |
review($item); | |
restart($item); | |
}, 100); | |
}, 100); | |
}, 1000); | |
}; | |
}; | |
window.APA = new Automatic(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment