Skip to content

Instantly share code, notes, and snippets.

@barretlee
Last active March 30, 2023 03:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barretlee/6cd37c57152405dc47b143aee23ed3ea to your computer and use it in GitHub Desktop.
Save barretlee/6cd37c57152405dc47b143aee23ed3ea to your computer and use it in GitHub Desktop.
Clear Linkedin 'Following' in one second
// open: https://www.linkedin.com/feed/following/
// Attention: versionTag(TODO)
var csrf_token, lang, instance, track, version;
function fetchList(start, count) {
return $.ajax({
url: "https://www.linkedin.com/voyager/api/feed/richRecommendedEntities",
dataType: 'json',
data: {
count: count || 20,
q: 'unfollowHubRecommendations',
start: start || 40
},
headers: {
"csrf-token": csrf_token,
"x-li-lang": lang,
"x-li-page-instance": instance,
"x-li-track": track,
"x-restli-protocol-version": version
}
});
}
function unfollow(id) {
if (!id) return;
return $.ajax({
type: 'post',
url: `https://www.linkedin.com/voyager/api/feed/follows?action=unfollowByEntityUrn`,
dataType: 'json',
contentType: "application/json",
data: JSON.stringify({
urn: id
}),
headers: {
"csrf-token": csrf_token,
"x-li-lang": lang,
"x-li-page-instance": instance,
"x-li-track": track,
"x-restli-protocol-version": version
}
}).then(function (data) {
console.log(data)
}).fail(function (err) {
console.log(err)
});
}
var oldSet = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.setRequestHeader = function () {
if (csrf_token && lang && instance && track && version) {
oldSet.apply(this, [].slice.call(arguments))
!run._$ && run();
XMLHttpRequest.prototype.setRequestHeader = oldSet;
return;
}
if (arguments[0] && arguments[0].toLowerCase() === 'csrf-token') csrf_token = arguments[1];
if (arguments[0] && arguments[0].toLowerCase() === 'x-li-lang') lang = arguments[1];
if (arguments[0] && arguments[0].toLowerCase() === 'x-li-page-instance') instance = arguments[1];
if (arguments[0] && arguments[0].toLowerCase() === 'x-li-track') track = arguments[1];
if (arguments[0] && arguments[0].toLowerCase() === 'x-restli-protocol-version') version = arguments[1];
oldSet.apply(this, [].slice.call(arguments))
};
var getConfigInterval = setInterval(function () {
window.scrollTo(0, document.documentElement.offsetHeight)
}, 500);
function run() {
console.log('start clear');
// getConfigInterval && clearInterval(getConfigInterval);
run._$ = true;
var start = 0, total = 59;
while (start <= total) {
fetchList(start, 40).then(function (data) {
if (data && data.elements) {
data.elements.forEach(function (item, index) {
var member = item && item.recommendedEntity && item.recommendedEntity['com.linkedin.voyager.feed.packageRecommendations.RecommendedMember'];
// "urn:li:fs_followingInfo:urn:li:member:ACoAACnjv1gBMFX-d_papkcXnSM9sqvC1XOXyr8"
member && member.followingInfo && member.followingInfo.entityUrn && unfollow(member.followingInfo.entityUrn);
});
}
});
start += 20;
}
}
// $('button[data-control-name="actor_follow_toggle"]').trigger('click')
@barretlee
Copy link
Author

barretlee commented Feb 13, 2018

@barretlee
Copy link
Author

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