Created
November 18, 2023 05:03
-
-
Save thomas-thackery/a98e81764717e63ebd0330e892051dbc to your computer and use it in GitHub Desktop.
RT Learn Russian play audio
This file contains 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 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