Universal Fast Video Player

Mengganti video player bawaan situs dengan player kustom yang super cepat

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Universal Fast Video Player
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Mengganti video player bawaan situs dengan player kustom yang super cepat
// @author       Ajit Prasetiyo
// @match        *://*/*
// @exclude      *://*.youtube.com/*
// @exclude      *://*.netflix.com/*
// @license      MIT
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Setelan performa player kustom
    const PLAYER_STYLES = `
        .custom-player-container {
            position: relative;
            width: 100%;
            height: 100%;
            background: #000;
        }
        .my-fast-player {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
    `;

    // Tambahkan style ke halaman
    const styleEl = document.createElement('style');
    styleEl.textContent = PLAYER_STYLES;
    document.head.appendChild(styleEl);

    function replaceWithCustomPlayer(originalVideo) {
        // Cek apakah video ini sudah kita ganti sebelumnya agar tidak looping
        if (originalVideo.dataset.replacedByCustom) return;

        const videoSrc = originalVideo.currentSrc || originalVideo.src;
        if (!videoSrc) return; // Keluar jika tidak ada sumber video yang valid

        console.log("Menemukan video asli, mencoba mengganti dengan Fast Player...", videoSrc);

        // Buat kontainer player baru
        const container = document.createElement('div');
        container.className = 'custom-player-container';

        // Buat elemen video baru buatan sendiri
        const myPlayer = document.createElement('video');
        myPlayer.className = 'my-fast-player';
        myPlayer.controls = true;
        myPlayer.autoplay = originalVideo.autoplay;
        
        // Optimasi Performa Kecepatan:
        myPlayer.preload = 'auto'; // Memaksa browser mengunduh video secepat mungkin
        myPlayer.style.willChange = 'transform'; // Memicu akselerasi GPU hardware

        // Salin sumber videonya
        myPlayer.src = videoSrc;

        // Masukkan player baru ke kontainer
        container.appendChild(myPlayer);

        // Sembunyikan player asli (jangan dihapus agar tidak merusak script bawaan web)
        originalVideo.style.display = 'none';
        originalVideo.dataset.replacedByCustom = 'true';

        // Selipkan player baru tepat di sebelah atau di atas player asli
        originalVideo.parentNode.insertBefore(container, originalVideo);
        
        // Pause video asli agar suara tidak tabrakan
        originalVideo.pause();
    }

    // Monitor halaman untuk mendeteksi video yang muncul belakangan (pemuatan dinamis)
    const observer = new MutationObserver(() => {
        const videos = document.querySelectorAll('video');
        videos.forEach(video => {
            if (video && !video.dataset.replacedByCustom && (video.src || video.currentSrc)) {
                replaceWithCustomPlayer(video);
            }
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();