User:Vitrinekast/Snatch these snippets: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "Copy-paste this into your console! (Right click -> inspect elements > console) == Adding audio elements to index files == <syntaxhighlight lang="javascript"> // select all links document.querySelectorAll("a").forEach((link) => { // if it includes your audio format if(link.href.indexOf(".mp3") > 0) { // create an audio element and set its source to yourlink var audioEl = document.createElement("audio"); audioEl.src = link.href; au...")
 
No edit summary
Line 5: Line 5:
// select all links
// select all links
document.querySelectorAll("a").forEach((link) => {
document.querySelectorAll("a").forEach((link) => {
     // if it includes your audio format
     // if it includes your audio format (regex)
 
     if(link.href.match(/\.(?:wav|mp3)$/i)) {
     if(link.href.indexOf(".mp3") > 0) {
         // create an audio element and set its source to yourlink
         // create an audio element and set its source to yourlink
         var audioEl = document.createElement("audio");
         var audioEl = document.createElement("audio");

Revision as of 11:30, 9 October 2023

Copy-paste this into your console! (Right click -> inspect elements > console)

Adding audio elements to index files

// select all links
document.querySelectorAll("a").forEach((link) => {
    // if it includes your audio format (regex)
    if(link.href.match(/\.(?:wav|mp3)$/i)) {
        // create an audio element and set its source to yourlink
        var audioEl = document.createElement("audio");
        audioEl.src = link.href;
        audioEl.controls = true;
        audioEl.style.display = "block";
        link.insertAdjacentElement("afterend", audioEl)
    };
});