🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

YouTube Float Player

Place the YouTube video in a small window at the bottom right corner when scrolling.

スクリプトをインストールするには、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 YouTube Float Player
// @namespace YouTube Float Player
// @version 1.0.0
// @description Place the YouTube video in a small window at the bottom right corner when scrolling.
// @author DumbGPT
// @match *://www.youtube.com/*
// @grant none
// ==/UserScript==

(function() {
'use strict';

var doc = document;
var win = window;
var floatheight = 0;

function docsearch(query) {
return doc.evaluate(query, doc, null, 7, null);
}

function insertStyle(str, id) {
var styleNode = null;
if (id != null) {
styleNode = doc.getElementById(id);
}
if (styleNode == null) {
styleNode = document.createElement("style");
styleNode.id = id;
styleNode.setAttribute("type", "text/css");
doc.head.appendChild(styleNode);
}
if (styleNode.textContent != str)
styleNode.textContent = str;
}

function reset_float() {
var page = docsearch("//ytd-page-manager/ytd-watch-flexy").snapshotItem(0);
if (!page) return;

if (page.getAttribute("float") != null) setTimeout(function () { win.dispatchEvent(new Event('resize')) }, 100);
page.removeAttribute("float");
page.parentNode.parentNode.removeAttribute("float");
insertStyle("", "ytpc_style_float");
floatheight = 0;
}

function float() {
if (win.location.href.indexOf("watch?") == -1) {
reset_float();
return;
}

var page = docsearch("//ytd-page-manager/ytd-watch-flexy").snapshotItem(0);
if (!page) return;

var intheater = page.getAttribute("theater") != null;
var fullscreen = page.getAttribute("fullscreen") != null;

if (fullscreen) {
reset_float();
return;
}

var vid = intheater ? docsearch("//*[@id='full-bleed-container']").snapshotItem(0)
: docsearch("//*[@id='primary-inner']/*[@id='player']").snapshotItem(0);
if (!vid) return;

var val = vid.getBoundingClientRect();
var vheight = val.bottom - val.top;

var W = doc.body.clientWidth || doc.documentElement.clientWidth;
var H = doc.body.clientHeight || doc.documentElement.clientHeight;
var height = 240;
var width = 427;

var infloat = page.getAttribute("float") != null;

if (!infloat) {
floatheight = vheight;
}

var thres = -1;
if (floatheight > 0) thres = floatheight - 220;

var scrollY = win.pageYOffset;

if (scrollY >= thres && thres > 0) {
page.setAttribute("float", "");
page.parentNode.parentNode.setAttribute("float", "");

var hoff = W - width;
var voff = H - height;
var rtl = (doc.body.getAttribute('dir') == 'rtl');
var lroff = rtl ? "right:0px !important;" : "left:" + hoff + "px !important;";

insertStyle("\
ytd-watch-flexy[float] #player-container {position: fixed !important; top: " + voff + "px !important; " + lroff + " width: " + width + "px !important; height: " + height + "px !important; z-index:1000 !important;}\
ytd-watch-flexy[float] .html5-main-video {width: " + width + "px !important; height: " + height + "px !important;}\
", "ytpc_style_float");
}
else {
reset_float();
}
}

win.addEventListener("focus", float, false);
win.addEventListener("blur", float, false);
win.addEventListener("resize", float, false);
win.addEventListener("scroll", float, false);

setInterval(float, 1000);
float();
})();