Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unfollow-pinterest.userscript.js
// ==UserScript==
// @name Pinterest Autounfollow
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Autofollow
// @author Alex DeLorenzo
// @match https://www.pinterest.com/organicallergyr/following
// @match https://www.pinterest.com/organicallergyr/following/*
// @require http://code.jquery.com/jquery-latest.js
// @grant none
// ==/UserScript==
const SECOND = 1000; // 1 second = 1000 milliseconds
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const RATE_LIMIT_TIMEOUT = 5 * MINUTE;
const PAGE_LOAD_TIMEOUT = 6 * SECOND;
const UNFOLLOW_COUNT = 200;
function get_followed() {
return $("button.antialiased");
}
function auto_scroll () {
$(window).scrollTop($(document).height());
}
function unfollow(followed) {
for (const follower of followed) {
if (follower.textContent.includes("Unfollow")) {
follower.click();
}
}
}
function build_follow_array(followers = []) {
if (followers.length < UNFOLLOW_COUNT) {
followers.push(...(get_followed().toArray()));
auto_scroll();
console.log("Waiting "+ PAGE_LOAD_TIMEOUT +"...");
setTimeout(build_follow_array, PAGE_LOAD_TIMEOUT, followers);
}
else {
return followers.slice(0, UNFOLLOW_COUNT);
}
}
function scroll_unfollow() {
const followed = build_follow_array();
unfollow(followed);
console.log("Waiting "+ RATE_LIMIT_TIMEOUT +"...");
setTimeout(scroll_unfollow, RATE_LIMIT_TIMEOUT);
}
function is_rate_limit_hit() {
return $(".ConfirmDialog").length !== 0;
}
function build_btn() {
const btn = $("<button/>",
{text: "Unfollow All These Niggas",
id: "unfollow_all",
click: scroll_unfollow});
$( document ).ready(function() {
$("div.headerContainer").append(btn);
btn.show();
});
}
(function() {
'use strict';
build_btn();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment