Universal Fast Video Player

Mengganti video player bawaan situs dengan player kustom yang super cepat

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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