Skip to content

Instantly share code, notes, and snippets.

@diegorv
Forked from cacheflowe/remove-twitter-likes.js
Created August 31, 2018 01:31
Show Gist options
  • Save diegorv/9eaa162e0ec2acdb3b67e406925a08b9 to your computer and use it in GitHub Desktop.
Save diegorv/9eaa162e0ec2acdb3b67e406925a08b9 to your computer and use it in GitHub Desktop.
Remove your Twitter likes
// go to your account Likes page and run this in the console:
function scrollToLoadMore() {
// keep scrolling if twitter tries to stop loading more.
// scroll up, then down to force infinite load.
window.scrollTo(0, 0);
setTimeout(function() {
window.scrollBy(0, 9999999999);
}, 200);
}
function removeTweet(tweetEl) {
// show it
tweetEl.style.backgroundColor = 'rgba(255,0,0,0.5)';
tweetEl.scrollIntoView();
window.scrollBy(0, -150);
// remove it
let favButton = tweetEl.querySelector('.js-actionFavorite');
favButton.click();
setTimeout(function() {
tweetEl.parentNode.removeChild(tweetEl);
}, 250);
}
function favThenRemove(tweetEl) {
// older tweets in your likes list may not show the favorited state correctly, so we click, then un-click.
// show it.
tweetEl.style.backgroundColor = 'rgba(0,255,0,0.5)';
// fav it.
let favButton = tweetEl.querySelector('.js-actionFavorite');
favButton.click();
setTimeout(function() {
removeTweet(tweetEl);
}, 450);
}
function removeFav() {
let tweetEl = document.querySelector('.js-actionable-tweet');
if(tweetEl) {
if(tweetEl.classList.contains('favorited')) {
removeTweet(tweetEl);
} else {
favThenRemove(tweetEl);
}
} else {
scrollToLoadMore();
}
}
let unfavInterval = setInterval(removeFav, 500);
@diegorv
Copy link
Author

diegorv commented Aug 31, 2018

setInterval(
function() {
t = $( 'button.ProfileTweet-action--unfavorite' ); // get unfavourite buttons
for ( i = 0; true; i++ ) { // count
if ( i >= t.length ) { // if items remain to unfavourite
window.scrollTo( 0, $( document ).height() ); // scroll to bottom of page - loads more
return
}
$( t[i] ).trigger( 'click' ).remove(); // click and remove button from dom
}
}, 2000
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment