仅在全屏状态下显示SNI栏,非全屏下隐藏
// ==UserScript==
// @name SNI 插件 - 仅在全屏模式显示
// @namespace ckyl-bili-sni-fullscreenonly
// @version 2025-07-14
// @description 仅在全屏状态下显示SNI栏,非全屏下隐藏
// @author CKylinMC
// @match https://*.bilibili.com/*
// @exclude https://www.bilibili.com/bangumi/play*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant none
// @license WTFPL
// ==/UserScript==
(function() {
'use strict';
function toggleSNI(show=true){
const id = "sni-plugin-fullscreenonly";
let css = document.querySelector("style#"+id);
if(!css) {
css = document.createElement("style");
css.id = id;
document.head.appendChild(css);
}
css.innerHTML = '';
css.appendChild(document.createTextNode(`
#ck-sni-container{
display: ${show?"block":"none"} !important;
}
`));
}
function applyState(){
const element = document.fullscreenElement ||
document.webkitFullscreenElement ||
document.mozFullScreenElement ||
document.msFullscreenElement;
return toggleSNI(!!element);
}
function hookEvents(){
['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange']
.forEach(event => {
try{document.removeEventListener(event, applyState);}catch(_){/*ignored*/}
document.addEventListener(event, applyState);
});
applyState();
}
hookEvents();
})();