unlock lpsg videos

unlock lpsg video access. may need to manually switch video format since I can't figure out a way to find it. Also load all images ASAP instead of having to scroll to them.

Ekde 2024/08/10. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         unlock lpsg videos
// @namespace    MBing
// @version      3.0
// @description  unlock lpsg video access. may need to manually switch video format since I can't figure out a way to find it. Also load all images ASAP instead of having to scroll to them.
// @author       MBing
// @match        https://www.lpsg.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license            MIT
// ==/UserScript==

(function() {
    'use strict';

    var easterEggPoster = document.getElementsByClassName("video-easter-egg-poster");
    var volume=0.1;
    var videoDiv=[];
    var imageUrl;
    var videoUrl;
    var newDiv;
    for (var i=easterEggPoster.length-1;i>-1;i--){
        imageUrl =easterEggPoster[i].children[0].src;
        videoUrl=imageUrl.replace("attachments/posters","video").replace("/lsvideo/thumbnails","lsvideo/videos").replace(".jpg",".mp4");
        videoDiv[i]=`<video onloadstart="this.volume=${volume}" style="width:750px; max-height: 750px;" controls=\"\" data-xf-init=\"video-init\" data-poster=\"${imageUrl}\" class=\"\" style=\"\" poster=\"${imageUrl}\"><source data-src=\"${videoUrl}\" src=\"${videoUrl}\"><div class=\"bbMediaWrapper-fallback\">Your browser is not able to display this video.</div></video>`;
        //void(easterEggPoster[i].innerHTML=videoDiv[i]);

        newDiv = document.createElement("div");
        newDiv.setAttribute("class","newVideoDiv");
        newDiv.innerHTML=videoDiv[i];
        easterEggPoster[i].parentElement.parentElement.append(newDiv);

        easterEggPoster[i].parentElement.parentElement.append(createButton("mov",i));
        easterEggPoster[i].parentElement.parentElement.append(createButton("m4v",i));
        easterEggPoster[i].parentElement.parentElement.append(createButton("mp4",i));
    }

    for (i=easterEggPoster.length-1;i>-1;i--){
        easterEggPoster[i].parentElement.parentElement.removeChild(easterEggPoster[i].parentElement);
    }

    var easterEggBlocker = document.getElementsByClassName("video-easter-egg-blocker");
    for (i=easterEggBlocker.length-1;i>-1;i--){
        easterEggBlocker[i].parentElement.removeChild(easterEggBlocker[i]);
    }

    var easterEggOverlay = document.getElementsByClassName("video-easter-egg-overlay");
    for (i=easterEggOverlay.length-1;i>-1;i--){
        easterEggOverlay[i].parentElement.removeChild(easterEggOverlay[i]);
    }

    var allVideoPlayers = document.getElementsByTagName('video');
    for (i=allVideoPlayers.length-1;i>-1;i--){
        allVideoPlayers[i].volume = volume;
    }

    //直接加载所有图片
    document.querySelectorAll('img[loading="lazy"]').forEach(img => img.loading = 'eager');

    function createButton(format,entryId){
        var inp;
        inp = document.createElement("input");
        inp.type = "button";
        inp.value = format;
        inp.id = entryId;
        inp.addEventListener('click', function () {
            var oldUrl = document.getElementsByClassName("newVideoDiv")[this.id].innerHTML;
            document.getElementsByClassName("newVideoDiv")[this.id].innerHTML=oldUrl.replaceAll("mp4",format).replaceAll("m4v",format).replaceAll("mov",format);
        });
        return inp;
    }

})();