Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Last active October 10, 2024 09:23
Show Gist options
  • Save ms-studio/318bfa853de306089c3e10605656a770 to your computer and use it in GitHub Desktop.
Save ms-studio/318bfa853de306089c3e10605656a770 to your computer and use it in GitHub Desktop.
Javascript that interacts with Readymag
console.log("trying to interact with Readymag...");
document.addEventListener('click', function (event) {
console.log("click intercepted!");
console.log( "click target: " + event.target );
if (event.target.matches('[data-id]')) {
// get the data-id of this
var dataID = event.target.getAttribute('data-id');
console.log(dataID);
if ( dataID == "67062ccd81545925be73f212") {
// play audio
var audio1 = document.querySelector(" [data-id='6706359bcde82ece0165030a'] video ");
audio1.currentTime = 0;
audio1.play();
}
} else if (event.target.matches('img')) {
// the closest ancestor with a data-id
console.log("target matches: img");
var dataID = event.target.parentElement.getAttribute('data-id');
console.log("closest id: "+dataID);
if ( dataID == "67068af9986fc1e1536aa9e1" ) {
// play audio
var audio1 = document.querySelector(" [data-id='6706359bcde82ece0165030a'] video ");
audio1.currentTime = 0;
audio1.play();
}
}
});
@ms-studio
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment