Inline Media Player (HTML5)

Watch video/audio URLs right on the page instead of downloading them!

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Inline Media Player (HTML5)
// @namespace    gfish
// @author       gfish
// @version      1.0
// @description  Watch video/audio URLs right on the page instead of downloading them!
// @license      MIT
// @match        *://*/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    const VIDEO_EXTENSIONS = ['mp4', 'm4v', 'mov', 'avi', 'mpeg', 'wmv', 'mov']
    const AUDIO_EXTENSIONS = ['mp3', 'wav', 'm4a', 'ogg', 'aac', 'flac']
    let inv = setInterval(() => {
        if (document.links.length > 0) {
            clearInterval(inv);
            Object.values(document.links).forEach(s => {
                let ext = s.href.split('.').pop().toLowerCase().split('?').shift();
                if (VIDEO_EXTENSIONS.includes(ext)) {
                    let frame = document.createElement("span");
                    frame.innerHTML = `<br><video controls="" loop preload="metadata" style="max-width: 100%; max-height: 100vh;" ><source src="${s.href}"></source></video>`;
                    s.parentNode.insertBefore(frame, s.nextSibling);
                }
                else if (AUDIO_EXTENSIONS.includes(ext)) {
                    let frame = document.createElement("span");
                    frame.innerHTML = `<br><audio controls="" loop preload="metadata" style="width: 100%;" ><source src="${s.href}"></source></audio>`;
                    s.parentNode.insertBefore(frame, s.nextSibling);
                }
            })
        }
    }, 100)
})();