Universal Fast Video Player

Mengganti video player bawaan situs dengan player kustom yang super cepat

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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
    });
})();