Skip to content

Instantly share code, notes, and snippets.

@thomas-thackery
Created November 18, 2023 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomas-thackery/a98e81764717e63ebd0330e892051dbc to your computer and use it in GitHub Desktop.
Save thomas-thackery/a98e81764717e63ebd0330e892051dbc to your computer and use it in GitHub Desktop.
RT Learn Russian play audio
// ==UserScript==
// @name RT Learn Russian play audio
// @version 0.1
// @description try to take over the world!
// @author Красный 13
// @match https://learnrussian.rt.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=rt.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
//rewrite baseURI
const baseURI = "https://learnrussian.rt.com";
//Get all elements that contain relative audio uris
const collection = document.getElementsByClassName("playtwo");
//Iterate over HTMLCollection
for (let item of collection) {
//create a new Audio object so that we can use the play() method
let audio = new Audio(baseURI + item.attributes[0].nodeValue)
// console.log(audio)
// create a new button
let button = document.createElement("button");
button.innerHTML = "Play Audio ▶️";
//add button to each child
item.appendChild(button);
//make the button a click event that opens the full audio path a
button.addEventListener("click", () => {
audio.play();
});
}
// tests
// console.log(baseURI + uri[0].attributes[0].nodeValue);
// console.log(baseURI + uri[1].attributes[0].nodeValue);
// console.log(baseURI + uri[2].attributes[0].nodeValue);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment