GBT HTML5 native player, full preload, download (GBTPP)

Replaces fluid player with browsers HTML5 native player, initialises native preload and proceeds full preload in background.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         GBT HTML5 native player, full preload, download (GBTPP)
// @version      4.61
// @namespace    _pc
// @description  Replaces fluid player with browsers HTML5 native player, initialises native preload and proceeds full preload in background.
// @author       verydelight
// @license      MIT
// @icon         https://www.gayporntube.com/favicon.ico
// @connect      gayboystube.com
// @connect      gayporntube.com
// @compatible   Firefox Tampermonkey
// @grant        GM.xmlHttpRequest
// @grant        GM_download
// @grant        GM_xmlHttpRequest
// @grant        GM.download
// @match        *://*.gayboystube.com/video/*
// @match        *://*.gayporntube.com/video/*
// @webRequest   {"selector":"*fluidplayer*","action":"cancel"}
// ==/UserScript==
(async function() {
	const videoplayer = document.getElementById('play-video');
	const videoplayerSource = videoplayer.querySelector('source');
	const pattern = /\/\?br=\d*$/;
	if (videoplayerSource) {
		const src = videoplayerSource.src.replace(pattern, '');
		if (src !== videoplayerSource.src) {
			videoplayerSource.src = src;
		}
		videoplayer.removeAttribute("height");
		videoplayer.removeAttribute("width");
        videoplayer.setAttribute("preload","auto");
        videoplayer.focus();
		await downloadVideo(videoplayerSource.src);
	}
	async function downloadVideo(url) {
		try {
			const response = await GM.xmlHttpRequest({
				method: 'GET',
				responseType: 'blob',
				url: url,
				headers: {
					"Content-Type": "video/mp4",
					"Accept": "video/mp4"
				},
			});
			const blob = new Blob([response.response], { type: 'video/mp4' });
			const objectUrl = URL.createObjectURL(blob);
			const { currentTime, paused, ended } = videoplayer;
            videoplayerSource.src = objectUrl;
			videoplayer.load();
            videoplayer.currentTime = currentTime;
			if (!paused && !ended && currentTime > 0) {
				videoplayer.play();
			}
            //const parts = url.split("/");
            //const filename = parts[parts.length - 1];
            const dlinfo = document.createElement('div');
            dlinfo.textContent = "Video ready/fully preloaded - Click download button or use save as or save video as from context menue";
            dlinfo.classList.add("blue");
            dlinfo.style.fontWeight = "bold";
            const container = document.querySelector("#tab_video_info");
            const dlBttn = container.querySelector(".bttn");
            const href = dlBttn.getAttribute('href');
            const urlObj = new URL(href);
            const filename = urlObj.searchParams.get('download_filename');
            dlBttn.href = objectUrl;
            dlBttn.download = filename;
            videoplayer.parentNode.insertBefore(dlinfo, videoplayer.nextSibling);
		} catch (err) {
			console.error("GBTPP: Error in fetching and downloading file: ", err);
		}
	}
})();