-
Notifications
You must be signed in to change notification settings - Fork 19
/
delete-likes.js
86 lines (73 loc) · 2.37 KB
/
delete-likes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// https://www.linkedin.com/in/{username}/detail/recent-activity
/**
* Halts execution for a certain amount of seconds.
* https://stackoverflow.com/a/39914235
*/
function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
// Gets like buttons on posts you've thumbed up.
function getLikesOnPosts() {
return document.querySelectorAll(".react-button__trigger.artdeco-button[aria-pressed=\"true\"]");
}
// Gets like buttons on comments you've thumbed up.
function getLikesOnComments() {
return document.querySelectorAll(".comments-comment-social-bar__like-action-button[aria-pressed=\"true\"]");
}
//
function getDeleteCommentButtons() {
var buttons = [];
for (const span of document.querySelectorAll("span.mh4.comments-options-menu__text")) {
if (span.textContent.includes("Delete")) {
buttons.push(span);
}
}
return buttons;
}
// Forces click on "load more comments" buttons.
function loadMoreComments() {
var loadMoreCommentsButtons = document.querySelectorAll(".button.comments-comments-list__show-previous-button");
for (var i = 0; i < loadMoreCommentsButtons.length; i++) {
loadMoreCommentsButtons[i].click();
}
}
// Forces click on "load previous replies" buttons.
function loadPreviousReplies() {
var loadPreviousRepliesButtons = document.querySelectorAll("button.show-prev-replies");
for (var i = 0; i < loadPreviousRepliesButtons.length; i++) {
loadPreviousRepliesButtons[i].click();
}
}
// Forces scroll down and loads more comments and previous replies
function loadMoreActivity() {
window.scrollTo(0, document.body.scrollHeight);
loadMoreComments();
loadPreviousReplies();
}
//
function deleteActivity() {
var i;
var likesOnPosts = getLikesOnPosts();
for (i = 0; i < likesOnPosts.length; i++) {
console.log(likesOnPosts[i].click());
}
var likesOnComments = getLikesOnComments();
for (i = 0; i < likesOnComments.length; i++) {
console.log(likesOnComments[i].click());
}
}
//
var keepGoing = true;
async function init() {
console.log("*** Starting activity deletion ***");
console.log(">>> Loading more activity")
loadMoreActivity();
await sleep(2);
console.log(">>> Deleting loaded activity")
deleteActivity();
if (keepGoing) {
await sleep(5);
init();
}
}
init();