Created
May 13, 2019 17:30
-
-
Save JustinShenk/a5f4599b7755784eaaa2d76e3ea1d801 to your computer and use it in GitHub Desktop.
Background script for Agreed - Slack Chrome Extension
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
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