Universal Fast Video Player

Mengganti video player bawaan situs dengan player kustom yang super cepat

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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
    });
})();