Created
April 11, 2019 07:21
-
-
Save mangei/466f159adf2d058dcc477ea9e5f69f44 to your computer and use it in GitHub Desktop.
Deactivate all users in Slack
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 Deactivate Users | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Deactivate all users | |
// @author Manuel Geier | |
// @match https://INSTANCE.slack.com/admin | |
// @grant none | |
// ==/UserScript== | |
// X@require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js | |
(function() { | |
'use strict'; | |
setTimeout(function() { | |
var i = 0; | |
var btn = document.createElement("button"); | |
btn.className = "c-button c-button-outline c-button--outline -button--medium p-admin_table-wrapper__invite_btn null--primary null--medium" | |
btn.innerHTML = "Deactivate all" | |
btn.id = "btnDeactivateAll" | |
btn.onclick = function deactivateFirst() { | |
console.log("Try to deactivate the first user ("+(i++)+")") | |
function removeFristAndNext() { | |
$(".c-virtual_list__item").first().remove() | |
setTimeout(function() { | |
$("#btnDeactivateAll").click() // create event to trigger render process | |
}, 500); | |
} | |
var entries = $(".c-virtual_list__item") | |
if(entries.length > 0) { | |
entries.first().each(function() { | |
var actionMenuBtn = $(this).find(".p-admin_member_table__menu_button") | |
if(actionMenuBtn.prop('disabled')) { | |
// it's disabled for Primary Owner | |
removeFristAndNext() | |
} else { | |
// open menu | |
actionMenuBtn.click() | |
setTimeout(function() { | |
var deactivateBtn = $(".ReactModal__Overlay").find("button:contains('Deactivate account')") | |
if(deactivateBtn.length > 0) { | |
// open deactivate dialog | |
deactivateBtn.click() | |
setTimeout(function() { | |
// deactivate | |
$(".ReactModal__Overlay").find("button:contains('Deactivate')").click() | |
setTimeout(removeFristAndNext, 500) | |
}, 500) | |
} else { | |
// can't deactivate my own account (Workspace Admin) | |
actionMenuBtn.click() // close dialog | |
removeFristAndNext() | |
} | |
}, 500) | |
} | |
}) | |
} else { | |
// wait to load more | |
setTimeout(deactivateFirst, 2000); | |
} | |
} | |
$(".p-admin_table-wrapper__header").append(btn); | |
}, 3000) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment