Created
October 13, 2020 00:09
-
-
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.
This file contains hidden or 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
// ==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