Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Background script for Agreed - Slack Chrome Extension
chrome.commands.onCommand.addListener(function(command) {
if (command === "agree-first-reaction") {
chrome.tabs.executeScript({
code: `
function clickFirstReaction() {
const query = "div.c-reaction_bar > button:nth-child(1):not(.c-reaction--reacted)";
const reactionsToClick = document.querySelectorAll(query);
const beforeCount = reactionsToClick.length;
if (reactionsToClick.length) {
reactionsToClick.forEach((button) => { button.click()} );
}
const afterCount = document.querySelectorAll(query).length;
}
clickFirstReaction()`
})
}
else if (command === "agree-every-reaction") {
chrome.tabs.executeScript({
code: `
function clickEveryReaction() {
const query = "div > button.c-reaction:not(.c-reaction--reacted)";
const reactionsToClick = document.querySelectorAll(query);
const beforeCount = reactionsToClick.length;
if (reactionsToClick.length) {
reactionsToClick.forEach((button) => { button.click()} );
}
const afterCount = document.querySelectorAll(query).length;
}
clickEveryReaction()`
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.