Skip to content

Instantly share code, notes, and snippets.

@rf5860
Last active January 7, 2024 08:41
Show Gist options
  • Save rf5860/ebd6185356900255e7f50241fff4811e to your computer and use it in GitHub Desktop.
Save rf5860/ebd6185356900255e7f50241fff4811e to your computer and use it in GitHub Desktop.
Script to add a "Copy Link" button for audio files/voicelines on some fandom/Wiki sites
// ==UserScript==
// @name VoiceLines to Clipboard
// @version 0.2
// @description Add a button to copy links for voicelines to the clipboard
// @author rjf89
// @updateURL https://gist.githubusercontent.com/rf5860/ebd6185356900255e7f50241fff4811e/raw/e17b04152cf26ea652986051d35be264bd53d040/VoiceLines%2520to%2520Clipboard.js
// @downloadURL https://gist.githubusercontent.com/rf5860/ebd6185356900255e7f50241fff4811e/raw/e17b04152cf26ea652986051d35be264bd53d040/VoiceLines%2520to%2520Clipboard.js
// @match https://*.fandom.com/wiki/*/Quotes
// @match https://*.fandom.com/wiki/*/Voice_lines
// @match https://*.fandom.com/wiki/*_voice_lines
// @match https://*.fandom.com/wiki/*/Responses
// @match https://*.fandom.com/wiki/*_Announcer_pack
// @match https://db.ascension.gg/?npc=*#sounds
// @icon https://static.wikia.nocookie.net/overwatch_gamepedia/images/2/2a/PI_Overwatch_Logo_White.png/revision/latest/scale-to-width-down/100?cb=20160706121419
// @grant GM_setClipboard
// ==/UserScript==
(function() {
function setClipboard(e) {
console.log(e.target);
const audio = e.target.parentElement.querySelector('audio[src],source[src]')
GM_setClipboard (audio.src.toString());
}
function addClipboard(a) {
const link = a[0];
const span = document.createElement("span");
span.addEventListener("mouseup", setClipboard, false);
span.style = "cursor: pointer";
span.textContent = "📋";
a[0].parentElement.appendChild(span);
}
// Create a new observer
const observer = new MutationObserver((mutationsList, observer) => {
// Look through all mutations that just occured
for(let mutation of mutationsList) {
// If the addedNodes property has one or more nodes
if(mutation.addedNodes.length) {
const nodes = document.querySelectorAll("div.audio-button, a.ext-audiobutton");
nodes.forEach(node => {
if(!node.dataset.alreadyFound) {
addClipboard([node]);
node.dataset.alreadyFound = true;
}
});
}
}
});
// Start observing the document with the configured parameters
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment