Skip to content

Instantly share code, notes, and snippets.

@JustinShenk
Created May 13, 2019 17:30
Show Gist options
  • Save JustinShenk/a5f4599b7755784eaaa2d76e3ea1d801 to your computer and use it in GitHub Desktop.
Save JustinShenk/a5f4599b7755784eaaa2d76e3ea1d801 to your computer and use it in GitHub Desktop.
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