@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 播放页 / 全站轻量兼容:Chrome / Safari / 夸克 / QQ(X5) / UC / 百度等
|
||||
* - 标记 UA,便于定向样式
|
||||
* - 动态视口高度 --app-vh
|
||||
* - Element.matches / closest / Promise.finally 兜底(旧版 QQ / 夸克)
|
||||
*/
|
||||
(function () {
|
||||
var root = document.documentElement;
|
||||
var ua = (navigator && navigator.userAgent) || "";
|
||||
|
||||
var isIOS = /iP(hone|od|ad)/.test(ua);
|
||||
var isAndroid = /Android/i.test(ua);
|
||||
var isQuark = /Quark/i.test(ua);
|
||||
var isQQ = /QQ\//i.test(ua) || /MQQBrowser/i.test(ua);
|
||||
var isUC = /UCBrowser|UCWEB/i.test(ua);
|
||||
var isWeChat = /MicroMessenger/i.test(ua);
|
||||
var isBaidu = /baidubrowser|bdbrowser|BaiduHD/i.test(ua);
|
||||
var isHuawei = /HuaweiBrowser|HONORBrowser|HBPC/i.test(ua);
|
||||
var isMiui = /MiuiBrowser/i.test(ua);
|
||||
var isSogou = /SogouMobileBrowser|SogouMSE/i.test(ua);
|
||||
var isSafari =
|
||||
/Safari/i.test(ua) &&
|
||||
!/Chrome|CriOS|Chromium|Edg|Quark|MQQBrowser|UCBrowser|MicroMessenger|baidubrowser|MiuiBrowser|HuaweiBrowser|Sogou/i.test(
|
||||
ua
|
||||
);
|
||||
|
||||
// 易劫持 video 的国产浏览器:强制走页面内 DPlayer + hls.js
|
||||
var forceCustomPlayer =
|
||||
isQuark ||
|
||||
isQQ ||
|
||||
isUC ||
|
||||
isWeChat ||
|
||||
isBaidu ||
|
||||
isHuawei ||
|
||||
isMiui ||
|
||||
isSogou ||
|
||||
/VivoBrowser|HeyTapBrowser|OPPOBrowser|HeyTap|QihooBrowser|360Browser|360SE|360EE/i.test(
|
||||
ua
|
||||
);
|
||||
|
||||
root.classList.add("compat-ready");
|
||||
if (isIOS) root.classList.add("is-ios");
|
||||
if (isAndroid) root.classList.add("is-android");
|
||||
if (isQuark) root.classList.add("is-quark");
|
||||
if (isQQ) root.classList.add("is-qq");
|
||||
if (isUC) root.classList.add("is-uc");
|
||||
if (isWeChat) root.classList.add("is-wechat");
|
||||
if (isBaidu) root.classList.add("is-baidu");
|
||||
if (isHuawei) root.classList.add("is-huawei");
|
||||
if (isMiui) root.classList.add("is-miui");
|
||||
if (isSogou) root.classList.add("is-sogou");
|
||||
if (isSafari) root.classList.add("is-safari");
|
||||
if (forceCustomPlayer) root.classList.add("is-cn-browser");
|
||||
|
||||
window.BrowserCompat = {
|
||||
isIOS: isIOS,
|
||||
isAndroid: isAndroid,
|
||||
isQuark: isQuark,
|
||||
isQQ: isQQ,
|
||||
isUC: isUC,
|
||||
isWeChat: isWeChat,
|
||||
isBaidu: isBaidu,
|
||||
isHuawei: isHuawei,
|
||||
isMiui: isMiui,
|
||||
isSogou: isSogou,
|
||||
isSafari: isSafari,
|
||||
forceCustomPlayer: forceCustomPlayer,
|
||||
needsX5Inline: isQQ || isWeChat || isUC || isQuark,
|
||||
};
|
||||
|
||||
/** 点击目标可能是 Text 节点(夸克/QQ 常见),统一取 Element 再 closest */
|
||||
window.domClosest = function (from, selector) {
|
||||
var el = from;
|
||||
if (!el) return null;
|
||||
if (el.nodeType !== 1) el = el.parentElement || el.parentNode;
|
||||
if (!el || el.nodeType !== 1 || typeof el.closest !== "function") return null;
|
||||
return el.closest(selector);
|
||||
};
|
||||
|
||||
if (!Element.prototype.matches) {
|
||||
Element.prototype.matches =
|
||||
Element.prototype.msMatchesSelector ||
|
||||
Element.prototype.webkitMatchesSelector ||
|
||||
function (selector) {
|
||||
var list = (this.document || this.ownerDocument).querySelectorAll(selector);
|
||||
var i = list.length;
|
||||
while (--i >= 0 && list.item(i) !== this) {}
|
||||
return i > -1;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Element.prototype.closest) {
|
||||
Element.prototype.closest = function (selector) {
|
||||
var el = this;
|
||||
while (el && el.nodeType === 1) {
|
||||
if (el.matches(selector)) return el;
|
||||
el = el.parentElement || el.parentNode;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof Promise !== "undefined" && !Promise.prototype.finally) {
|
||||
Promise.prototype.finally = function (onFinally) {
|
||||
var P = this.constructor;
|
||||
return this.then(
|
||||
function (value) {
|
||||
return P.resolve(typeof onFinally === "function" ? onFinally() : onFinally).then(
|
||||
function () {
|
||||
return value;
|
||||
}
|
||||
);
|
||||
},
|
||||
function (reason) {
|
||||
return P.resolve(typeof onFinally === "function" ? onFinally() : onFinally).then(
|
||||
function () {
|
||||
throw reason;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function setAppVh() {
|
||||
var h = window.innerHeight || 0;
|
||||
if (window.visualViewport && window.visualViewport.height) {
|
||||
h = window.visualViewport.height;
|
||||
}
|
||||
if (h > 0) {
|
||||
root.style.setProperty("--app-vh", h + "px");
|
||||
}
|
||||
}
|
||||
|
||||
setAppVh();
|
||||
window.addEventListener("resize", setAppVh, { passive: true });
|
||||
window.addEventListener("orientationchange", function () {
|
||||
setTimeout(setAppVh, 120);
|
||||
});
|
||||
if (window.visualViewport) {
|
||||
window.visualViewport.addEventListener("resize", setAppVh, { passive: true });
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user