project Websites / videos.bentasker.co.uk avatar

Websites / videos.bentasker.co.uk / Release: v0.19



Git Tag: v0.19
Commit: 2ebc9f72
Released: 11 Mar 2022 19:45:39

V0.19

This release was made to support delivering www.bentasker.co.uk via eepsite (jira-projects/CDN#13)

However, unless the user has an outproxy configured, there are supporting changes required on the embedding website (because the user won't be able to fetch https://videos.bentasker.co.uk/resources/embed/embed.min.js). Assuming the site is dual-homed, it obviously isn't an option to just embed the I2P name.

The following javascript, when called, will iterate over any <script> tags and rewrite their source. And additional video tag is inserted at the event to act as a ready-ness switch for calling the embed function.

function Clearnet2I2P(){
    if (!window.location.hostname.split(".").pop().toLowerCase() == "i2p"){
        /* Nothing to do */
        return;
    }

    var video_found = false;

    mappings = {
        "pfanalytics.bentasker.co.uk" : "5es4aj6pfdxoz6oz6vbcczix25dlfelrdav6a6hw7tuudb7kxwba.b32.i2p",
        "videos.bentasker.co.uk" : "bapmqkdc7xotvlym3bj75gdb4tlgg2poezkmz36w64qum4racpyq.b32.i2p"
    }

    var i, src, dom, newurl, newele;
    var buf = [];
    var eles = document.getElementsByTagName('script');

    for (i=0; i<eles.length; i++){
        src = eles[i].getAttribute("src");
        if (!src || src[0] == "/" || src[0] == "."){
            // Relative or empty link, skip
            continue;
        }

        dom = src.split("/")[2].toLowerCase();

        if (!video_found && dom.includes("videos.bentasker.co.uk")){
            video_found = true;
        }

        // Do we have a mapping for that domain?
        if (mappings[dom]){
            newurl = src.replace("://"+dom, "://" + mappings[dom]).replace("https://","http://");

            newele = document.createElement('script');
            newele.setAttribute("src", newurl);

            // Push to a buffer - the DOM will be updated later
            //
            // This helps avert an infinite loop
            buf.push([newele, eles[i]]);
        }
    }

    // Process anything we've found
    for (i=0; i<buf.length; i++){
        buf[i][1].parentNode.insertBefore(buf[i][0], buf[i][1]);
    }

    if (video_found){
        // We want to re-detect videos once we know the script has loaded
        s = document.createElement('script');
        s.setAttribute('src', 'http://bapmqkdc7xotvlym3bj75gdb4tlgg2poezkmz36w64qum4racpyq.b32.i2p/resources/embed/embed.min.js');
        s.addEventListener('load',function(){embedBensPlayerDivs()});
        document.body.appendChild(s);
    }

}

Clearnet2I2P();
Snapshots


Milestones: