(function () {
var LOGO_URL = '/fb-logo.png?v=20260306w';
var HOME_SEARCH_CACHE_KEY = 'fb.home.search.q';
function setFavicons() {
var rels = ['icon', 'shortcut icon', 'apple-touch-icon'];
rels.forEach(function (rel) {
var link = document.querySelector('link[rel="' + rel + '"]');
if (!link) {
link = document.createElement('link');
link.setAttribute('rel', rel);
document.head.appendChild(link);
}
link.setAttribute('href', LOGO_URL);
link.setAttribute('type', 'image/png');
});
var msTile = document.querySelector('meta[name="msapplication-TileImage"]');
if (msTile) msTile.setAttribute('content', LOGO_URL);
}
function ensureStaticStyles() {
if (document.getElementById('fb-brand-style')) return;
var style = document.createElement('style');
style.id = 'fb-brand-style';
style.textContent = [
'.credits { display: none !important; }',
'[class*="credits"] { display: none !important; }',
'#fb-header-brand {',
' display: inline-flex;',
' align-items: center;',
' margin-right: 10px;',
' line-height: 1;',
' pointer-events: none;',
' user-select: none;',
'}',
'#fb-header-brand img { width: 26px; height: 26px; object-fit: contain; display:block; }',
'#fb-top-corner-brand {',
' position: fixed;',
' top: 10px;',
' left: 12px;',
' z-index: 2147483000;',
' display: inline-flex;',
' align-items: center;',
' justify-content: center;',
' width: 40px;',
' height: 40px;',
' border-radius: 10px;',
' background: rgba(41,44,60,.75);',
' border: 1px solid rgba(198,208,245,.25);',
' backdrop-filter: blur(8px);',
' pointer-events: none;',
' user-select: none;',
'}',
'#fb-top-corner-brand img { width: 22px; height: 22px; object-fit: contain; display:block; }',
'body#login-page #fb-top-corner-brand, #login #fb-top-corner-brand { display: none !important; }',
'body#login-page #fb-header-brand, #login #fb-header-brand { display: none !important; }',
'@media (max-width: 736px) { #fb-top-corner-brand { top: 8px; left: 8px; width: 34px; height: 34px; } }'
].join('\n');
document.head.appendChild(style);
}
function tuneLoginBrand() {
var login = document.getElementById('login');
if (!login) return;
var form = login.querySelector('form');
if (!form) return;
var imgs = form.querySelectorAll('img');
if (imgs.length > 0) {
imgs.forEach(function (img, idx) {
if (idx === 0) {
if (img.dataset.fbLogoReady !== '1') {
img.src = LOGO_URL;
img.srcset = '';
img.style.width = '92px';
img.style.height = '92px';
img.style.objectFit = 'contain';
img.style.display = 'block';
img.style.margin = '0 auto 8px';
img.dataset.fbLogoReady = '1';
}
} else {
img.remove();
}
});
}
var title = form.querySelector('h1');
if (title && title.textContent !== '繁星文档') {
title.textContent = '繁星文档';
title.style.marginTop = '6px';
}
}
function suppressNativeHeaderBrand() {
if (location.pathname.indexOf('/login') === 0 || document.getElementById('login')) return;
var header = document.querySelector('header');
if (!header) return;
var walker = document.createTreeWalker(header, NodeFilter.SHOW_TEXT, null);
var node;
while ((node = walker.nextNode())) {
var txt = (node.nodeValue || '').trim();
if (txt === 'File Browser' || txt === '文件浏览器') {
node.nodeValue = '';
}
}
var nativeImgs = header.querySelectorAll('img:not(#fb-header-brand img)');
nativeImgs.forEach(function (img) {
if (img.closest && img.closest('#fb-header-brand')) return;
img.style.display = 'none';
});
}
function ensureHeaderBrand() {
var onLogin = location.pathname.indexOf('/login') === 0 || !!document.getElementById('login');
var old = document.getElementById('fb-header-brand');
if (onLogin) {
if (old) old.remove();
return false;
}
var header = document.querySelector('header');
if (!header) return false;
var brand = old;
if (!brand) {
brand = document.createElement('div');
brand.id = 'fb-header-brand';
brand.setAttribute('aria-hidden', 'true');
brand.innerHTML = '
';
header.insertBefore(brand, header.firstChild);
} else {
var img = brand.querySelector('img');
if (img) img.src = LOGO_URL;
if (brand.parentElement !== header) {
header.insertBefore(brand, header.firstChild);
}
}
return true;
}
function ensureTopCornerFallback(useHeader) {
var onLogin = location.pathname.indexOf('/login') === 0 || !!document.getElementById('login');
var el = document.getElementById('fb-top-corner-brand');
if (onLogin || useHeader) {
if (el) el.remove();
return;
}
if (!el) {
el = document.createElement('div');
el.id = 'fb-top-corner-brand';
el.setAttribute('aria-hidden', 'true');
el.innerHTML = '
';
document.body.appendChild(el);
} else {
var img = el.querySelector('img');
if (img) img.src = LOGO_URL;
}
}
function renameSidebarRoot() {
var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null);
var node;
while ((node = walker.nextNode())) {
var txt = (node.nodeValue || '').trim();
if (txt === '我的文件' || txt === 'My Files') {
node.nodeValue = node.nodeValue.replace(txt, '繁星文档');
}
}
}
function removeLegacyInlineSearch() {
var legacy = document.getElementById('fb-inline-search');
if (legacy) legacy.remove();
var legacyStyle = document.getElementById('fb-inline-search-style');
if (legacyStyle) legacyStyle.remove();
var search = document.getElementById('search');
if (search && search.style && search.style.display === 'none') search.style.display = '';
}
function isSearchInput(el) {
if (!el || el.tagName !== 'INPUT') return false;
var t = (el.getAttribute('type') || '').toLowerCase();
var p = (el.getAttribute('placeholder') || '').toLowerCase();
if (t === 'search') return true;
if (p.indexOf('search') >= 0 || p.indexOf('搜索') >= 0) return true;
if ((el.className || '').toString().toLowerCase().indexOf('search') >= 0) return true;
return false;
}
function readCachedHomeSearch() {
try {
return (sessionStorage.getItem(HOME_SEARCH_CACHE_KEY) || '').trim();
} catch (e) {
return '';
}
}
function writeCachedHomeSearch(q) {
try {
sessionStorage.setItem(HOME_SEARCH_CACHE_KEY, (q || '').trim());
} catch (e) {}
}
function goSearch(q) {
if (location.pathname === '/search') return;
var qs = (q || '').trim();
if (!qs) qs = readCachedHomeSearch();
location.assign('/search' + (qs ? ('?q=' + encodeURIComponent(qs)) : ''));
}
function installSearchRedirectGuards() {
if (window.__fbSearchRedirectGuardInstalled) return;
window.__fbSearchRedirectGuardInstalled = true;
// Keep home search input value cached for /search fallback.
document.addEventListener('input', function (e) {
if (location.pathname.indexOf('/login') === 0) return;
var homeInput = e.target && e.target.closest && e.target.closest('#search input, #search #input input');
if (!homeInput) return;
writeCachedHomeSearch(e.target.value || '');
}, true);
document.addEventListener('click', function (e) {
if (location.pathname.indexOf('/login') === 0) return;
var inSearch = e.target && e.target.closest && e.target.closest('#search');
if (!inSearch) return;
var onInput = e.target && e.target.closest && e.target.closest('#search input, #search #input input');
if (onInput) return; // keep typing, no redirect on click.
// Intercept magnifier / action click to prevent built-in index popup.
var icon = e.target && e.target.closest && e.target.closest('.search-button,header .search-button,#search #input > i,#search .search-button,#search .action,#search [title*="search" i],#search [aria-label*="search" i],#search [title*="搜索" i],#search [aria-label*="搜索" i],#search i');
if (!icon) return;
e.preventDefault();
e.stopPropagation();
if (e.stopImmediatePropagation) e.stopImmediatePropagation();
}, true);
document.addEventListener('keydown', function (e) {
if (location.pathname.indexOf('/login') === 0) return;
if (location.pathname === '/search') return;
var homeInput = e.target && e.target.closest && e.target.closest('#search input, #search #input input');
if (!homeInput) return;
if (e.key !== 'Enter') return;
var q = (e.target.value || '').trim();
writeCachedHomeSearch(q);
e.preventDefault();
e.stopPropagation();
if (e.stopImmediatePropagation) e.stopImmediatePropagation();
goSearch(q);
}, true);
}
function apply() {
setFavicons();
ensureStaticStyles();
tuneLoginBrand();
suppressNativeHeaderBrand();
var ok = ensureHeaderBrand();
ensureTopCornerFallback(ok);
renameSidebarRoot();
removeLegacyInlineSearch();
installSearchRedirectGuards();
}
var timer = null;
var ob = new MutationObserver(function () {
if (timer) clearTimeout(timer);
timer = setTimeout(apply, 20);
});
ob.observe(document.documentElement, { childList: true, subtree: true });
apply();
if (window.requestAnimationFrame) requestAnimationFrame(apply);
setTimeout(apply, 30);
})();