Skip to content

Instantly share code, notes, and snippets.

@bigethan
Created October 13, 2020 00:09
Show Gist options
  • Save bigethan/b74e2a27034bff4f49d294cf346439b6 to your computer and use it in GitHub Desktop.
Save bigethan/b74e2a27034bff4f49d294cf346439b6 to your computer and use it in GitHub Desktop.
Copies the link to stories as they are created in clubhouse. Not recommended if you don't use a clipboard history tool. To install click the `Raw` button and your userscript extension will take it from there.
// ==UserScript==
// @name Copy New Story Link
// @namespace http://bigethan.com/
// @version 0.1
// @description Adds the link to a created story to the clipboard (don't use without a clipboard history tool)
// @author @bigethan
// @match https://app.clubhouse.io/*
// @grant none
// ==/UserScript==
(function(document) {
'use strict';
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (
mutation.type === "childList" &&
mutation.addedNodes.length > 0 &&
/message-success/.test(mutation.addedNodes[0].className)
) {
let link = mutation.addedNodes[0].querySelector(".actions a");
if (link) {
navigator.clipboard.writeText(link.href);
}
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// wait for the page to load to have the messages element
setTimeout(function () {
observer.observe(document.getElementById("messages"), config);
}, 7000);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment