//监听
// const observer = new MutationObserver(function(mutationsList, observer) {console.log(mutationsList)});
// observer.observe(
// document.querySelector("")
// , { attributes: true, attributeOldValue: true, characterData: true, characterDataOldValue:true,childList: true, subtree: true, });
//获取浏览器缩放百分比的方法
// function detectZoom() {
// var ratio = 0,
// screen = window.screen,
// ua = navigator.userAgent.toLowerCase();
// if (window.devicePixelRatio !== undefined) {
// ratio = window.devicePixelRatio;
// }
// else if (~ua.indexOf('msie')) {
// if (screen.deviceXDPI && screen.logicalXDPI) {
// ratio = screen.deviceXDPI / screen.logicalXDPI;
// }
// }
// else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
// ratio = window.outerWidth / window.innerWidth;
// }
// if (ratio) {
// ratio = Math.round(ratio * 100);
// }
// return ratio;
// };
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// @match *.bilibili.com/video/*
// @match *.bilibili.com/s/video/*
// @match *.bilibili.com/bangumi/play/*
// @match *.bilibili.com/cheese/play/*
// @match *.bilibili.com/blackboard/*
// @match *.bilibili.com/medialist/play/watchlater/*
// @match *.biligame.com/detail/*
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//$(document).scrollTop();
//结果为0,表明可能是全屏;结果不为0,表明一定不是全屏(部分无效)
//function isFullScreen() {
// return !! (document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen);
//}
//结果为true,表明是全屏;结果为false,表明不是全屏
//视频控制顶栏top和left位置
//isPointZero(document.querySelector(".bilibili-player-video-top"))
//function isPointZero(obj) { //获取某元素以浏览器左上角为原点的坐标
// var t = obj.offsetTop; //获取该元素对应父容器的上边距
// var l = obj.offsetLeft; //对应父容器的上边距
// //判断是否有父容器,如果存在则累加其边距
// while (obj = obj.offsetParent) {//等效 obj = obj.offsetParent;while (obj != undefined)
// t += obj.offsetTop; //叠加父容器的上边距
// l += obj.offsetLeft; //叠加父容器的左边距
// }
// if(t==0&&l==0){return true}else{return false}
//}
//结果为true,表明是全屏;结果为false,表明不是全屏
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
function isBilibiliVideoFullScreen() {
function isPointZero(obj) {
var t = obj.offsetTop;
var l = obj.offsetLeft;
while (obj = obj.offsetParent) {
t += obj.offsetTop;
l += obj.offsetLeft;
}
return (t == 0 && l == 0);
}
var c = 1; // Credibility 可信度
if(/.bilibili.com\/video\/*/.test(window.location.href)){
$(".mode-fullscreen").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bilibili-player-video-popup").style.padding == '' ? c *= 1.02 : c *= 0.98;
document.querySelector(".bilibili-player-popup-inner").style.width != '100%' ? c *= 1.05 : c *= 0.95;
document.querySelector(".bilibili-player-video-control-bottom-center").childElementCount == 1 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.closed").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bilibili-player-video-bottom-area").childElementCount == 0 ? c *= 1.1 : c *= 0.9;
window.getComputedStyle(document.querySelector(".float-nav")).display == 'none' ? c *= 1.01 : c *= 0.99;
$(document).scrollTop() == 0 ? c *= 1 : c *= 0.9;
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector(".bilibili-player-video-top")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.bilibili.com\/s\/video\/*/.test(window.location.href)) {
$(".player-fullscreen-fix").length == 1 ? c *= 1.1 : c *= 0.9;
$(".mode-fullscreen").length == 1 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-wrap-plus").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bilibili-player-video-control-bottom-center").childElementCount == 1 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.closed").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bilibili-player-video-bottom-area").childElementCount == 0 ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 0.9;
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector(".bilibili-player-video-top")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.bilibili.com\/bangumi\/play\/*/.test(window.location.href)) {
document.querySelector("div[data-screen]").getAttribute('data-screen') == 'full' ? c *= 1.1 : c *= 0.9;
$(".video-full-screen").length == 1 ? c *= 1.1 : c *= 0.9;
$(".squirtle-wide-screen").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-sendbar-wrap").childElementCount == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-pagelist-wrap.squirtle-block-wrap").style.display == 'block' ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-widescreen-wrap.squirtle-block-wrap").style.display == 'none' ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-pagefullscreen-wrap.squirtle-block-wrap").style.display == 'none' ? c *= 1.1 : c *= 0.9;
document.querySelector(".bpx-player-sending-area").childElementCount == 0 ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 0.9;
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector(".bpx-player-top-wrap")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.bilibili.com\/cheese\/play\/*/.test(window.location.href)) {
document.querySelector("div[data-screen]").getAttribute('data-screen') == 'full' ? c *= 1.1 : c *= 0.9;
document.querySelector("div[data-screen-kind]").getAttribute('data-screen-kind') == 4 ? c *= 1.1 : c *= 0.9;
$(".bpx-state-black-gap").length == 0 ? c *= 1.1 : c *= 1;
document.querySelector(".bpx-player-video-bottom-area").childElementCount == 0 ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-sendbar-wrap").childElementCount == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bpx-player-video-top-title").style.opacity == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bpx-player-video-top-mask").getAttribute("hidden") == null ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-pagelist-wrap").style.display == 'block' ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-widescreen-wrap").style.display == 'none' ? c *= 1.1 : c *= 0.9;
document.querySelector(".squirtle-pagefullscreen-wrap").style.display == 'none' ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 1;//无效
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector(".bpx-player-video-top")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.bilibili.com\/blackboard\/*/.test(window.location.href)) {
if ($(":not([id*='van-popover'])>iframe:not([src*='message\.bilibili\.com']):not([src*='live\.bilibili\.com']):not([src*='activity-feedtag\.html'])").length == 0) {
return false;
}
var ifr = $(":not([id*='van-popover'])>iframe:not([src*='message\.bilibili\.com']):not([src*='live\.bilibili\.com']):not([src*='activity-feedtag\.html'])");
if ($(":not([id*='van-popover'])>iframe:not([src*='message\.bilibili\.com']):not([src*='live\.bilibili\.com']):not([src*='activity-feedtag\.html'])").length > 1) {
$(":not([id*='van-popover'])>iframe:not([src*='message\.bilibili\.com']):not([src*='live\.bilibili\.com']):not([src*='activity-feedtag\.html'])").each(function () {
if (!hasOverLayer($(this)[0])) {
ifr = $(this);
return false; // break
}
});
}
$(".player-fullscreen-fix").length == 1 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".mode-fullscreen").length == 1 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-wrap-plus").length == 1 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-control-bottom-center")[0].childElementCount == 1 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-btn.bilibili-player-video-btn-widescreen.closed").length == 0 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.video-state-fullscreen-off").length == 0 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.closed").length == 1 ? c *= 1.1 : c *= 0.9;
ifr.contents().find(".bilibili-player-video-bottom-area")[0].childElementCount == 0 ? c *= 1.1 : c *= 0.9;
ifr.context.fullscreen ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 0.9;
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(ifr[0]) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.bilibili.com\/medialist\/play\/watchlater\/*/.test(window.location.href)) {
$(".player-fullscreen-fix").length == 1 ? c *= 1.1 : c *= 0.9;
$(".mode-fullscreen").length == 1 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-wrap-plus").length == 1 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.video-state-fullscreen-off").length == 0 ? c *= 1.1 : c *= 0.9;
$(".bilibili-player-video-btn.bilibili-player-video-btn-fullscreen.closed").length == 1 ? c *= 1.1 : c *= 0.9;
document.querySelector(".bilibili-player-video-bottom-area").childElementCount == 0 ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 0.9;
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector(".bilibili-player-video-top")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
if (/.biligame.com\/detail\/*/.test(window.location.href)) {
$("iframe").context.fullscreen ? c *= 1.1 : c *= 0.9;
hasOverLayer(document.querySelector(".bili-game-header-nav")) ? c *= 1.1 : c *= 0.9;
hasOverLayer(document.querySelector(".main-bar")) ? c *= 1.1 : c *= 0.9;
$(document).scrollTop() == 0 ? c *= 1 : c *= 1;//无效
!!(document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen) ? c *= 1.1 : c *= 0.9;
isPointZero(document.querySelector("iframe")) ? c *= 1.1 : c *= 0.9;
return c > 1;
}
}
// 获取"倍速"按钮
function getvideospeedbutton(list) {
var vlist = list||getvideooriframelist();
var v;
if (vlist.length == 0) {
return false;
}
if (vlist.length == 1) {
if (vlist[0].tagName == 'VIDEO') {
v = vlist[0];
} else if (vlist[0].tagName == 'IFRAME') {
return false;
}
return v.parentNode.parentNode.querySelector("[aria-label='倍速']") ||
v.parentNode.parentNode.parentNode.querySelector("[aria-label='倍速']");
}
}
// 获取video或者iframe
function getvideooriframelist() {
var vlist = [];
if (/.bilibili.com\/blackboard\/*/.test(window.location.href) || /.biligame.com\/detail\/*/.test(window.location.href)) {
$(":not([id*='van-popover'])>iframe:not([src*='message\.bilibili\.com']):not([src*='live\.bilibili\.com']):not([src*='activity-feedtag\.html'])").each(function () {
/* */if (hasOverLayer($(this)[0])) {
return true; //continue
} else if (isparentdisplaynone($(this)[0])) {
return true; //continue
} else if (!isparentdisplaynone($(this)[0]) && isoverflowhidden($(this)[0])) {
return true; //continue
} else if (!iscrossoriginiframe($(this)[0]) && $(this).contents().find("video").length > 0) {
vlist.push($(this).contents().find("video")[0]);
} else if (iscrossoriginiframe($(this)[0])) {
vlist.push($(this)[0]);
}
});
}else{
vlist = Array.prototype.slice.call(document.querySelectorAll("video"));
}
return vlist;
}
// 判断元素是否被其他元素覆盖
function hasOverLayer(element) {
let document = element.ownerDocument,
rect = element.getBoundingClientRect(), // 获取目标的矩形信息
x = rect.x,
y = rect.y,
width = rect.width,
height = rect.height;
x |= 0;
y |= 0;
width |= 0;
height |= 0;
// 四顶点取样
let elements = [
document.elementFromPoint(x + 1, y + 1),
document.elementFromPoint(x + width - 1, y + 1),
document.elementFromPoint(x + 1, y + height - 1),
document.elementFromPoint(x + width - 1, y + height - 1)
];
// 判断非本身及非子孙元素
return elements.filter((el) => el !== null).some((el) => el !== element && !element.contains(el));
}
// 判断元素的所有父元素是否显示
function isparentdisplaynone(el) {
getParents(el).forEach(function (e) {
try {
if (window.getComputedStyle(e).display == 'none') {
return true;
}
} catch (err) { }
});
return false;
}
// 判断元素是否被overflow隐藏了
function isoverflowhidden(el) {
var p;
getParents(el).forEach(function (e) {
try {
if (window.getComputedStyle(e).overflow == 'hidden') {
p = e;
}
} catch (err) { }
});
if (typeof (p) == "undefined") {
return false;
}
if (getPositionTop(el) >= getPositionTop(p) + p.offsetHeight) {
return true;
}
return false;
}
// 判断iframe是否跨域
function iscrossoriginiframe(ifr) {
try { if (ifr.contentWindow.document.domain) {} } catch (e) {
return /Blocked a frame with origin.*from accessing a cross-origin frame\./.test(e.toString());
}
return false;
}
// 获取元素的所有父元素
function getParents(el, parentSelector) {
if (parentSelector === undefined) {
parentSelector = document;
}
var parents = [];
var p = el.parentNode;
while (p !== parentSelector) {
var o = p;
parents.push(o);
p = o.parentNode;
}
parents.push(parentSelector);
return parents;
}
// 获取元素到顶部距离,一直查到到最上级父元素
function getPositionTop(node) {
let top = node.offsetTop;
let parent = node.offsetParent;
while (parent != null) {
top += parent.offsetTop;
parent = parent.offsetParent;
}
return top;
}
// 获取元素到左侧距离,一直查到到最上级父元素
function getPositionLeft(node) {
let left = node.offsetLeft;
let parent = node.offsetParent;
while (parent != null) {
left += parent.offsetLeft;
parent = parent.offsetParent;
}
return left;
}
function isInIframe() {
let inFrame = true;
try { if (window.top == self) {
inFrame = false;
}} catch (err) { }
try { if (window.parent.location == self.location) {
inFrame = false;
}} catch (err) { }
return inFrame;
}
//倍速按钮较小,新加一个覆盖层,用来绑定单击重置速度方法和滚轮改变速度方法,添加失败就尝试返回倍速按钮
function createSpeedButtonCoverLayer(mode) {
let speedbutton = getvideospeedbutton();
if (!speedbutton) { return false; }
let ctrl = speedbutton.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".bilibili-player-video-control");
let ctrltop = speedbutton.parentNode.parentNode.parentNode.parentNode.querySelector('.bilibili-player-video-control-top');
let ctrlbottom = speedbutton.parentNode.parentNode.parentNode.parentNode.querySelector(".bilibili-player-video-control-bottom");
let body = document.querySelector("body");
let bilibili_player_area = speedbutton.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".bilibili-player-area");
let ctrlbottomright = speedbutton.parentNode.parentNode.parentNode.querySelector(".bilibili-player-video-control-bottom-right");
if (ctrl == null || ctrltop == null || ctrlbottom == null || body == null || bilibili_player_area == null || ctrlbottomright == null) { return speedbutton; }
let p;
if (mode == 'body' || mode == 'test' || typeof(mode) != 'string') {
p = body;
} else if (mode == 'player') {
p = bilibili_player_area;
} else if (mode == 'ctrl') {
p = ctrlbottomright;
} else {
p = body;
}
let layer = document.createElement("div");
layer.className = 'speed-button-cover-layer';
layer.style.position = 'absolute';
layer.style.zIndex = getComputedStyle(ctrl).zIndex;
// layer.style.background = 'yellow';
layer.style.top = getPositionTop(ctrltop) + ctrltop.offsetHeight - getPositionTop(p) + 'px';
layer.style.height = getPositionTop(ctrlbottom) + ctrlbottom.offsetHeight - (getPositionTop(ctrltop) + ctrltop.offsetHeight) + 2 + 'px';
layer.style.left = getPositionLeft(speedbutton) - getPositionLeft(p) + 'px';
layer.style.width = getComputedStyle(speedbutton).width;
p.appendChild(layer);
return layer;
}
//将一个元素赋予点击和拖动的功能并禁用浏览器右键菜单功能
function clickormove(node, afterClickFun, afterMoveFun) {
var mousedownpos = [-1, -1, -1, -1]; // 鼠标按下位置和鼠标距离node左上角的坐标差
var shortMove = 10; //允许误差,如果鼠标移动距离过小,则认为是点击事件,而非拖动事件
var moved = false; //是否拖动过。受shortMove影响
var correctTarget = false; //用mousedown和mouseup模拟click
// document
document.addEventListener("mousedown", function(event) {
if (event.target == node) {
node.addEventListener("mousemove", mousemove);
mousedownpos = [
event.pageY,
event.pageX,
event.pageY - parseFloat(getComputedStyle(node)
.top),
event.pageX - parseFloat(getComputedStyle(node)
.left)
];
document.onselectstart = function() {
return false;
}; //临时取消字段选择功能
}
moved = false;
});
document.addEventListener("mouseup", function() {
node.removeEventListener("mousemove", mousemove);
document.onselectstart = function() {
return true;
}; //启用字段选择功能
moved = false;
});
// node
node.oncontextmenu = function() {
return false;
};
node.addEventListener("mousedown", function() {
correctTarget = true;
});
node.addEventListener("mouseup", function() {
if (moved) {
afterMoveFun();
} else if (correctTarget) {
afterClickFun();
}
correctTarget = false;
});
function mousemove(event) {
if (moved) {
node.style.top = event.pageY - mousedownpos[2] + "px";
node.style.left = event.pageX - mousedownpos[3] + "px";
} else if (
Math.abs(event.pageY - mousedownpos[0]) > shortMove ||
Math.abs(event.pageX - mousedownpos[1]) > shortMove
) {
node.style.top = event.pageY - mousedownpos[2] + "px";
node.style.left = event.pageX - mousedownpos[3] + "px";
moved = true;
}
}
}
//判断元素是否贴边,返回方向
function onWhichSide(element) {
const viewWidth = window.innerWidth || document.documentElement.clientWidth;
const viewHeight = window.innerHeight || document.documentElement.clientHeight;
const {
top,
right,
bottom,
left,
} = element.getBoundingClientRect();
if(top <= 0){
return 'top';
}else if(left <= 0){
return 'left'
}else if(right >= viewWidth){
return 'right';
}else if(bottom >= viewHeight){
return 'bottom';
}else{
return false;
}
}
console