Last active
March 24, 2020 16:39
-
-
Save NobleUplift/d67818bb2ffe6b2a81316e06bd0f7f20 to your computer and use it in GitHub Desktop.
GreaseMonkey script to remove Follows You profile cards from Following page
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
// ==UserScript== | |
// @name Hide Follows You | |
// @namespace twitter.com | |
// @description Hide mutuals to unfollow unfollowers. | |
// @match https://twitter.com/*/following | |
// @version 2 | |
// @require http://code.jquery.com/jquery-latest.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// ==/UserScript== | |
var neverUnfollow = new Set(); | |
// Add Twitter handles to never unfollow here | |
// neverUnfollow.add("") | |
function isError(element, expectedTag, level) { | |
//console.log(element[0].nodeName + ' == ' + expectedTag); | |
if (element == null || element[0] == null) { | |
console.log('ELEMENT AT LEVEL ' + level + ' IS NULL!'); | |
console.log(element); | |
return true; | |
} else if (element[0].tagName == expectedTag) { | |
return false; | |
} else { | |
console.log('ERROR DETECTED AT LEVEL ' + level + '!'); | |
console.log(element); | |
return true; | |
} | |
} | |
function hideFollowsYou (jNode) { | |
if (jNode.text() != jNode.html()) { | |
return; | |
} | |
//console.log('JNode HTML: '); | |
//console.log(jNode.html()); | |
var row = jNode; // span css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0 | |
if (isError(row, 'SPAN', -10)) | |
return; | |
row = row.parent() // span css-901oao css-16my406 css-bfa6kz r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0 | |
if (isError(row, 'SPAN', -9)) | |
return; | |
row = row.parent() // div css-901oao r-1awozwy r-jwli3a r-6koalj r-18u37iz r-16y2uox r-1qd0xha r-a023e6 r-vw2c0b r-1777fci r-eljoum r-dnmrzs r-bcqeeo r-q4m81j r-qvutc0 | |
if (isError(row, 'DIV', -8)) | |
return; | |
row = row.parent() // div css-18t94o4 css-1dbjc4n r-urgr8i r-42olwf r-sdzlij r-1phboty r-rs99b7 r-1w2pmg r-1vsu8ta r-aj3cln r-1fneopy r-o7ynqc r-6416eg r-lrvibr | |
if (isError(row, 'DIV', -7)) | |
return; | |
row = row.parent() // div css-1dbjc4n r-1n0xq6e | |
if (isError(row, 'DIV', -6)) | |
return; | |
row = row.parent() // div (name handle) css-1dbjc4n r-1awozwy r-18u37iz r-1wtj0ep | |
if (isError(row, 'DIV', -5)) | |
return; | |
row = row.parent() // div (name handle description) css-1dbjc4n r-1iusvr4 r-16y2uox r-5f2r5o | |
if (isError(row, 'DIV', -4)) | |
return; | |
row = row.parent() // div css-1dbjc4n r-18u37iz r-thb0q2 | |
if (isError(row, 'DIV', -3)) | |
return; | |
row = row.parent() // div css-18t94o4 css-1dbjc4n r-1j3t67a r-1w50u8q r-o7ynqc r-1j63xyz | |
if (isError(row, 'DIV', -2)) | |
return; | |
row = row.parent(); // div css-1dbjc4n r-1ila09b r-qklmqi r-1adg3ll | |
if (isError(row, 'DIV', -1)) | |
return; | |
row = row.parent(); // div | |
if (isError(row, 'DIV', 0)) | |
return; | |
//console.log('Row: '); | |
//console.log(row); | |
//console.log(row.attr('class')); | |
if (typeof row.attr('class') === 'string' && row.attr('class').length > 0) { | |
console.log('Incorrect row located!'); | |
return; | |
} | |
var userInfo = row.children().first(); // div | |
if (isError(userInfo, 'DIV', 1)) | |
return; | |
userInfo = userInfo.children().first(); // div | |
if (isError(userInfo, 'DIV', 2)) | |
return; | |
userInfo = userInfo.children().first(); // div | |
if (isError(userInfo, 'DIV', 3)) | |
return; | |
userInfo = userInfo.children().eq(1); // div (no avatar) | |
if (isError(userInfo, 'DIV', 4)) | |
return; | |
userInfo = userInfo.children().first(); // div | |
if (isError(userInfo, 'DIV', 5)) | |
return; | |
userInfo = userInfo.children().first(); // div | |
if (isError(userInfo, 'DIV', 6)) | |
return; | |
userInfo = userInfo.children().first(); // a | |
if (isError(userInfo, 'A', 7)) | |
return; | |
userInfo = userInfo.children().first(); // div | |
if (isError(userInfo, 'DIV', 8)) | |
return; | |
userInfo = userInfo.children().eq(1); // div (handle and follows you) | |
if (isError(userInfo, 'DIV', 9)) | |
return; | |
//var userInfo = row.first().first().first().children().eq(1).first().first().first().first().children().eq(1); | |
//console.log('User Info: '); | |
//console.log(userInfo); | |
var twitterHandle = userInfo.children().first().children().first(); | |
//console.log(twitterHandle.text().trim()); | |
var followStatus = userInfo.children().eq(1).children().first(); | |
//console.log(followStatus.text().trim()); | |
//var twitterHandle = jNode.find(".r-111h2gw:first-child"); // first-child excludes Follows you | |
//console.log("Never Unfollow has \"" + twitterHandle.text().trim().substr(1) + "\"? " + neverUnfollow.has(twitterHandle.text().trim().substr(1))); | |
if (neverUnfollow.has(twitterHandle.text().trim().substr(1))) { | |
console.log("Never Unfollow @" + twitterHandle.text().trim().substr(1)); | |
row.remove(); | |
} | |
//var followStatus = jNode.find(".r-aaos50"); | |
if (followStatus.text().trim() == "Follows you") { | |
row.remove(); | |
} | |
} | |
waitForKeyElements ('span:contains(Following)', hideFollowsYou); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment