我从Github获得了此代码,它似乎打开了“关注”窗口,然后单击我关注的用户,但是当Instagram询问“您确定吗?”时,它并不确定或某物像那样。 (我在Chrome控制台中运行程序)
注意:我的Instagam设置为德语,因此: 按照=“ abonniert” 取消确认的确认=“ Nicht mehr folgen”
openFollowersWindow().then(function () {
populateUnfollowsPool();
digestUnfollowsPool();
});
function openFollowersWindow() {
var onFollowersWindowWasOpenedListeners = [];
var openWindowTimeout = 3000;
var followersElement = getFollowersElement();
followersElement.click();
function digestOnFollowersWindowWasOpenedListeners() {
onFollowersWindowWasOpenedListeners.forEach(function (onFollowersWindowWasOpenedListener) {
onFollowersWindowWasOpenedListener();
});
}
var wasOpened;
setTimeout(function () {
// TODO Verify that the window was indeed opened
wasOpened = true;
digestOnFollowersWindowWasOpenedListeners();
}, openWindowTimeout);
return {
then: function (onFollowersWindowWasOpened) {
if (wasOpened) {
onFollowersWindowWasOpened();
} else {
onFollowersWindowWasOpenedListeners.push(onFollowersWindowWasOpened);
}
}
};
}
function getFollowersElement() {
return getFollowersElementWithUsername(getUsername());
}
function getUsername() {
var pageTitleElement = document.getElementsByTagName('h1')[0];
if (!pageTitleElement) throw new Error('No title to get username from');
return pageTitleElement.innerHTML;
}
function getFollowersElementWithUsername(username) {
var followersElement = document.querySelectorAll('a[href="/' + username + '/following/"]')[0];
if (!followersElement) throw new Error('No followers element was found');
return followersElement;
}
var unfollowsPool;
function populateUnfollowsPool() {
var buttons = document.getElementsByTagName('button');
unfollowsPool = [];
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
if (button.innerHTML.includes('Abonniert')) {
var randomTimeoutForUnfollow = Math.floor((Math.random() * 10) + 1) * 1000;
console.log('Following button!');
var unfollow = {
buttonElement: button,
timeout: randomTimeoutForUnfollow
};
unfollowsPool.push(unfollow);
}
}
}
function digestUnfollowsPool() {
if (unfollowsPool.length === 0) {
console.log('Unfollow pool empty, repopulating');
populateUnfollowsPool();
}
var unfollow = unfollowsPool.shift();
var unfollowTimeout = unfollow.timeout;
console.log('Clicking unfollow button in ', unfollowTimeout);
setTimeout(function () {
var unfollowButtonElement = unfollow.buttonElement;
unfollowButtonElement.scrollIntoView(true);
console.log('Clicking unfollow button');
unfollowButtonElement.click();
console.log('Clicked. Continuing digesting unfollow pool');
digestUnfollowsPool();
}, unfollowTimeout);
}