Universal Fast Video Player

Mengganti video player bawaan situs dengan player kustom yang super cepat

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
    });
})();