Skip to content

Instantly share code, notes, and snippets.

@mbparvezme
Created April 13, 2020 22:37
Show Gist options
  • Save mbparvezme/13817b7306ce38053741e3de49049b35 to your computer and use it in GitHub Desktop.
Save mbparvezme/13817b7306ce38053741e3de49049b35 to your computer and use it in GitHub Desktop.
var _memberMenus = document.getElementsByTagName('button');
var _confirmed = false;
var _i = 0;
var _f = 0;
var _resetAttempted = false;
function clickMemberMenu() {
if (typeof(_memberMenus[_f]) !== 'undefined' && _memberMenus[_f].getAttribute('aria-label') == 'Member Settings') {
_resetAttempted = false;
_memberMenus[_f].click();
setTimeout(getAnchorsForMember, 1000);
}else{
_f++;
if (_memberMenus.length > _f) {
clickMemberMenu();
}else if (_resetAttempted) {
console.log('Stopping 1');
}else{
setTimeout(resetAndStartAgain(), 1000);
}
}
}
function getAnchorsForMember() {
if (document.querySelector(".uiContextualLayerPositioner.uiLayer:not(.hidden_elem)") &&
document.querySelector(".uiContextualLayerPositioner.uiLayer:not(.hidden_elem)").querySelector('[data-testid="leave_group"]') &&
document.querySelector(".uiContextualLayerPositioner.uiLayer:not(.hidden_elem)").querySelector('[data-testid="leave_group"]').textContent == 'Remove from Group') {
document.querySelector(".uiContextualLayerPositioner.uiLayer:not(.hidden_elem)").querySelector('[data-testid="leave_group"]').click();
console.log('Clicked');
setTimeout(waitForConfirmationButton, 1000);
}else{
console.log('No link for member');
_f++;
if (_memberMenus.length > _f) {
clickMemberMenu();
}else{
setTimeout(resetAndStartAgain(), 1000);
}
}
}
function waitForConfirmationButton() {
if (document.querySelector(".uiLayer:not(.hidden_elem)") && document.querySelector(".uiLayer:not(.hidden_elem)").querySelector('.layerConfirm')) {
document.querySelector(".uiLayer:not(.hidden_elem)").querySelector('.layerConfirm').click();
_confirmed = true;
console.log('confirmed');
setTimeout(finishedAnchor, 1000);
}else{
setTimeout(waitForConfirmationButton, 1000);
}
}
function finishedAnchor() {
_confirmed = false;
checkForNextMember();
}
function checkForNextMember() {
_f++;
if (_memberMenus.length > _f) {
clickMemberMenu();
}else{
resetAndStartAgain();
}
}
function resetAndStartAgain() {
console.log('Resetting');
_i = 0;
_f = 0;
_resetAttempted = true;
_memberMenus = document.getElementsByTagName('button');
if (_memberMenus.length > _f) {
clickMemberMenu();
}else{
console.log('Stopping 2');
}
}
if (_memberMenus.length > _f) {
console.log(_memberMenus.length);
clickMemberMenu();
}else{
console.log('Stopping 3');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment