Created
August 27, 2025 15:22
-
-
Save wgetge/a0f17ef69a6e1abb380892a2fba1ce0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 虎牙免登陆清晰度 | |
// @namespace https://github.com/demon-zhonglin/tmJavaScript | |
// @version 0.9 | |
// @description 虎牙免登陆可控清晰度【自动切最高清晰度】【自 2023-07 huya 更新后,全网首发 huya 绕过登录可切换画质清晰度】 | |
// @author demon-zhonglin | |
// @include https://*.huya.com/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// @run-at document-start | |
// @noframes | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
function untilTrue(fn, maxRetry = 1000) { | |
let retry = 0; | |
const interval = setInterval(() => { | |
if (fn() || ++retry >= maxRetry) { | |
clearInterval(interval); | |
} | |
}, 500); | |
} | |
function hideLoginDialog(node) { | |
if (node.nodeType === Node.ELEMENT_NODE) { | |
const element = /** @type {Element} */ (node); | |
if (element.matches('#HUYA-UDBSdkLgn') && element.style.display === 'block') { | |
element.style.display = 'none'; | |
} | |
} | |
} | |
new MutationObserver(mrs => { | |
mrs.forEach(mr => { | |
if (mr.type === 'childList') { | |
mr.addedNodes.forEach(hideLoginDialog) | |
} | |
else { | |
hideLoginDialog(mr.target) | |
} | |
}) | |
}).observe(document, { | |
childList: true, | |
subtree: true, | |
attributes: true | |
}) | |
// 更新画质项 节点属性 | |
function changeVideotypeItem() { | |
$('.player-videotype-list li').each(function (e, t) { | |
let obj = $(t).data('data'); | |
obj.status = 1; | |
$(t).data('data', obj); | |
}); | |
const videotypeList = $('.player-menu-panel ul.player-videotype-list > li'); | |
if (videotypeList.length > 0) { | |
setTimeout(() => { | |
try { | |
videotypeList[0].click(); | |
} catch { | |
window.alert('自动切换画质失败,请手动切换视频画质!'); | |
} | |
}, 1000); | |
return true; | |
} | |
} | |
// 清空倒计时 | |
function clearCountdown() { | |
const timeNum = window.localStorage.getItem('roomHeartbeat'); | |
if (Number.isInteger(timeNum)) { | |
window.localStorage.setItem('roomHeartbeat', -Infinity); // 跳过未登录时间检测 | |
} | |
} | |
const main = () => { | |
// 避免多开浏览器tab有某个tab失效导致重新触发登录时间 | |
clearCountdown(); | |
// 覆盖关闭窗口事件 | |
untilTrue(() => { | |
if (window.HyLogin) { | |
window.HyLogin.prototype.closeUdbLogin = function () { | |
window.HyLogin.notice("loginClose"); | |
}; | |
return true; | |
} | |
}); | |
// 监听视频状态 | |
untilTrue(() => { | |
if (window.VPlayer?.prototype?.videoStatus === 0 && changeVideotypeItem()) { | |
return true; | |
} | |
}); | |
}; | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment