Skip to content

Instantly share code, notes, and snippets.

@blastrock
Last active November 9, 2020 14:39
Show Gist options
  • Save blastrock/072b5b105c898d3b83fc2883dcb8ecd3 to your computer and use it in GitHub Desktop.
Save blastrock/072b5b105c898d3b83fc2883dcb8ecd3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Slack To Meet
// @version 0.2
// @description Add a button to Slack to create a Google Meet and send the link
// @author blastrock
// @match https://app.slack.com/*
// @require https://raw.githubusercontent.com/uzairfarooq/arrive/master/minified/arrive.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
const arriveOpt = {
existing: true,
};
async function sendMeetImpl(messageText, sendButton) {
const randId = Math.random().toString().substring(2);
messageText.innerHTML = `https://g.co/meet/${randId}`;
await new Promise(r => setTimeout(r, 200));
sendButton.click();
}
async function sendMeet() {
const sendButton = document.querySelector('button[data-qa="texty_send_button"]');
const messageText = document.querySelector('div[data-qa="message_input"] div p');
sendMeetImpl(messageText, sendButton);
}
async function sendMeetThread() {
const sendButton = document.querySelector('div.p-threads_flexpane div[data-qa="reply_container"] button[data-qa="texty_send_button"]');
const messageText = document.querySelector('div.p-threads_flexpane div[data-qa="message_input"] div p');
sendMeetImpl(messageText, sendButton);
}
document.arrive('div.p-ia__view_header', arriveOpt, function () {
const meetButton = document.createElement("button");
meetButton.innerHTML = "Create Meet";
meetButton.setAttribute("class", "c-button-unstyled");
meetButton.setAttribute("data-qa", "slack-meet");
meetButton.onclick = sendMeet;
const upBar = this;
const config = { childList: true };
const callback = () => {
if (upBar.querySelector('button[data-qa="channel-details"]'))
{
if (!upBar.querySelector('button[data-qa="slack-meet"]'))
upBar.appendChild(meetButton);
} else {
upBar.removeChild(meetButton);
}
};
const observer = new MutationObserver(callback);
observer.observe(upBar, config);
callback();
});
document.arrive('div.p-flexpane_header__primary', arriveOpt, function () {
const upBar = this;
const meetButton = document.createElement("button");
meetButton.innerHTML = "Create Meet";
meetButton.setAttribute("class", "c-button-unstyled");
meetButton.onclick = sendMeetThread;
const closeButton = upBar.querySelector('button[data-qa="close_flexpane"]');
upBar.insertBefore(meetButton, closeButton);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment